This commit is contained in:
Gianpaolo Coro 2015-10-19 16:35:45 +00:00
parent a617392fcb
commit 25da959635
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
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");
}
}