[Zerofile-svn] SF.net SVN: zerofile: [63] trunk/src/ZeroFile.java
Status: Pre-Alpha
Brought to you by:
karl-bengtsson
|
From: <kar...@us...> - 2007-12-04 13:47:51
|
Revision: 63
http://zerofile.svn.sourceforge.net/zerofile/?rev=63&view=rev
Author: karl-bengtsson
Date: 2007-12-04 05:47:54 -0800 (Tue, 04 Dec 2007)
Log Message:
-----------
test of initial download method
Modified Paths:
--------------
trunk/src/ZeroFile.java
Modified: trunk/src/ZeroFile.java
===================================================================
--- trunk/src/ZeroFile.java 2007-12-04 13:35:23 UTC (rev 62)
+++ trunk/src/ZeroFile.java 2007-12-04 13:47:54 UTC (rev 63)
@@ -1,5 +1,5 @@
-import java.io.IOException;
-import java.net.InetAddress;
+import java.io.*;
+import java.net.*;
public class ZeroFile {
/**
@@ -45,4 +45,63 @@
return null;
}
}
+
+ public static void downloadFileFromHTTP(String address)
+ {
+ OutputStream out = null;
+ URLConnection conn = null;
+ InputStream in = null;
+ int lastSlashIndex = address.lastIndexOf('/');
+ if (!(lastSlashIndex >= 0 && lastSlashIndex < address.length() - 1))
+ {
+ System.err.println("Could not figure out local file name for " + address);
+ }
+ else
+ {
+ try
+ {
+ String localFileName;
+ if (!ZeroFileSettings.getDownloadFolder().equals(""))
+ localFileName = ZeroFileSettings.getDownloadFolder() + address.substring(lastSlashIndex + 1);
+ else
+ localFileName = System.getProperty("user.home") + address.substring(lastSlashIndex + 1);
+ URL url = new URL(address);
+ out = new BufferedOutputStream(
+ new FileOutputStream(localFileName));
+ conn = url.openConnection();
+ in = conn.getInputStream();
+ byte[] buffer = new byte[1024];
+ int numRead;
+ long numWritten = 0;
+ /*while ((numRead = in.read(buffer)) != -1)
+ {
+ out.write(buffer, 0, numRead);
+ numWritten += numRead;
+ }*/
+ System.out.println(localFileName + "\t" + numWritten);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ if (in != null)
+ {
+ in.close();
+ }
+ if (out != null)
+ {
+ out.close();
+ }
+ }
+ catch (IOException ioe)
+ {
+ System.out.println(ioe);
+ }
+ }
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|