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

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sat Oct 2 07:01:37 MST 2004


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

Modified Files:
	NetUtil.java 
Log Message:
Installer improvements
BD-15

Index: NetUtil.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/NetUtil.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** NetUtil.java	29 Sep 2004 22:15:30 -0000	1.12
--- NetUtil.java	2 Oct 2004 14:01:35 -0000	1.13
***************
*** 9,12 ****
--- 9,13 ----
  import java.io.InputStreamReader;
  import java.io.OutputStream;
+ import java.net.JarURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
***************
*** 16,20 ****
  import java.util.List;
  import java.util.jar.JarEntry;
- import java.util.jar.JarFile;
  
  /**
--- 17,20 ----
***************
*** 535,576 ****
      public static long getLastModified(URL url)
      {
!         if (url.getProtocol().equals(PROTOCOL_JAR))
          {
              // form is jar:file:.../xxx.jar!.../filename.ext
              try
              {
!                 String spec = url.getFile();
!                 int bang = spec.indexOf('!');
! 
!                 String jar = spec.substring(0, bang);
!                 url = new URL(jar); // Note: replacing input argument!!!
!                 JarFile jarfile = new JarFile(url.getFile());
! 
!                 // Skip the ! and the leading /
!                 String file = spec.substring(bang + 2);
!                 JarEntry jarEntry = jarfile.getJarEntry(file);
! 
!                 long time = jarEntry.getTime();
!                 if (time != -1)
!                 {
!                     return time;
!                 }
              }
!             catch (IOException ex)
              {
!                 log.debug("Could not get the file " + url + " from the jar." + ex); //$NON-NLS-1$ //$NON-NLS-2$
              }
! 
!             // If we got here we did not get the timestamp of the file in the jar
!             // So now get the timestamp of the jar itself.
          }
  
!         if (url.getProtocol().equals(PROTOCOL_FILE))
!         {
!             File file = new File(url.getFile());
!             return file.lastModified();
!         }
  
!         return System.currentTimeMillis();
      }
  
--- 535,581 ----
      public static long getLastModified(URL url)
      {
!         long time = 0;
!         URLConnection urlConnection = null;
!         try
!         {
!             urlConnection = url.openConnection();
!             time = urlConnection.getLastModified();
!         }
!         catch (IOException e)
!         {
!             // TODO Auto-generated catch block
!             e.printStackTrace();
!         }
! 
!         // If it were a jar then time contains the last modified date of the jar.
!         if (urlConnection instanceof JarURLConnection)
          {
              // form is jar:file:.../xxx.jar!.../filename.ext
+             JarURLConnection jarConnection = (JarURLConnection) urlConnection;
+             JarEntry jarEntry = null;
              try
              {
!                 jarEntry = jarConnection.getJarEntry();
              }
!             catch (IOException e2)
              {
!                 assert false;
              }
!             time = jarEntry.getTime();
          }
  
!         return time;
!     }
  
!     /**
!      * Returns whether the left is newer than the right by comparing their last
!      * modified dates.
!      * @param left
!      * @param right
!      * @return true if the left is newer
!      */
!     public static boolean isNewer(URL left, URL right)
!     {
!         return NetUtil.getLastModified(left) > NetUtil.getLastModified(right);
      }
  



More information about the jsword-svn mailing list