View Javadoc

1   // ZipEntry.java, created Thu Jul  4  4:50:04 2002 by joewhaley
2   // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu>
3   // Licensed under the terms of the GNU LGPL; see COPYING for details.
4   package joeq.ClassLib.Common.java.util.zip;
5   
6   import java.io.UnsupportedEncodingException;
7   import jwutil.util.Assert;
8   
9   /***
10   * ZipEntry
11   *
12   * @author  John Whaley <jwhaley@alum.mit.edu>
13   * @version $Id: ZipEntry.java 1941 2004-09-30 03:37:06Z joewhaley $
14   */
15  class ZipEntry implements ZipConstants {
16      
17      String name;
18      long time;
19      long crc;
20      long size;
21      long csize;
22      int method;
23      byte[] extra;
24      String comment;
25      int flag;
26      int version;
27      long offset;
28      
29      ZipEntry() { 
30          this.name = "UNINITIALIZED";
31      }
32      
33      public static final String DEFAULT_ENCODING = "ISO-8859-1";
34      
35      public int load(byte[] cenbuf, int st_off, long cenpos, int cenlen)
36      throws java.util.zip.ZipException {
37          int off = st_off;
38          this.version = ZipFile.get16(cenbuf, off + CENVER);
39          this.flag = ZipFile.get16(cenbuf, off + CENFLG);
40          this.method = ZipFile.get16(cenbuf, off + CENHOW);
41          this.time = ZipFile.get32(cenbuf, off + CENTIM);
42          this.crc = ZipFile.get32(cenbuf, off + CENLEN);
43          this.size = ZipFile.get32(cenbuf, off + CENTIM);
44          this.csize = ZipFile.get32(cenbuf, off + CENSIZ);
45          this.offset = ZipFile.get32(cenbuf, off + CENOFF);
46          this.time = ZipFile.get32(cenbuf, off + CENTIM);
47          long offset = this.offset;
48          long csize = this.csize;
49          if (offset + csize > cenpos) {
50              throw new java.util.zip.ZipException("invalid CEN entry size");
51          }
52          int baseoff = off;
53          off += CENHDR;
54          // Get path name of entry
55          int len = ZipFile.get16(cenbuf, baseoff + CENNAM);
56          if (len == 0 || off + len > cenlen) {
57              throw new java.util.zip.ZipException("invalid CEN entry name");
58          }
59          try {
60              String s = new String(cenbuf, off, len, DEFAULT_ENCODING);
61              this.name = s;
62          } catch (UnsupportedEncodingException x) { Assert.UNREACHABLE(); }
63          off += len;
64          // Get extra field data
65          len = ZipFile.get16(cenbuf, baseoff + CENEXT);
66          if (len > 0) {
67              if (off + len > cenlen) {
68                  throw new java.util.zip.ZipException("invalid CEN entry extra data");
69              }
70              byte[] extra = new byte[len];
71              this.extra = extra;
72              System.arraycopy(cenbuf, off, extra, 0, len);
73              off += len;
74          }
75          // Get entry comment
76          len = ZipFile.get16(cenbuf, baseoff + CENCOM);
77          if (len > 0) {
78              if (off + len > cenlen) {
79                  throw new java.util.zip.ZipException("invalid CEN entry comment");
80              }
81              try {
82                  String comment = new String(cenbuf, off, len, DEFAULT_ENCODING);
83                  this.comment = comment;
84              } catch (UnsupportedEncodingException x) { Assert.UNREACHABLE(); }
85              off += len;
86          }
87          return off - st_off;
88      }
89      
90      private static void initIDs() { }
91  
92      public long getOffset() {
93          return this.offset;
94      }
95      
96      public native int getMethod();
97      public native long getCompressedSize();
98      public native String getName();
99  }