parent
999d10ae5d
commit
bad86d8284
@ -6,9 +6,7 @@ import java.io.File;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.*;
|
||||||
import java.net.SocketTimeoutException;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
@ -58,13 +56,24 @@ public class HttpDownloader extends Downloader {
|
|||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private URI getURIFromRequestUrl(String source) {
|
||||||
|
try {
|
||||||
|
URL url = new URL(source);
|
||||||
|
return new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef());
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void download() {
|
protected void download() {
|
||||||
DefaultHttpClient httpClient = null;
|
DefaultHttpClient httpClient = null;
|
||||||
BufferedOutputStream out = null;
|
BufferedOutputStream out = null;
|
||||||
InputStream connection = null;
|
InputStream connection = null;
|
||||||
try {
|
try {
|
||||||
HttpGet httpGet = new HttpGet(request.getSource());
|
HttpGet httpGet = new HttpGet(getURIFromRequestUrl(request.getSource()));
|
||||||
httpClient = createHttpClient();
|
httpClient = createHttpClient();
|
||||||
HttpResponse response = httpClient.execute(httpGet);
|
HttpResponse response = httpClient.execute(httpGet);
|
||||||
HttpEntity httpEntity = response.getEntity();
|
HttpEntity httpEntity = response.getEntity();
|
||||||
|
@ -108,6 +108,12 @@ public class HttpDownloaderTest extends InstrumentationTestCase {
|
|||||||
assertFalse(new File(feedFile.getFile_url()).exists());
|
assertFalse(new File(feedFile.getFile_url()).exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: replace with smaller test file
|
||||||
|
public void testUrlWithSpaces() {
|
||||||
|
download("http://acedl.noxsolutions.com/ace/Don't Call Salman Rushdie Sneezy in Finland.mp3", "testUrlWithSpaces", true);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
private static class FeedFileImpl extends FeedFile {
|
private static class FeedFileImpl extends FeedFile {
|
||||||
public FeedFileImpl(String download_url) {
|
public FeedFileImpl(String download_url) {
|
||||||
super(null, download_url, false);
|
super(null, download_url, false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user