44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package org.gcube.dataanalysis.seadatanet;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.net.URL;
|
|
import java.net.URLConnection;
|
|
|
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
|
|
|
public class Downloader {
|
|
|
|
public static void downloadFile(String fileurl, String destinationFile) throws Exception{
|
|
try {
|
|
URL smpFile = new URL(fileurl);
|
|
URLConnection uc = (URLConnection) smpFile.openConnection();
|
|
InputStream is = uc.getInputStream();
|
|
AnalysisLogger.getLogger().debug("Retrieving file from " + fileurl + " to :" + destinationFile);
|
|
inputStreamToFile(is, destinationFile);
|
|
is.close();
|
|
} catch (Exception e) {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
public static void inputStreamToFile(InputStream is, String path) throws FileNotFoundException, IOException {
|
|
FileOutputStream out = new FileOutputStream(new File(path));
|
|
byte buf[] = new byte[1024];
|
|
int len = 0;
|
|
while ((len = is.read(buf)) > 0)
|
|
out.write(buf, 0, len);
|
|
out.close();
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public static void main(String args[]) throws Exception{
|
|
downloadFile("https://dl.dropboxusercontent.com/u/12809149/2_Reviewed.jpg","test.jpg");
|
|
}
|
|
}
|