harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r628014 - in /harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util: jar/ zip/
Date Fri, 15 Feb 2008 11:18:58 GMT
Author: tellison
Date: Fri Feb 15 03:18:56 2008
New Revision: 628014

URL: http://svn.apache.org/viewvc?rev=628014&view=rev
Log:
Enhance JavaDoc and code tidy-up in archive module.
No functional changes.

Modified:
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Checksum.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPOutputStream.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
    harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/jar/InitManifest.java
Fri Feb 15 03:18:56 2008
@@ -145,25 +145,19 @@
     private int skipFirstEmptyLines(int start, byte[] buf) {
         int res = start;
         if (buf.length > start) {
-           if ((char)buf[res] == '\r') {
-              res ++;
-              if (res < buf.length) {     
-               if ((char)buf[res] == '\n') {
-                   res ++;  
-                   return skipFirstEmptyLines(res, buf);   
-               } else {
-                  return res; 
-               
-               } 
-              }
-              return res;
-           } else if ((char)buf[res] == '\n') {
-              res ++;  
-              return skipFirstEmptyLines(res, buf);   
-           } else {
-             return res;    
-           }                     
-            
+            if ((char) buf[res] == '\r') {
+                res++;
+                if ((res < buf.length) && ((char) buf[res] == '\n')) {
+                    res++;
+                    return skipFirstEmptyLines(res, buf);
+                }
+                return res;
+            } else if ((char) buf[res] == '\n') {
+                res++;
+                return skipFirstEmptyLines(res, buf);
+            } else {
+                return res;
+            }
         }
         return res;
     }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Checksum.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Checksum.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Checksum.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Checksum.java
Fri Feb 15 03:18:56 2008
@@ -17,12 +17,40 @@
 
 package java.util.zip;
 
+/**
+ * Interface to types that can compute a checksum value of given data.
+ */
 public interface Checksum {
+
+    /**
+     * Answers the computed checksum value so far.
+     * 
+     * @return the checksum value
+     */
     public long getValue();
 
+    /**
+     * Reinitialize the checksum computation to its starting value.
+     */
     public void reset();
 
-    public void update(int val);
-
+    /**
+     * Update the checksum value based on the given byte array
+     * 
+     * @param buf
+     *            the data used to update the checksum
+     * @param off
+     *            the starting point for data values
+     * @param nbytes
+     *            the number of bytes to consider
+     */
     public void update(byte[] buf, int off, int nbytes);
+
+    /**
+     * Update the checksum value based on the given data value.
+     * 
+     * @param val
+     *            a single byte value
+     */
+    public void update(int val);
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPInputStream.java
Fri Feb 15 03:18:56 2008
@@ -26,20 +26,22 @@
 /**
  * The GZIPInputStream class is used to read data stored in the GZIP format.
  */
-public class GZIPInputStream extends java.util.zip.InflaterInputStream {
-    protected CRC32 crc = new CRC32();
+public class GZIPInputStream extends InflaterInputStream {
 
-    protected boolean eos = false;
+    private static final int FCOMMENT = 16;
 
-    public final static int GZIP_MAGIC = 0x8b1f;
+    private static final int FEXTRA = 4;
 
     private static final int FHCRC = 2;
 
-    private static final int FEXTRA = 4;
-
     private static final int FNAME = 8;
 
-    private static final int FCOMMENT = 16;
+    /** Value of GZIP header magic number. */
+    public final static int GZIP_MAGIC = 0x8b1f;
+
+    protected CRC32 crc = new CRC32();
+
+    protected boolean eos = false;
 
     /**
      * Construct a GZIPInputStream to read from GZIP data from the underlying
@@ -47,6 +49,8 @@
      * 
      * @param is
      *            InputStream to read data from
+     * @throws IOException
+     *             if an IO error occurs reading the stream
      */
     public GZIPInputStream(InputStream is) throws IOException {
         this(is, BUF_SIZE);
@@ -60,6 +64,8 @@
      *            InputStream to read data from
      * @param size
      *            Internal read buffer size
+     * @throws IOException
+     *             if an IO exception occurs reading the stream
      */
     public GZIPInputStream(InputStream is, int size) throws IOException {
         super(is, new Inflater(true), size);
@@ -107,6 +113,15 @@
         }
     }
 
+    /**
+     * Closes this stream and any underlying streams.
+     */
+    @Override
+    public void close() throws IOException {
+        eos = true;
+        super.close();
+    }
+
     private long getLong(byte[] buffer, int off) {
         long l = 0;
         l |= (buffer[off] & 0xFF);
@@ -121,7 +136,8 @@
     }
 
     /**
-     * Reads and decompresses GZIP data from the underlying stream into buf.
+     * Reads and decompresses GZIP data from the underlying stream into the
+     * given buffer.
      * 
      * @param buffer
      *            Buffer to receive data
@@ -149,7 +165,7 @@
                 // Get non-compressed bytes read by fill
                 int size = inf.getRemaining();
                 final int trailerSize = 8; // crc (4 bytes) + total out (4
-                                            // bytes)
+                // bytes)
                 byte[] b = new byte[trailerSize];
                 int copySize = (size > trailerSize) ? trailerSize : size;
 
@@ -166,15 +182,6 @@
             return val;
         }
         throw new ArrayIndexOutOfBoundsException();
-    }
-
-    /**
-     * Closes this stream and any underlying streams.
-     */
-    @Override
-    public void close() throws IOException {
-        eos = true;
-        super.close();
     }
 
     private void readFully(byte[] buffer, int offset, int length)

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPOutputStream.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPOutputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/GZIPOutputStream.java
Fri Feb 15 03:18:56 2008
@@ -34,6 +34,8 @@
      * 
      * @param os
      *            OutputStream to write to
+     * @throws IOException
+     *             if an IO error occurs writing to the output stream
      */
     public GZIPOutputStream(OutputStream os) throws IOException {
         this(os, BUF_SIZE);
@@ -47,6 +49,8 @@
      *            OutputStream to write to
      * @param size
      *            Internal buffer size
+     * @throws IOException
+     *             if an IO error occurs writing to the output stream
      */
     public GZIPOutputStream(OutputStream os, int size) throws IOException {
         super(os, new Deflater(Deflater.DEFAULT_COMPRESSION, true), size);
@@ -70,8 +74,8 @@
     }
 
     /**
-     * Write up to nbytes of data from buf, starting at offset off, to the
-     * underlying stream in GZIP format.
+     * Write up to nbytes of data from the given buffer, starting at offset off,
+     * to the underlying stream in GZIP format.
      */
     @Override
     public void write(byte[] buffer, int off, int nbytes) throws IOException {
@@ -79,18 +83,18 @@
         crc.update(buffer, off, nbytes);
     }
 
-    private int writeShort(int i) throws IOException {
-        out.write(i & 0xFF);
-        out.write((i >> 8) & 0xFF);
-        return i;
-    }
-
     private long writeLong(long i) throws IOException {
         // Write out the long value as an unsigned int
         out.write((int) (i & 0xFF));
         out.write((int) (i >> 8) & 0xFF);
         out.write((int) (i >> 16) & 0xFF);
         out.write((int) (i >> 24) & 0xFF);
+        return i;
+    }
+
+    private int writeShort(int i) throws IOException {
+        out.write(i & 0xFF);
+        out.write((i >> 8) & 0xFF);
         return i;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/Inflater.java
Fri Feb 15 03:18:56 2008
@@ -28,28 +28,48 @@
  */
 public class Inflater {
 
+    private static final byte MAGIC_NUMBER = 120;
+
+    static {
+        oneTimeInitialization();
+    }
+
+    // Fill in the JNI id caches
+    private static native void oneTimeInitialization();
+
     private boolean finished; // Set by the inflateImpl native
 
-    private boolean needsDictionary; // Set by the inflateImpl native
+    private boolean gotFirstByte = false;
 
-    private long streamHandle = -1;
+    int inLength;
 
     int inRead;
 
-    int inLength;
+    private boolean needsDictionary; // Set by the inflateImpl native
 
-    // Fill in the JNI id caches
-    private static native void oneTimeInitialization();
+    private boolean pass_magic_number_check = true;
 
-    static {
-        oneTimeInitialization();
-    }
+    private long streamHandle = -1;
 
-    private static final byte MAGIC_NUMBER = 120;
+    /**
+     * Constructs a new Inflater instance.
+     */
+    public Inflater() {
+        this(false);
+    }
 
-    private boolean gotFirstByte = false;
+    /**
+     * Constructs a new Inflater instance. If noHeader is true the Inflater will
+     * not attempt to read a ZLIB header.
+     * 
+     * @param noHeader
+     *            If true, read a ZLIB header from input.
+     */
+    public Inflater(boolean noHeader) {
+        streamHandle = createStream(noHeader);
+    }
 
-    private boolean pass_magic_number_check = true;
+    private native long createStream(boolean noHeader1);
 
     /**
      * Release any resources associated with this Inflater. Any unused
@@ -99,6 +119,38 @@
     private native synchronized int getAdlerImpl(long handle);
 
     /**
+     * Returns a long int of total number of bytes of input read by the
+     * Inflater. This method performs the same as getTotalIn except it returns a
+     * long value instead of an integer
+     * 
+     * @see #getTotalIn()
+     * @return Total bytes read
+     */
+    public synchronized long getBytesRead() {
+        // Throw NPE here
+        if (streamHandle == -1) {
+            throw new NullPointerException();
+        }
+        return getTotalInImpl(streamHandle);
+    }
+
+    /**
+     * Returns a long int of total number of bytes of input output by the
+     * Inflater. This method performs the same as getTotalOut except it returns
+     * a long value instead of an integer
+     * 
+     * @see #getTotalOut()
+     * @return Total bytes output
+     */
+    public synchronized long getBytesWritten() {
+        // Throw NPE here
+        if (streamHandle == -1) {
+            throw new NullPointerException();
+        }
+        return getTotalOutImpl(streamHandle);
+    }
+
+    /**
      * Returns the number of bytes of current input remaining to be read by the
      * inflater
      * 
@@ -203,24 +255,6 @@
             int nbytes, long handle);
 
     /**
-     * Constructs a new Inflater instance.
-     */
-    public Inflater() {
-        this(false);
-    }
-
-    /**
-     * Constructs a new Inflater instance. If noHeader is true the Inflater will
-     * not attempt to read a ZLIB header.
-     * 
-     * @param noHeader
-     *            If true, read a ZLIB header from input.
-     */
-    public Inflater(boolean noHeader) {
-        streamHandle = createStream(noHeader);
-    }
-
-    /**
      * Indicates whether the input bytes were compressed with a preset
      * dictionary. This method should be called prior to inflate() to determine
      * if a dictionary is required. If so setDictionary() should be called with
@@ -234,6 +268,12 @@
         return needsDictionary;
     }
 
+    /**
+     * Answers whether more data is required in the input buffer.
+     * 
+     * @return true if the input buffer is empty, and false otherwise.
+     * @see #setInput(byte[])
+     */
     public synchronized boolean needsInput() {
         return inRead == inLength;
     }
@@ -254,18 +294,33 @@
     private native synchronized void resetImpl(long handle);
 
     /**
-     * Sets the preset dictionary to be used for inflation to buf.
-     * needsDictionary() can be called to determine whether the current input
-     * was deflated using a preset dictionary.
+     * Sets the preset dictionary to be used for inflation.
+     * 
+     * <code>needsDictionary()</code> can be called to determine whether the
+     * current input was deflated using a preset dictionary.
      * 
      * @param buf
      *            The buffer containing the dictionary bytes
-     * @see #needsDictionary
+     * @see #needsDictionary()
      */
     public synchronized void setDictionary(byte[] buf) {
         setDictionary(buf, 0, buf.length);
     }
 
+    /**
+     * Sets the dictionary used to inflate the given data.
+     * 
+     * The dictionary should be set if the {@link #inflate(byte[])} returned
+     * zero bytes inflated and {@link #needsDictionary()} returns
+     * <code>true</code>.
+     * 
+     * @param buf
+     *            the bytes containing the dictionary
+     * @param off
+     *            offset into the buffer to the start of the dictionary
+     * @param nbytes
+     *            length of the dictionary, in bytes
+     */
     public synchronized void setDictionary(byte[] buf, int off, int nbytes) {
         if (streamHandle == -1) {
             throw new IllegalStateException();
@@ -327,40 +382,6 @@
         }
     }
 
-    /**
-     * Returns a long int of total number of bytes of input read by the
-     * Inflater. This method performs the same as getTotalIn except it returns a
-     * long value instead of an integer
-     * 
-     * @see #getTotalIn()
-     * @return Total bytes read
-     */
-    public synchronized long getBytesRead() {
-        // Throw NPE here
-        if (streamHandle == -1) {
-            throw new NullPointerException();
-        }
-        return getTotalInImpl(streamHandle);
-    }
-
-    /**
-     * Returns a long int of total number of bytes of input output by the
-     * Inflater. This method performs the same as getTotalOut except it returns
-     * a long value instead of an integer
-     * 
-     * @see #getTotalOut()
-     * @return Total bytes output
-     */
-    public synchronized long getBytesWritten() {
-        // Throw NPE here
-        if (streamHandle == -1) {
-            throw new NullPointerException();
-        }
-        return getTotalOutImpl(streamHandle);
-    }
-
     private native synchronized void setInputImpl(byte[] buf, int off,
             int nbytes, long handle);
-
-    private native long createStream(boolean noHeader1);
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipFile.java
Fri Feb 15 03:18:56 2008
@@ -35,7 +35,6 @@
  * @see ZipInputStream
  * @see ZipEntry
  */
-
 public class ZipFile implements ZipConstants {
 
     String fileName;
@@ -50,14 +49,10 @@
         ntvinit();
     }
 
-    /**
-     * Open zip file for read.
-     */
+    /** Open ZIP file for read. */
     public static final int OPEN_READ = 1;
 
-    /**
-     * Delete zip file when closed.
-     */
+    /** Delete ZIP file when closed. */
     public static final int OPEN_DELETE = 4;
 
     /**
@@ -65,19 +60,26 @@
      * 
      * @param file
      *            the File
+     * @throws ZipException
+     *             if a ZIP format exception occurs reading the file
+     * @throws IOException
+     *             if an IO exception occurs reading the file
      */
     public ZipFile(File file) throws ZipException, IOException {
         this(file.getPath());
     }
 
     /**
-     * Constructs a new ZipFile opened on the specified File using the specified
+     * Constructs a new ZipFile opened on the specified file using the specified
      * mode.
      * 
      * @param file
-     *            the File
+     *            the file
      * @param mode
-     *            the mode to use, either OPEN_READ or OPEN_READ | OPEN_DELETE
+     *            the mode to use, either <code>OPEN_READ</code> or
+     *            <code>OPEN_READ | OPEN_DELETE</code>
+     * @throws IOException
+     *             if an IO exception occurs reading the file
      */
     public ZipFile(File file, int mode) throws IOException {
         if (mode == OPEN_READ || mode == (OPEN_READ | OPEN_DELETE)) {
@@ -101,6 +103,8 @@
      * 
      * @param filename
      *            the file path name
+     * @throws IOException
+     *             if an IO exception occured reading the file
      */
     public ZipFile(String filename) throws IOException {
         SecurityManager security = System.getSecurityManager();
@@ -135,6 +139,9 @@
 
     /**
      * Closes this ZipFile.
+     * 
+     * @throws IOException
+     *             if an IO exception occured closing the file
      */
     public synchronized void close() throws IOException {
         if (descriptor != -1 && fileName != null) {
@@ -152,9 +159,9 @@
     }
 
     /**
-     * Answers all of the zip entries contained in this ZipFile.
+     * Answers all of the ZIP entries contained in this ZipFile.
      * 
-     * @return an Enumeration of the zip entries
+     * @return an Enumeration of the ZIP entries
      */
     public Enumeration<? extends ZipEntry> entries() {
         return new ZFEnum<ZipEntry>();
@@ -182,6 +189,8 @@
      * @param entry
      *            the ZipEntry
      * @return an input stream on the ZipEntry data
+     * @throws IOException
+     *             if an IO exception occurs reading the data
      */
     public InputStream getInputStream(ZipEntry entry) throws IOException {
         if (descriptor == -1) {

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipInputStream.java
Fri Feb 15 03:18:56 2008
@@ -89,6 +89,9 @@
 
     /**
      * Closes the current zip entry and positions to read the next entry.
+     * 
+     * @throws IOException
+     *             if an IO exception occurs closing the entry
      */
     public void closeEntry() throws IOException {
         if (zipClosed) {
@@ -143,6 +146,10 @@
 
     /**
      * Reads the next zip entry from this ZipInputStream.
+     * 
+     * @return the next entry
+     * @throws IOException
+     *             if an IO exception occurs reading the next entry
      */
     public ZipEntry getNextEntry() throws IOException {
         if (currentEntry != null) {

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java?rev=628014&r1=628013&r2=628014&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/java/util/zip/ZipOutputStream.java
Fri Feb 15 03:18:56 2008
@@ -34,8 +34,10 @@
 public class ZipOutputStream extends DeflaterOutputStream implements
         ZipConstants {
 
+    /** Method for compressed entries */
     public static final int DEFLATED = 8;
 
+    /** Method for uncompressed entries */
     public static final int STORED = 0;
 
     static final int ZIPDataDescriptorFlag = 8;
@@ -307,6 +309,8 @@
     /**
      * Sets the ZipFile comment associated with the file being written.
      * 
+     * @param comment
+     *            the file comment
      */
     public void setComment(String comment) {
         if (comment.length() > 0xFFFF) {
@@ -317,9 +321,10 @@
 
     /**
      * Sets the compression level to be used for writing entry data. This level
-     * may be set on a per entry basis. level must have a value between 0 and
-     * 10.
+     * may be set on a per entry basis.
      * 
+     * @param level
+     *            the compression level, must have a value between 0 and 10.
      */
     public void setLevel(int level) {
         if (level < Deflater.DEFAULT_COMPRESSION



Mime
View raw message