/[classpath]/classpath/java/util/zip/ZipEntry.java
ViewVC logotype

Diff of /classpath/java/util/zip/ZipEntry.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by tromey, Mon Jun 3 22:51:34 2002 UTC revision 1.7 by mark, Fri Nov 29 14:04:19 2002 UTC
# Line 55  public class ZipEntry implements ZipCons Line 55  public class ZipEntry implements ZipCons
55    private static int KNOWN_CRC    = 4;    private static int KNOWN_CRC    = 4;
56    private static int KNOWN_TIME   = 8;    private static int KNOWN_TIME   = 8;
57    
58    private static Calendar cal = Calendar.getInstance();    private static Calendar cal;
59    
60    private String name;    private String name;
61    private int size;    private int size;
62    private int compressedSize;    private int compressedSize;
63    private int crc;    private int crc;
64    private int time;    private int dostime;
65    private short known = 0;    private short known = 0;
66    private short method = -1;    private short method = -1;
67    private byte[] extra = null;    private byte[] extra = null;
68    private String comment = null;    private String comment = null;
69    
   int zipFileIndex = -1;  /* used by ZipFile */  
70    int flags;              /* used by ZipOutputStream */    int flags;              /* used by ZipOutputStream */
71    int offset;             /* used by ZipFile and ZipOutputStream */    int offset;             /* used by ZipFile and ZipOutputStream */
72    
# Line 104  public class ZipEntry implements ZipCons Line 103  public class ZipEntry implements ZipCons
103      size = e.size;      size = e.size;
104      compressedSize = e.compressedSize;      compressedSize = e.compressedSize;
105      crc = e.crc;      crc = e.crc;
106      time = e.time;      dostime = e.dostime;
107      method = e.method;      method = e.method;
108      extra = e.extra;      extra = e.extra;
109      comment = e.comment;      comment = e.comment;
110    }    }
111    
112    void setDOSTime(int dostime)    final void setDOSTime(int dostime)
113    {    {
114      int sec = 2 * (dostime & 0x1f);      this.dostime = dostime;
115      int min = (dostime >> 5) & 0x3f;      known |= KNOWN_TIME;
     int hrs = (dostime >> 11) & 0x1f;  
     int day = (dostime >> 16) & 0x1f;  
     int mon = ((dostime >> 21) & 0xf) - 1;  
     int year = ((dostime >> 25) & 0x7f) + 1980; /* since 1900 */  
       
     // Guard against invalid or missing date causing  
     // IndexOutOfBoundsException.  
     try  
       {  
         synchronized (cal)  
           {  
             cal.set(year, mon, day, hrs, min, sec);  
             time = (int) (cal.getTime().getTime() / 1000L);  
           }  
         known |= KNOWN_TIME;  
       }  
     catch (RuntimeException ex)  
       {  
         /* Ignore illegal time stamp */  
         known &= ~KNOWN_TIME;  
       }  
116    }    }
117    
118    int getDOSTime()    final int getDOSTime()
119    {    {
120      if ((known & KNOWN_TIME) == 0)      if ((known & KNOWN_TIME) == 0)
121        return 0;        return 0;
122      synchronized (cal)      else
123        {        return dostime;
         cal.setTime(new Date(time*1000L));  
         return (cal.get(cal.YEAR) - 1980 & 0x7f) << 25  
           | (cal.get(cal.MONTH) + 1) << 21  
           | (cal.get(cal.DAY_OF_MONTH)) << 16  
           | (cal.get(cal.HOUR_OF_DAY)) << 11  
           | (cal.get(cal.MINUTE)) << 5  
           | (cal.get(cal.SECOND)) >> 1;  
       }  
124    }    }
125    
126    /**    /**
# Line 190  public class ZipEntry implements ZipCons Line 160  public class ZipEntry implements ZipCons
160     */     */
161    public void setTime(long time)    public void setTime(long time)
162    {    {
163      this.time = (int) (time / 1000L);      Calendar cal = getCalendar();
164        synchronized (cal)
165          {
166            cal.setTime(new Date(time*1000L));
167            dostime = (cal.get(cal.YEAR) - 1980 & 0x7f) << 25
168              | (cal.get(cal.MONTH) + 1) << 21
169              | (cal.get(cal.DAY_OF_MONTH)) << 16
170              | (cal.get(cal.HOUR_OF_DAY)) << 11
171              | (cal.get(cal.MINUTE)) << 5
172              | (cal.get(cal.SECOND)) >> 1;
173          }
174        dostime = (int) (dostime / 1000L);
175      this.known |= KNOWN_TIME;      this.known |= KNOWN_TIME;
176    }    }
177    
# Line 200  public class ZipEntry implements ZipCons Line 181  public class ZipEntry implements ZipCons
181     */     */
182    public long getTime()    public long getTime()
183    {    {
184      return (known & KNOWN_TIME) != 0 ? time * 1000L : -1;      if ((known & KNOWN_TIME) == 0)
185          return -1;
186        
187        int sec = 2 * (dostime & 0x1f);
188        int min = (dostime >> 5) & 0x3f;
189        int hrs = (dostime >> 11) & 0x1f;
190        int day = (dostime >> 16) & 0x1f;
191        int mon = ((dostime >> 21) & 0xf) - 1;
192        int year = ((dostime >> 25) & 0x7f) + 1980; /* since 1900 */
193      
194        try
195          {
196            cal = getCalendar();
197            synchronized (cal)
198              {
199                cal.set(year, mon, day, hrs, min, sec);
200                return cal.getTime().getTime();
201              }
202          }
203        catch (RuntimeException ex)
204          {
205            /* Ignore illegal time stamp */
206            known &= ~KNOWN_TIME;
207            return -1;
208          }
209      }
210    
211      private static synchronized Calendar getCalendar()
212      {
213        if (cal == null)
214          cal = Calendar.getInstance();
215    
216        return cal;
217    }    }
218    
219    /**    /**
# Line 320  public class ZipEntry implements ZipCons Line 333  public class ZipEntry implements ZipCons
333                  int flags = extra[pos];                  int flags = extra[pos];
334                  if ((flags & 1) != 0)                  if ((flags & 1) != 0)
335                    {                    {
336                      time = ((extra[pos+1] & 0xff)                      long time = ((extra[pos+1] & 0xff)
337                              | (extra[pos+2] & 0xff) << 8                              | (extra[pos+2] & 0xff) << 8
338                              | (extra[pos+3] & 0xff) << 16                              | (extra[pos+3] & 0xff) << 16
339                              | (extra[pos+4] & 0xff) << 24);                              | (extra[pos+4] & 0xff) << 24);
340                      known |= KNOWN_TIME;                      setTime(time);
341                    }                    }
342                }                }
343              pos += len;              pos += len;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26