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

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

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

revision 1.16.2.2 by gnu_andrew, Sun Jan 16 15:15:13 2005 UTC revision 1.16.2.3 by gnu_andrew, Fri Jan 28 10:43:57 2005 UTC
# Line 1  Line 1 
1  /* ZipFile.java --  /* ZipFile.java --
2     Copyright (C) 2001, 2002, 2003, 2004  Free Software Foundation, Inc.     Copyright (C) 2001, 2002, 2003, 2004, 2005
3       Free Software Foundation, Inc.
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
6    
# Line 38  exception statement from your version. * Line 39  exception statement from your version. *
39    
40  package java.util.zip;  package java.util.zip;
41    
42    import gnu.java.util.EmptyEnumeration;
43    
44  import java.io.BufferedInputStream;  import java.io.BufferedInputStream;
45  import java.io.DataInput;  import java.io.DataInput;
46  import java.io.EOFException;  import java.io.EOFException;
# Line 94  public class ZipFile implements ZipConst Line 97  public class ZipFile implements ZipConst
97    {    {
98      this.raf = new RandomAccessFile(name, "r");      this.raf = new RandomAccessFile(name, "r");
99      this.name = name;      this.name = name;
100        checkZipFile();
101    }    }
102    
103    /**    /**
# Line 106  public class ZipFile implements ZipConst Line 110  public class ZipFile implements ZipConst
110    {    {
111      this.raf = new RandomAccessFile(file, "r");      this.raf = new RandomAccessFile(file, "r");
112      this.name = file.getPath();      this.name = file.getPath();
113        checkZipFile();
114    }    }
115    
116    /**    /**
# Line 135  public class ZipFile implements ZipConst Line 140  public class ZipFile implements ZipConst
140        }        }
141      this.raf = new RandomAccessFile(file, "r");      this.raf = new RandomAccessFile(file, "r");
142      this.name = file.getPath();      this.name = file.getPath();
143        checkZipFile();
144      }
145    
146      private void checkZipFile() throws IOException, ZipException
147      {
148        byte[] magicBuf = new byte[4];
149        raf.read(magicBuf);
150    
151        if (readLeInt(magicBuf, 0) != LOCSIG)
152          {
153            raf.close();
154            throw new ZipException("Not a valid zip file");
155          }
156      }
157    
158      /**
159       * Checks if file is closed and throws an exception.
160       */
161      private void checkClosed()
162      {
163        if (closed)
164          throw new IllegalStateException("ZipFile has closed: " + name);
165    }    }
166    
167    /**    /**
# Line 312  public class ZipFile implements ZipConst Line 339  public class ZipFile implements ZipConst
339    
340    /**    /**
341     * Returns an enumeration of all Zip entries in this Zip file.     * Returns an enumeration of all Zip entries in this Zip file.
342       *
343       * @exception IllegalStateException when the ZipFile has already been closed
344     */     */
345    public Enumeration entries()    public Enumeration entries()
346    {    {
347        checkClosed();
348        
349      try      try
350        {        {
351          return new ZipEntryEnumeration(getEntries().values().iterator());          return new ZipEntryEnumeration(getEntries().values().iterator());
352        }        }
353      catch (IOException ioe)      catch (IOException ioe)
354        {        {
355          return null;          return EmptyEnumeration.getInstance();
356        }        }
357    }    }
358    
# Line 335  public class ZipFile implements ZipConst Line 366  public class ZipFile implements ZipConst
366    {    {
367      synchronized(raf)      synchronized(raf)
368        {        {
369          if (closed)          checkClosed();
           throw new IllegalStateException("ZipFile has closed: " + name);  
370    
371          if (entries == null)          if (entries == null)
372            readEntries();            readEntries();
# Line 351  public class ZipFile implements ZipConst Line 381  public class ZipFile implements ZipConst
381     * @param the name. May contain directory components separated by     * @param the name. May contain directory components separated by
382     * slashes ('/').     * slashes ('/').
383     * @return the zip entry, or null if no entry with that name exists.     * @return the zip entry, or null if no entry with that name exists.
384       *
385       * @exception IllegalStateException when the ZipFile has already been closed
386     */     */
387    public ZipEntry getEntry(String name)    public ZipEntry getEntry(String name)
388    {    {
389        checkClosed();
390    
391      try      try
392        {        {
393          HashMap entries = getEntries();          HashMap entries = getEntries();
# Line 423  public class ZipFile implements ZipConst Line 457  public class ZipFile implements ZipConst
457     * @param entry the entry to create an InputStream for.     * @param entry the entry to create an InputStream for.
458     * @return the input stream, or null if the requested entry does not exist.     * @return the input stream, or null if the requested entry does not exist.
459     *     *
460       * @exception IllegalStateException when the ZipFile has already been closed
461     * @exception IOException if a i/o error occured.     * @exception IOException if a i/o error occured.
462     * @exception ZipException if the Zip archive is malformed.       * @exception ZipException if the Zip archive is malformed.  
463     */     */
464    public InputStream getInputStream(ZipEntry entry) throws IOException    public InputStream getInputStream(ZipEntry entry) throws IOException
465    {    {
466        checkClosed();
467    
468      HashMap entries = getEntries();      HashMap entries = getEntries();
469      String name = entry.getName();      String name = entry.getName();
470      ZipEntry zipEntry = (ZipEntry) entries.get(name);      ZipEntry zipEntry = (ZipEntry) entries.get(name);
# Line 459  public class ZipFile implements ZipConst Line 496  public class ZipFile implements ZipConst
496    
497    /**    /**
498     * Returns the number of entries in this zip file.     * Returns the number of entries in this zip file.
499       *
500       * @exception IllegalStateException when the ZipFile has already been closed
501     */     */
502    public int size()    public int size()
503    {    {
504        checkClosed();
505        
506      try      try
507        {        {
508          return getEntries().size();          return getEntries().size();

Legend:
Removed from v.1.16.2.2  
changed lines
  Added in v.1.16.2.3

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