bodewig     2004/11/12 04:15:13

  Modified:    src/main/org/apache/tools/bzip2 CBZip2InputStream.java
               src/main/org/apache/tools/zip ZipOutputStream.java
               src/testcases/org/apache/tools/zip ZipOutputStreamTest.java
  Log:
  deprecated or not, this is the only way to avoid creation of both - a Date 
and a Calendar instance - that works on JDK 1.3 and 1.2 - 
Calendar#setTimeInMillis has been protected before 1.4
  
  Revision  Changes    Path
  1.19      +4 -4      
ant/src/main/org/apache/tools/bzip2/CBZip2InputStream.java
  
  Index: CBZip2InputStream.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/bzip2/CBZip2InputStream.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- CBZip2InputStream.java    9 Mar 2004 16:48:54 -0000       1.18
  +++ CBZip2InputStream.java    12 Nov 2004 12:15:13 -0000      1.19
  @@ -126,7 +126,7 @@
       private int computedBlockCRC, computedCombinedCRC;
   
       int i2, count, chPrev, ch2;
  -    int i, tPos;
  +    int global_i, tPos;
       int rNToGo = 0;
       int rTPos  = 0;
       int j2;
  @@ -668,14 +668,14 @@
           char ch;
   
           cftab[0] = 0;
  -        for (i = 1; i <= 256; i++) {
  +        for (int i = 1; i <= 256; i++) {
               cftab[i] = unzftab[i - 1];
           }
  -        for (i = 1; i <= 256; i++) {
  +        for (int i = 1; i <= 256; i++) {
               cftab[i] += cftab[i - 1];
           }
   
  -        for (i = 0; i <= last; i++) {
  +        for (int i = 0; i <= last; i++) {
               ch = (char) ll8[i];
               tt[cftab[ch]] = i;
               cftab[ch]++;
  
  
  
  1.28      +12 -17    ant/src/main/org/apache/tools/zip/ZipOutputStream.java
  
  Index: ZipOutputStream.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipOutputStream.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- ZipOutputStream.java      12 Nov 2004 12:04:59 -0000      1.27
  +++ ZipOutputStream.java      12 Nov 2004 12:15:13 -0000      1.28
  @@ -24,7 +24,6 @@
   import java.io.OutputStream;
   import java.io.RandomAccessFile;
   import java.io.UnsupportedEncodingException;
  -import java.util.Calendar;
   import java.util.Date;
   import java.util.Hashtable;
   import java.util.Vector;
  @@ -581,7 +580,7 @@
           written += 2;
   
           // last mod. time and date
  -        writeOut(toDosTime(new Date(ze.getTime())));
  +        writeOut(toDosTime(ze.getTime()));
           written += 4;
   
           // CRC
  @@ -669,7 +668,7 @@
           written += 2;
   
           // last mod. time and date
  -        writeOut(toDosTime(new Date(ze.getTime())));
  +        writeOut(toDosTime(ze.getTime()));
           written += 4;
   
           // CRC
  @@ -765,12 +764,10 @@
       /**
        * Convert a Date object to a DOS date/time field.
        *
  -     * <p>Stolen from InfoZip's <code>fileio.c</code></p>
  -     *
        * @since 1.1
        */
       protected static ZipLong toDosTime(Date time) {
  -        return new ZipLong(toDosTime(time));
  +        return new ZipLong(toDosTime(time.getTime()));
       }
   
       /**
  @@ -780,21 +777,19 @@
        *
        * @since 1.26
        */
  -    protected static byte[] toDosTime(Date time) {
  -        Calendar cal = Calendar.getInstance();
  -        cal.setTime(time);
  -        int year = cal.get(Calendar.YEAR);
  +    protected static byte[] toDosTime(long t) {
  +        Date time = new Date(t);
  +        int year = time.getYear() + 1900;
           if (year < 1980) {
               return DOS_TIME_MIN.getBytes();
           }
  -        int month = cal.get(Calendar.MONTH) + 1;
  +        int month = time.getMonth() + 1;
           long value =  ((year - 1980) << 25)
               |         (month << 21)
  -            |              (cal.get(Calendar.DAY_OF_MONTH) << 16)
  -            |         (cal.get(Calendar.HOUR_OF_DAY) << 11)
  -            |         (cal.get(Calendar.MINUTE) << 5)
  -            |         (cal.get(Calendar.SECOND) >> 1);
  -
  +            |         (time.getDate() << 16)
  +            |         (time.getHours() << 11)
  +            |         (time.getMinutes() << 5)
  +            |         (time.getSeconds() >> 1);
           byte[] result = new byte[4];
           result[0] = (byte) ((value & 0xFF));
           result[1] = (byte) ((value & 0xFF00) >> 8);
  
  
  
  1.2       +10 -8     
ant/src/testcases/org/apache/tools/zip/ZipOutputStreamTest.java
  
  Index: ZipOutputStreamTest.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/testcases/org/apache/tools/zip/ZipOutputStreamTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ZipOutputStreamTest.java  5 Nov 2004 14:46:25 -0000       1.1
  +++ ZipOutputStreamTest.java  12 Nov 2004 12:15:13 -0000      1.2
  @@ -21,6 +21,7 @@
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
   
  +import java.util.Calendar;
   import java.util.Date;
   
   public class ZipOutputStreamTest extends TestCase {
  @@ -37,22 +38,23 @@
        
       protected void setUp() throws Exception {
           time = new Date();
  -        byte[] result = new byte[4];
  -        int year = time.getYear() + 1900;
  -        int month = time.getMonth() + 1;
  +        Calendar cal = Calendar.getInstance();
  +        cal.setTime(time);
  +        int year = cal.get(Calendar.YEAR);
  +        int month = cal.get(Calendar.MONTH) + 1;
           long value =  ((year - 1980) << 25)
               |         (month << 21)
  -            |         (time.getDate() << 16)
  -            |         (time.getHours() << 11)
  -            |         (time.getMinutes() << 5)
  -            |         (time.getSeconds() >> 1);
  +            |              (cal.get(Calendar.DAY_OF_MONTH) << 16)
  +            |         (cal.get(Calendar.HOUR_OF_DAY) << 11)
  +            |         (cal.get(Calendar.MINUTE) << 5)
  +            |         (cal.get(Calendar.SECOND) >> 1);
   
  +        byte[] result = new byte[4];
           result[0] = (byte) ((value & 0xFF));
           result[1] = (byte) ((value & 0xFF00) >> 8);
           result[2] = (byte) ((value & 0xFF0000) >> 16);
           result[3] = (byte) ((value & 0xFF000000L) >> 24);
           zl = new ZipLong(result);
  -        
       }
   
       protected void tearDown() throws Exception {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to