[jsword-svn] common/java/core/org/crosswire/common/util s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Thu Aug 18 13:58:45 MST 2005


Update of /cvs/jsword/common/java/core/org/crosswire/common/util
In directory www.crosswire.org:/tmp/cvs-serv16274/java/core/org/crosswire/common/util

Modified Files:
	NetUtil.java 
Log Message:
Working on getting download to work with a proxy server.
Upgrading commons-net from 1.3 to 1.4.

Index: NetUtil.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/NetUtil.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** NetUtil.java	27 Jul 2005 23:26:42 -0000	1.23
--- NetUtil.java	18 Aug 2005 20:58:42 -0000	1.24
***************
*** 40,43 ****
--- 40,49 ----
  import java.util.jar.JarEntry;
  
+ import org.apache.commons.httpclient.HttpClient;
+ import org.apache.commons.httpclient.HttpException;
+ import org.apache.commons.httpclient.HttpStatus;
+ import org.apache.commons.httpclient.methods.GetMethod;
+ import org.apache.commons.httpclient.util.HttpURLConnection;
+ 
  /**
   * The NetUtil class looks after general utility stuff around the
***************
*** 47,51 ****
   *      The copyright to this program is held by it's authors.
   * @author Joe Walker [joe at eireneh dot com]
!  * @author Mark Goodwin
   */
  public final class NetUtil
--- 53,58 ----
   *      The copyright to this program is held by it's authors.
   * @author Joe Walker [joe at eireneh dot com]
!  * @author Mark Goodwin [goodwinster at gmail dot com]
!  * @author DM Smith [dmsmith555 at yahoo dot com]
   */
  public final class NetUtil
***************
*** 534,537 ****
--- 541,578 ----
      public static int getSize(URL url)
      {
+         if (url.getProtocol().equals(PROTOCOL_HTTP))
+         {
+             // Create an instance of HttpClient.
+             HttpClient client = new HttpClient();
+ 
+             // Create a method instance.
+             GetMethod method = new GetMethod(url.toExternalForm());
+             
+             // Execute the method.
+             try
+             {
+                 int statusCode = client.executeMethod(method);
+                 if (statusCode != HttpStatus.SC_OK)
+                 {
+                     return 0;
+                 }
+             }
+             catch (HttpException e)
+             {
+                 // TODO Auto-generated catch block
+                 e.printStackTrace();
+             }
+             catch (IOException e)
+             {
+                 // TODO Auto-generated catch block
+                 e.printStackTrace();
+             }
+ 
+             HttpURLConnection connection = new HttpURLConnection(method, url);
+             
+             return connection.getContentLength();
+ 
+         }
+ 
          try
          {
***************
*** 552,555 ****
--- 593,629 ----
      public static long getLastModified(URL url)
      {
+         if (url.getProtocol().equals(PROTOCOL_HTTP))
+         {
+             // Create an instance of HttpClient.
+             HttpClient client = new HttpClient();
+ 
+             // Create a method instance.
+             GetMethod method = new GetMethod(url.toExternalForm());
+             
+             // Execute the method.
+             try
+             {
+                 int statusCode = client.executeMethod(method);
+                 if (statusCode != HttpStatus.SC_OK)
+                 {
+                     return 0;
+                 }
+             }
+             catch (HttpException e)
+             {
+                 // TODO Auto-generated catch block
+                 e.printStackTrace();
+             }
+             catch (IOException e)
+             {
+                 // TODO Auto-generated catch block
+                 e.printStackTrace();
+             }
+ 
+             HttpURLConnection connection = new HttpURLConnection(method, url);
+             
+             return connection.getLastModified();
+ 
+         }
          try
          {



More information about the jsword-svn mailing list