git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/SeaDataNetConnector@119874 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
a617392fcb
commit
25da959635
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue