harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r556570 [3/3] - in /harmony/enhanced/classlib/trunk/modules/archive/src/main/java: java/util/jar/ java/util/zip/ org/apache/harmony/archive/internal/nls/ org/apache/harmony/archive/util/
Date Mon, 16 Jul 2007 09:22:24 GMT
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?view=diff&rev=556570&r1=556569&r2=556570
==============================================================================
--- 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
Mon Jul 16 02:22:19 2007
@@ -17,7 +17,6 @@
 
 package java.util.zip;
 
-
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -35,48 +34,48 @@
  * @see ZipFile
  */
 public class ZipInputStream extends InflaterInputStream implements ZipConstants {
-	static final int DEFLATED = 8;
+    static final int DEFLATED = 8;
 
-	static final int STORED = 0;
+    static final int STORED = 0;
 
-	static final int ZIPDataDescriptorFlag = 8;
+    static final int ZIPDataDescriptorFlag = 8;
 
-	static final int ZIPLocalHeaderVersionNeeded = 20;
+    static final int ZIPLocalHeaderVersionNeeded = 20;
 
-	private boolean zipClosed = false;
+    private boolean zipClosed = false;
 
-	private boolean entriesEnd = false;
+    private boolean entriesEnd = false;
 
-	private boolean hasDD = false;
+    private boolean hasDD = false;
 
-	private int entryIn = 0;
+    private int entryIn = 0;
 
-	private int inRead, lastRead = 0;
+    private int inRead, lastRead = 0;
 
-	ZipEntry currentEntry;
+    ZipEntry currentEntry;
 
-	private final byte[] hdrBuf = new byte[LOCHDR - LOCVER];
+    private final byte[] hdrBuf = new byte[LOCHDR - LOCVER];
 
-	private final CRC32 crc = new CRC32();
+    private final CRC32 crc = new CRC32();
 
-	private byte[] nameBuf = new byte[256];
+    private byte[] nameBuf = new byte[256];
 
-	private char[] charBuf = new char[256];
+    private char[] charBuf = new char[256];
 
-	/**
-	 * Constructs a new ZipInputStream on the specified input stream.
-	 * 
-	 * @param stream
-	 *            the input stream
-	 */
-	public ZipInputStream(InputStream stream) {
-		super(new PushbackInputStream(stream, BUF_SIZE), new Inflater(true));
-		if (stream == null) {
+    /**
+     * Constructs a new ZipInputStream on the specified input stream.
+     * 
+     * @param stream
+     *            the input stream
+     */
+    public ZipInputStream(InputStream stream) {
+        super(new PushbackInputStream(stream, BUF_SIZE), new Inflater(true));
+        if (stream == null) {
             throw new NullPointerException();
         }
-	}
+    }
 
-	/**
+    /**
      * Closes this ZipInputStream.
      */
     @Override
@@ -88,283 +87,283 @@
         }
     }
 
-	/**
-	 * Closes the current zip entry and positions to read the next entry.
-	 */
-	public void closeEntry() throws IOException {
-		if (zipClosed) {
+    /**
+     * Closes the current zip entry and positions to read the next entry.
+     */
+    public void closeEntry() throws IOException {
+        if (zipClosed) {
             throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
         }
-		if (currentEntry == null) {
+        if (currentEntry == null) {
             return;
         }
-		if (currentEntry instanceof java.util.jar.JarEntry) {
-			Attributes temp = ((JarEntry) currentEntry).getAttributes();
-			if (temp != null && temp.containsKey("hidden")) { //$NON-NLS-1$
+        if (currentEntry instanceof java.util.jar.JarEntry) {
+            Attributes temp = ((JarEntry) currentEntry).getAttributes();
+            if (temp != null && temp.containsKey("hidden")) { //$NON-NLS-1$
                 return;
             }
-		}
-		// Ensure all entry bytes are read
-		skip(Long.MAX_VALUE);
-		int inB, out;
-		if (currentEntry.compressionMethod == DEFLATED) {
-			inB = inf.getTotalIn();
-			out = inf.getTotalOut();
-		} else {
-			inB = inRead;
-			out = inRead;
-		}
-		int diff = 0;
-		// Pushback any required bytes
-		if ((diff = entryIn - inB) != 0) {
+        }
+        // Ensure all entry bytes are read
+        skip(Long.MAX_VALUE);
+        int inB, out;
+        if (currentEntry.compressionMethod == DEFLATED) {
+            inB = inf.getTotalIn();
+            out = inf.getTotalOut();
+        } else {
+            inB = inRead;
+            out = inRead;
+        }
+        int diff = 0;
+        // Pushback any required bytes
+        if ((diff = entryIn - inB) != 0) {
             ((PushbackInputStream) in).unread(buf, len - diff, diff);
         }
 
-		if (hasDD) {
-			in.read(hdrBuf, 0, EXTHDR);
-			if (getLong(hdrBuf, 0) != EXTSIG) {
+        if (hasDD) {
+            in.read(hdrBuf, 0, EXTHDR);
+            if (getLong(hdrBuf, 0) != EXTSIG) {
                 throw new ZipException(Messages.getString("archive.1F")); //$NON-NLS-1$
             }
-			currentEntry.crc = getLong(hdrBuf, EXTCRC);
-			currentEntry.compressedSize = getLong(hdrBuf, EXTSIZ);
-			currentEntry.size = getLong(hdrBuf, EXTLEN);
-		}
-		if (currentEntry.crc != crc.getValue()) {
+            currentEntry.crc = getLong(hdrBuf, EXTCRC);
+            currentEntry.compressedSize = getLong(hdrBuf, EXTSIZ);
+            currentEntry.size = getLong(hdrBuf, EXTLEN);
+        }
+        if (currentEntry.crc != crc.getValue()) {
             throw new ZipException(Messages.getString("archive.20")); //$NON-NLS-1$
         }
-		if (currentEntry.compressedSize != inB || currentEntry.size != out) {
+        if (currentEntry.compressedSize != inB || currentEntry.size != out) {
             throw new ZipException(Messages.getString("archive.21")); //$NON-NLS-1$
         }
 
-		inf.reset();
-		lastRead = inRead = entryIn = len = 0;
-		crc.reset();
-		currentEntry = null;
-	}
-
-	/**
-	 * Reads the next zip entry from this ZipInputStream.
-	 */
-	public ZipEntry getNextEntry() throws IOException {
-		if (currentEntry != null) {
+        inf.reset();
+        lastRead = inRead = entryIn = len = 0;
+        crc.reset();
+        currentEntry = null;
+    }
+
+    /**
+     * Reads the next zip entry from this ZipInputStream.
+     */
+    public ZipEntry getNextEntry() throws IOException {
+        if (currentEntry != null) {
             closeEntry();
         }
-		if (entriesEnd) {
+        if (entriesEnd) {
             return null;
         }
 
-		int x = 0, count = 0;
-		while (count != 4) {
-			count += x = in.read(hdrBuf, count, 4 - count);
-			if (x == -1) {
+        int x = 0, count = 0;
+        while (count != 4) {
+            count += x = in.read(hdrBuf, count, 4 - count);
+            if (x == -1) {
                 return null;
             }
-		}
-		long hdr = getLong(hdrBuf, 0);
-		if (hdr == CENSIG) {
-			entriesEnd = true;
-			return null;
-		}
-		if (hdr != LOCSIG) {
+        }
+        long hdr = getLong(hdrBuf, 0);
+        if (hdr == CENSIG) {
+            entriesEnd = true;
+            return null;
+        }
+        if (hdr != LOCSIG) {
             return null;
         }
 
-		// Read the local header
-		count = 0;
-		while (count != (LOCHDR - LOCVER)) {
-			count += x = in.read(hdrBuf, count, (LOCHDR - LOCVER) - count);
-			if (x == -1) {
+        // Read the local header
+        count = 0;
+        while (count != (LOCHDR - LOCVER)) {
+            count += x = in.read(hdrBuf, count, (LOCHDR - LOCVER) - count);
+            if (x == -1) {
                 throw new EOFException();
             }
-		}
-		int version = getShort(hdrBuf, 0) & 0xff;
-		if (version > ZIPLocalHeaderVersionNeeded) {
+        }
+        int version = getShort(hdrBuf, 0) & 0xff;
+        if (version > ZIPLocalHeaderVersionNeeded) {
             throw new ZipException(Messages.getString("archive.22")); //$NON-NLS-1$
         }
-		int flags = getShort(hdrBuf, LOCFLG - LOCVER);
-		hasDD = ((flags & ZIPDataDescriptorFlag) == ZIPDataDescriptorFlag);
-		int cetime = getShort(hdrBuf, LOCTIM - LOCVER);
-		int cemodDate = getShort(hdrBuf, LOCTIM - LOCVER + 2);
-		int cecompressionMethod = getShort(hdrBuf, LOCHOW - LOCVER);
-		long cecrc = 0, cecompressedSize = 0, cesize = -1;
-		if (!hasDD) {
-			cecrc = getLong(hdrBuf, LOCCRC - LOCVER);
-			cecompressedSize = getLong(hdrBuf, LOCSIZ - LOCVER);
-			cesize = getLong(hdrBuf, LOCLEN - LOCVER);
-		}
-		int flen = getShort(hdrBuf, LOCNAM - LOCVER);
-		if (flen == 0) {
+        int flags = getShort(hdrBuf, LOCFLG - LOCVER);
+        hasDD = ((flags & ZIPDataDescriptorFlag) == ZIPDataDescriptorFlag);
+        int cetime = getShort(hdrBuf, LOCTIM - LOCVER);
+        int cemodDate = getShort(hdrBuf, LOCTIM - LOCVER + 2);
+        int cecompressionMethod = getShort(hdrBuf, LOCHOW - LOCVER);
+        long cecrc = 0, cecompressedSize = 0, cesize = -1;
+        if (!hasDD) {
+            cecrc = getLong(hdrBuf, LOCCRC - LOCVER);
+            cecompressedSize = getLong(hdrBuf, LOCSIZ - LOCVER);
+            cesize = getLong(hdrBuf, LOCLEN - LOCVER);
+        }
+        int flen = getShort(hdrBuf, LOCNAM - LOCVER);
+        if (flen == 0) {
             throw new ZipException(Messages.getString("archive.23")); //$NON-NLS-1$
         }
-		int elen = getShort(hdrBuf, LOCEXT - LOCVER);
+        int elen = getShort(hdrBuf, LOCEXT - LOCVER);
 
-		count = 0;
-		if (flen > nameBuf.length) {
-			nameBuf = new byte[flen];
-			charBuf = new char[flen];
-		}
-		while (count != flen) {
-			count += x = in.read(nameBuf, count, flen - count);
-			if (x == -1) {
+        count = 0;
+        if (flen > nameBuf.length) {
+            nameBuf = new byte[flen];
+            charBuf = new char[flen];
+        }
+        while (count != flen) {
+            count += x = in.read(nameBuf, count, flen - count);
+            if (x == -1) {
                 throw new EOFException();
             }
-		}
-		currentEntry = createZipEntry(Util.convertUTF8WithBuf(nameBuf, charBuf,
-				0, flen));
-		currentEntry.time = cetime;
-		currentEntry.modDate = cemodDate;
-		currentEntry.setMethod(cecompressionMethod);
-		if (cesize != -1) {
-			currentEntry.setCrc(cecrc);
-			currentEntry.setSize(cesize);
-			currentEntry.setCompressedSize(cecompressedSize);
-		}
-		if (elen > 0) {
-			count = 0;
-			byte[] e = new byte[elen];
-			while (count != elen) {
-				count += x = in.read(e, count, elen - count);
-				if (x == -1) {
+        }
+        currentEntry = createZipEntry(Util.convertUTF8WithBuf(nameBuf, charBuf,
+                0, flen));
+        currentEntry.time = cetime;
+        currentEntry.modDate = cemodDate;
+        currentEntry.setMethod(cecompressionMethod);
+        if (cesize != -1) {
+            currentEntry.setCrc(cecrc);
+            currentEntry.setSize(cesize);
+            currentEntry.setCompressedSize(cecompressedSize);
+        }
+        if (elen > 0) {
+            count = 0;
+            byte[] e = new byte[elen];
+            while (count != elen) {
+                count += x = in.read(e, count, elen - count);
+                if (x == -1) {
                     throw new EOFException();
                 }
-			}
-			currentEntry.setExtra(e);
-		}
-		return currentEntry;
-	}
-
-	/* Read 4 bytes from the buffer and store it as an int */
-
-	/**
-	 * Reads up to the specified number of uncompressed bytes into the buffer
-	 * starting at the offset.
-	 * 
-	 * @param buffer
-	 *            a byte array
-	 * @param start
-	 *            the starting offset into the buffer
-	 * @param length
-	 *            the number of bytes to read
-	 * @return the number of bytes read
-	 */
-	@Override
+            }
+            currentEntry.setExtra(e);
+        }
+        return currentEntry;
+    }
+
+    /* Read 4 bytes from the buffer and store it as an int */
+
+    /**
+     * Reads up to the specified number of uncompressed bytes into the buffer
+     * starting at the offset.
+     * 
+     * @param buffer
+     *            a byte array
+     * @param start
+     *            the starting offset into the buffer
+     * @param length
+     *            the number of bytes to read
+     * @return the number of bytes read
+     */
+    @Override
     public int read(byte[] buffer, int start, int length) throws IOException {
-		if (zipClosed) {
+        if (zipClosed) {
             throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
         }
-		if (inf.finished() || currentEntry == null) {
+        if (inf.finished() || currentEntry == null) {
             return -1;
         }
-		// avoid int overflow, check null buffer
-		if (start <= buffer.length && length >= 0 && start >= 0
-				&& buffer.length - start >= length) {
-			if (currentEntry.compressionMethod == STORED) {
-				int csize = (int) currentEntry.size;
-				if (inRead >= csize) {
+        // avoid int overflow, check null buffer
+        if (start <= buffer.length && length >= 0 && start >= 0
+                && buffer.length - start >= length) {
+            if (currentEntry.compressionMethod == STORED) {
+                int csize = (int) currentEntry.size;
+                if (inRead >= csize) {
                     return -1;
                 }
-				if (lastRead >= len) {
-					lastRead = 0;
-					if ((len = in.read(buf)) == -1) {
+                if (lastRead >= len) {
+                    lastRead = 0;
+                    if ((len = in.read(buf)) == -1) {
                         return -1;
                     }
-					entryIn += len;
-				}
-				int toRead = length > len ? len - lastRead : length;
-				if ((csize - inRead) < toRead) {
+                    entryIn += len;
+                }
+                int toRead = length > len ? len - lastRead : length;
+                if ((csize - inRead) < toRead) {
                     toRead = csize - inRead;
                 }
-				System.arraycopy(buf, lastRead, buffer, start, toRead);
-				lastRead += toRead;
-				inRead += toRead;
-				crc.update(buffer, start, toRead);
-				return toRead;
-			}
-			if (inf.needsInput()) {
-				fill();
-				if (len > 0) {
+                System.arraycopy(buf, lastRead, buffer, start, toRead);
+                lastRead += toRead;
+                inRead += toRead;
+                crc.update(buffer, start, toRead);
+                return toRead;
+            }
+            if (inf.needsInput()) {
+                fill();
+                if (len > 0) {
                     entryIn += len;
                 }
-			}
-			int read = 0;
-			try {
-				read = inf.inflate(buffer, start, length);
-			} catch (DataFormatException e) {
-				throw new ZipException(e.getMessage());
-			}
-			if (read == 0 && inf.finished()) {
+            }
+            int read = 0;
+            try {
+                read = inf.inflate(buffer, start, length);
+            } catch (DataFormatException e) {
+                throw new ZipException(e.getMessage());
+            }
+            if (read == 0 && inf.finished()) {
                 return -1;
             }
-			crc.update(buffer, start, read);
-			return read;
-		}
-		throw new ArrayIndexOutOfBoundsException();
-	}
-
-	/**
-	 * Skips up to the specified number of bytes in the current zip entry.
-	 * 
-	 * @param value
-	 *            the number of bytes to skip
-	 * @return the number of bytes skipped
-	 */
-	@Override
+            crc.update(buffer, start, read);
+            return read;
+        }
+        throw new ArrayIndexOutOfBoundsException();
+    }
+
+    /**
+     * Skips up to the specified number of bytes in the current zip entry.
+     * 
+     * @param value
+     *            the number of bytes to skip
+     * @return the number of bytes skipped
+     */
+    @Override
     public long skip(long value) throws IOException {
-		if (value >= 0) {
-			long skipped = 0;
-			byte[] b = new byte[1024];
-			while (skipped != value) {
-				long rem = value - skipped;
-				int x = read(b, 0, (int) (b.length > rem ? rem : b.length));
-				if (x == -1) {
+        if (value >= 0) {
+            long skipped = 0;
+            byte[] b = new byte[1024];
+            while (skipped != value) {
+                long rem = value - skipped;
+                int x = read(b, 0, (int) (b.length > rem ? rem : b.length));
+                if (x == -1) {
                     return skipped;
                 }
-				skipped += x;
-			}
-			return skipped;
-		}
+                skipped += x;
+            }
+            return skipped;
+        }
         throw new IllegalArgumentException();
-}
+    }
 
-	/**
-	 * Answers 1 if the EOF has been reached, otherwise returns 0.
-	 * 
-	 * @return 0 after EOF of current entry, 1 otherwise
-	 */
-	@Override
+    /**
+     * Answers 1 if the EOF has been reached, otherwise returns 0.
+     * 
+     * @return 0 after EOF of current entry, 1 otherwise
+     */
+    @Override
     public int available() throws IOException {
-		if (zipClosed) {
+        if (zipClosed) {
             throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
         }
-		if (currentEntry == null) {
+        if (currentEntry == null) {
             return 1;
         }
-		if (currentEntry.compressionMethod == STORED) {
-			if (inRead >= currentEntry.size) {
+        if (currentEntry.compressionMethod == STORED) {
+            if (inRead >= currentEntry.size) {
                 return 0;
             }
-		} else {
-			if (inf.finished()) {
+        } else {
+            if (inf.finished()) {
                 return 0;
             }
-		}
-		return 1;
-	}
-
-	protected ZipEntry createZipEntry(String name) {
-		return new ZipEntry(name);
-	}
-
-	private int getShort(byte[] buffer, int off) {
-		return (buffer[off] & 0xFF) | ((buffer[off + 1] & 0xFF) << 8);
-	}
-
-	private long getLong(byte[] buffer, int off) {
-		long l = 0;
-		l |= (buffer[off] & 0xFF);
-		l |= (buffer[off + 1] & 0xFF) << 8;
-		l |= (buffer[off + 2] & 0xFF) << 16;
-		l |= ((long) (buffer[off + 3] & 0xFF)) << 24;
-		return l;
-	}
+        }
+        return 1;
+    }
+
+    protected ZipEntry createZipEntry(String name) {
+        return new ZipEntry(name);
+    }
+
+    private int getShort(byte[] buffer, int off) {
+        return (buffer[off] & 0xFF) | ((buffer[off + 1] & 0xFF) << 8);
+    }
+
+    private long getLong(byte[] buffer, int off) {
+        long l = 0;
+        l |= (buffer[off] & 0xFF);
+        l |= (buffer[off + 1] & 0xFF) << 8;
+        l |= (buffer[off + 2] & 0xFF) << 16;
+        l |= ((long) (buffer[off + 3] & 0xFF)) << 24;
+        return l;
+    }
 }

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?view=diff&rev=556570&r1=556569&r2=556570
==============================================================================
--- 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
Mon Jul 16 02:22:19 2007
@@ -17,7 +17,6 @@
 
 package java.util.zip;
 
-
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -33,392 +32,393 @@
  * @see ZipEntry
  */
 public class ZipOutputStream extends DeflaterOutputStream implements
-		ZipConstants {
+        ZipConstants {
 
-	public static final int DEFLATED = 8;
+    public static final int DEFLATED = 8;
 
-	public static final int STORED = 0;
+    public static final int STORED = 0;
 
-	static final int ZIPDataDescriptorFlag = 8;
+    static final int ZIPDataDescriptorFlag = 8;
 
-	static final int ZIPLocalHeaderVersionNeeded = 20;
+    static final int ZIPLocalHeaderVersionNeeded = 20;
 
-	private String comment;
+    private String comment;
 
-	private final Vector<String> entries = new Vector<String>();
+    private final Vector<String> entries = new Vector<String>();
 
-	private int compressMethod = DEFLATED;
+    private int compressMethod = DEFLATED;
 
-	private int compressLevel = Deflater.DEFAULT_COMPRESSION;
+    private int compressLevel = Deflater.DEFAULT_COMPRESSION;
 
-	private ByteArrayOutputStream cDir = new ByteArrayOutputStream();
+    private ByteArrayOutputStream cDir = new ByteArrayOutputStream();
 
-	private ZipEntry currentEntry;
+    private ZipEntry currentEntry;
 
-	private final CRC32 crc = new CRC32();
+    private final CRC32 crc = new CRC32();
 
-	private int offset = 0, curOffset = 0, nameLength;
+    private int offset = 0, curOffset = 0, nameLength;
 
-	private byte[] nameBytes;
+    private byte[] nameBytes;
 
-	/**
-	 * Constructs a new ZipOutputStream on p1
-	 * 
-	 * @param p1
-	 *            OutputStream The InputStream to output to
-	 */
-	public ZipOutputStream(OutputStream p1) {
-		super(p1, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
-	}
+    /**
+     * Constructs a new ZipOutputStream on p1
+     * 
+     * @param p1
+     *            OutputStream The InputStream to output to
+     */
+    public ZipOutputStream(OutputStream p1) {
+        super(p1, new Deflater(Deflater.DEFAULT_COMPRESSION, true));
+    }
 
-	/**
-	 * Closes the current ZipEntry if any. Closes the underlying output stream.
-	 * If the stream is already closed this method does nothing.
-	 * 
-	 * @exception IOException
-	 *                If an error occurs closing the stream
-	 */
-	@Override
+    /**
+     * Closes the current ZipEntry if any. Closes the underlying output stream.
+     * If the stream is already closed this method does nothing.
+     * 
+     * @exception IOException
+     *                If an error occurs closing the stream
+     */
+    @Override
     public void close() throws IOException {
-		if (out != null) {
-			finish();
-			out.close();
-			out = null;
-		}
-	}
-
-	/**
-	 * Closes the current ZipEntry. Any entry terminal data is written to the
-	 * underlying stream.
-	 * 
-	 * @exception IOException
-	 *                If an error occurs closing the entry
-	 */
-	public void closeEntry() throws IOException {
-		if (cDir == null) {
+        if (out != null) {
+            finish();
+            out.close();
+            out = null;
+        }
+    }
+
+    /**
+     * Closes the current ZipEntry. Any entry terminal data is written to the
+     * underlying stream.
+     * 
+     * @exception IOException
+     *                If an error occurs closing the entry
+     */
+    public void closeEntry() throws IOException {
+        if (cDir == null) {
             throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
         }
-		if (currentEntry == null) {
+        if (currentEntry == null) {
             return;
         }
-		if (currentEntry.getMethod() == DEFLATED) {
-			super.finish();
-		}
-
-		// Verify values for STORED types
-		if (currentEntry.getMethod() == STORED) {
-			if (crc.getValue() != currentEntry.crc) {
+        if (currentEntry.getMethod() == DEFLATED) {
+            super.finish();
+        }
+
+        // Verify values for STORED types
+        if (currentEntry.getMethod() == STORED) {
+            if (crc.getValue() != currentEntry.crc) {
                 throw new ZipException(Messages.getString("archive.20")); //$NON-NLS-1$
             }
-			if (currentEntry.size != crc.tbytes) {
+            if (currentEntry.size != crc.tbytes) {
                 throw new ZipException(Messages.getString("archive.21")); //$NON-NLS-1$
             }
-		}
-		curOffset = LOCHDR;
+        }
+        curOffset = LOCHDR;
 
-		// Write the DataDescriptor
-		if (currentEntry.getMethod() != STORED) {
-			curOffset += EXTHDR;
-			writeLong(out, EXTSIG);
-			writeLong(out, currentEntry.crc = crc.getValue());
-			writeLong(out, currentEntry.compressedSize = def.getTotalOut());
-			writeLong(out, currentEntry.size = def.getTotalIn());
-		}
-		// Update the CentralDirectory
-		writeLong(cDir, CENSIG);
-		writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version created
-		writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version to extract
-		writeShort(cDir, currentEntry.getMethod() == STORED ? 0
-				: ZIPDataDescriptorFlag);
-		writeShort(cDir, currentEntry.getMethod());
-		writeShort(cDir, currentEntry.time);
-		writeShort(cDir, currentEntry.modDate);
-		writeLong(cDir, crc.getValue());
-		if (currentEntry.getMethod() == DEFLATED) {
-			curOffset += writeLong(cDir, def.getTotalOut());
-			writeLong(cDir, def.getTotalIn());
-		} else {
-			curOffset += writeLong(cDir, crc.tbytes);
-			writeLong(cDir, crc.tbytes);
-		}
-		curOffset += writeShort(cDir, nameLength);
-		if (currentEntry.extra != null) {
+        // Write the DataDescriptor
+        if (currentEntry.getMethod() != STORED) {
+            curOffset += EXTHDR;
+            writeLong(out, EXTSIG);
+            writeLong(out, currentEntry.crc = crc.getValue());
+            writeLong(out, currentEntry.compressedSize = def.getTotalOut());
+            writeLong(out, currentEntry.size = def.getTotalIn());
+        }
+        // Update the CentralDirectory
+        writeLong(cDir, CENSIG);
+        writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version created
+        writeShort(cDir, ZIPLocalHeaderVersionNeeded); // Version to extract
+        writeShort(cDir, currentEntry.getMethod() == STORED ? 0
+                : ZIPDataDescriptorFlag);
+        writeShort(cDir, currentEntry.getMethod());
+        writeShort(cDir, currentEntry.time);
+        writeShort(cDir, currentEntry.modDate);
+        writeLong(cDir, crc.getValue());
+        if (currentEntry.getMethod() == DEFLATED) {
+            curOffset += writeLong(cDir, def.getTotalOut());
+            writeLong(cDir, def.getTotalIn());
+        } else {
+            curOffset += writeLong(cDir, crc.tbytes);
+            writeLong(cDir, crc.tbytes);
+        }
+        curOffset += writeShort(cDir, nameLength);
+        if (currentEntry.extra != null) {
             curOffset += writeShort(cDir, currentEntry.extra.length);
         } else {
             writeShort(cDir, 0);
         }
-		String c;
-		if ((c = currentEntry.getComment()) != null) {
+        String c;
+        if ((c = currentEntry.getComment()) != null) {
             writeShort(cDir, c.length());
         } else {
             writeShort(cDir, 0);
         }
-		writeShort(cDir, 0); // Disk Start
-		writeShort(cDir, 0); // Internal File Attributes
-		writeLong(cDir, 0); // External File Attributes
-		writeLong(cDir, offset);
-		cDir.write(nameBytes);
-		nameBytes = null;
-		if (currentEntry.extra != null) {
+        writeShort(cDir, 0); // Disk Start
+        writeShort(cDir, 0); // Internal File Attributes
+        writeLong(cDir, 0); // External File Attributes
+        writeLong(cDir, offset);
+        cDir.write(nameBytes);
+        nameBytes = null;
+        if (currentEntry.extra != null) {
             cDir.write(currentEntry.extra);
         }
-		offset += curOffset;
-		if (c != null) {
+        offset += curOffset;
+        if (c != null) {
             cDir.write(c.getBytes());
         }
-		currentEntry = null;
-		crc.reset();
-		def.reset();
-		done = false;
-	}
-
-	/**
-	 * Indicates that all entries have been written to the stream. Any terminal
-	 * ZipFile information is written to the underlying stream.
-	 * 
-	 * @exception IOException
-	 *                If an error occurs while finishing
-	 */
-	@Override
+        currentEntry = null;
+        crc.reset();
+        def.reset();
+        done = false;
+    }
+
+    /**
+     * Indicates that all entries have been written to the stream. Any terminal
+     * ZipFile information is written to the underlying stream.
+     * 
+     * @exception IOException
+     *                If an error occurs while finishing
+     */
+    @Override
     public void finish() throws IOException {
-		if (out == null) {
+        if (out == null) {
             throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
         }
-		if (cDir == null) {
+        if (cDir == null) {
             return;
         }
-		if (entries.size() == 0) {
+        if (entries.size() == 0) {
             throw new ZipException(Messages.getString("archive.28")); //$NON-NLS-1$;
         }
-		if (currentEntry != null) {
+        if (currentEntry != null) {
             closeEntry();
         }
-		int cdirSize = cDir.size();
-		// Write Central Dir End
-		writeLong(cDir, ENDSIG);
-		writeShort(cDir, 0); // Disk Number
-		writeShort(cDir, 0); // Start Disk
-		writeShort(cDir, entries.size()); // Number of entries
-		writeShort(cDir, entries.size()); // Number of entries
-		writeLong(cDir, cdirSize); // Size of central dir
-		writeLong(cDir, offset); // Offset of central dir
-		if (comment != null) {
-			writeShort(cDir, comment.length());
-			cDir.write(comment.getBytes());
-		} else {
+        int cdirSize = cDir.size();
+        // Write Central Dir End
+        writeLong(cDir, ENDSIG);
+        writeShort(cDir, 0); // Disk Number
+        writeShort(cDir, 0); // Start Disk
+        writeShort(cDir, entries.size()); // Number of entries
+        writeShort(cDir, entries.size()); // Number of entries
+        writeLong(cDir, cdirSize); // Size of central dir
+        writeLong(cDir, offset); // Offset of central dir
+        if (comment != null) {
+            writeShort(cDir, comment.length());
+            cDir.write(comment.getBytes());
+        } else {
             writeShort(cDir, 0);
         }
-		// Write the central dir
-		out.write(cDir.toByteArray());
-		cDir = null;
-
-	}
-
-	/**
-	 * Writes entry information for ze to the underlying stream. Data associated
-	 * with the entry can then be written using write(). After data is written
-	 * closeEntry() must be called to complete the storing of ze on the
-	 * underlying stream.
-	 * 
-	 * @param ze
-	 *            ZipEntry to store
-	 * @exception IOException
-	 *                If an error occurs storing the entry
-	 * @see #write
-	 */
-	public void putNextEntry(ZipEntry ze) throws java.io.IOException {
+        // Write the central dir
+        out.write(cDir.toByteArray());
+        cDir = null;
+
+    }
+
+    /**
+     * Writes entry information for ze to the underlying stream. Data associated
+     * with the entry can then be written using write(). After data is written
+     * closeEntry() must be called to complete the storing of ze on the
+     * underlying stream.
+     * 
+     * @param ze
+     *            ZipEntry to store
+     * @exception IOException
+     *                If an error occurs storing the entry
+     * @see #write
+     */
+    public void putNextEntry(ZipEntry ze) throws java.io.IOException {
         if (currentEntry != null) {
             closeEntry();
         }
-		if (ze.getMethod() == STORED
-				|| (compressMethod == STORED && ze.getMethod() == -1)) {
-			if (ze.crc == -1) {
+        if (ze.getMethod() == STORED
+                || (compressMethod == STORED && ze.getMethod() == -1)) {
+            if (ze.crc == -1) {
                 /* [MSG "archive.20", "Crc mismatch"] */
                 throw new ZipException(Messages.getString("archive.20")); //$NON-NLS-1$
             }
-			if (ze.size == -1 && ze.compressedSize == -1) {
+            if (ze.size == -1 && ze.compressedSize == -1) {
                 /* [MSG "archive.21", "Size mismatch"] */
                 throw new ZipException(Messages.getString("archive.21")); //$NON-NLS-1$
             }
-			if (ze.size != ze.compressedSize && ze.compressedSize != -1
-					&& ze.size != -1) {
+            if (ze.size != ze.compressedSize && ze.compressedSize != -1
+                    && ze.size != -1) {
                 /* [MSG "archive.21", "Size mismatch"] */
                 throw new ZipException(Messages.getString("archive.21")); //$NON-NLS-1$
             }
-		}
+        }
         /* [MSG "archive.1E", "Stream is closed"] */
-		if (cDir == null) {
+        if (cDir == null) {
             throw new IOException(Messages.getString("archive.1E")); //$NON-NLS-1$
         }
-		if (entries.contains(ze.name)) {
+        if (entries.contains(ze.name)) {
             /* [MSG "archive.29", "Entry already exists: {0}"] */
             throw new ZipException(Messages.getString("archive.29", ze.name)); //$NON-NLS-1$
         }
-		nameLength = utf8Count(ze.name);
-		if (nameLength > 0xffff) {
+        nameLength = utf8Count(ze.name);
+        if (nameLength > 0xffff) {
             /* [MSG "archive.2A", "Name too long: {0}"] */
-            throw new IllegalArgumentException(Messages.getString("archive.2A", ze.name));
//$NON-NLS-1$
+            throw new IllegalArgumentException(Messages.getString(
+                    "archive.2A", ze.name)); //$NON-NLS-1$
         }
 
-		def.setLevel(compressLevel);
-		currentEntry = ze;
-		entries.add(currentEntry.name);
-		if (currentEntry.getMethod() == -1) {
+        def.setLevel(compressLevel);
+        currentEntry = ze;
+        entries.add(currentEntry.name);
+        if (currentEntry.getMethod() == -1) {
             currentEntry.setMethod(compressMethod);
         }
-		writeLong(out, LOCSIG); // Entry header
-		writeShort(out, ZIPLocalHeaderVersionNeeded); // Extraction version
-		writeShort(out, currentEntry.getMethod() == STORED ? 0
-				: ZIPDataDescriptorFlag);
-		writeShort(out, currentEntry.getMethod());
-		if (currentEntry.getTime() == -1) {
+        writeLong(out, LOCSIG); // Entry header
+        writeShort(out, ZIPLocalHeaderVersionNeeded); // Extraction version
+        writeShort(out, currentEntry.getMethod() == STORED ? 0
+                : ZIPDataDescriptorFlag);
+        writeShort(out, currentEntry.getMethod());
+        if (currentEntry.getTime() == -1) {
             currentEntry.setTime(System.currentTimeMillis());
         }
-		writeShort(out, currentEntry.time);
-		writeShort(out, currentEntry.modDate);
+        writeShort(out, currentEntry.time);
+        writeShort(out, currentEntry.modDate);
 
-		if (currentEntry.getMethod() == STORED) {
-			if (currentEntry.size == -1) {
+        if (currentEntry.getMethod() == STORED) {
+            if (currentEntry.size == -1) {
                 currentEntry.size = currentEntry.compressedSize;
             } else if (currentEntry.compressedSize == -1) {
                 currentEntry.compressedSize = currentEntry.size;
             }
-			writeLong(out, currentEntry.crc);
-			writeLong(out, currentEntry.size);
-			writeLong(out, currentEntry.size);
-		} else {
-			writeLong(out, 0);
-			writeLong(out, 0);
-			writeLong(out, 0);
-		}
-		writeShort(out, nameLength);
-		if (currentEntry.extra != null) {
+            writeLong(out, currentEntry.crc);
+            writeLong(out, currentEntry.size);
+            writeLong(out, currentEntry.size);
+        } else {
+            writeLong(out, 0);
+            writeLong(out, 0);
+            writeLong(out, 0);
+        }
+        writeShort(out, nameLength);
+        if (currentEntry.extra != null) {
             writeShort(out, currentEntry.extra.length);
         } else {
             writeShort(out, 0);
         }
-		nameBytes = toUTF8Bytes(currentEntry.name, nameLength);
-		out.write(nameBytes);
-		if (currentEntry.extra != null) {
+        nameBytes = toUTF8Bytes(currentEntry.name, nameLength);
+        out.write(nameBytes);
+        if (currentEntry.extra != null) {
             out.write(currentEntry.extra);
         }
-	}
+    }
 
-	/**
-	 * Sets the ZipFile comment associated with the file being written.
-	 * 
-	 */
-	public void setComment(String comment) {
-		if (comment.length() > 0xFFFF) {
+    /**
+     * Sets the ZipFile comment associated with the file being written.
+     * 
+     */
+    public void setComment(String comment) {
+        if (comment.length() > 0xFFFF) {
             throw new IllegalArgumentException(Messages.getString("archive.2B")); //$NON-NLS-1$
         }
-		this.comment = comment;
-	}
+        this.comment = comment;
+    }
 
-	/**
-	 * 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.
-	 * 
-	 */
-	public void setLevel(int level) {
-		if (level < Deflater.DEFAULT_COMPRESSION
-				|| level > Deflater.BEST_COMPRESSION) {
+    /**
+     * 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.
+     * 
+     */
+    public void setLevel(int level) {
+        if (level < Deflater.DEFAULT_COMPRESSION
+                || level > Deflater.BEST_COMPRESSION) {
             throw new IllegalArgumentException();
         }
-		compressLevel = level;
-	}
+        compressLevel = level;
+    }
 
-	/**
-	 * Sets the compression method to be used when compressing entry data.
-	 * method must be one of STORED or DEFLATED.
-	 * 
-	 * @param method
-	 *            Compression method to use
-	 */
-	public void setMethod(int method) {
-		if (method != STORED && method != DEFLATED) {
+    /**
+     * Sets the compression method to be used when compressing entry data.
+     * method must be one of STORED or DEFLATED.
+     * 
+     * @param method
+     *            Compression method to use
+     */
+    public void setMethod(int method) {
+        if (method != STORED && method != DEFLATED) {
             throw new IllegalArgumentException();
         }
-		compressMethod = method;
+        compressMethod = method;
 
-	}
+    }
 
-	private long writeLong(OutputStream os, long i) throws java.io.IOException {
-		// Write out the long value as an unsigned int
-		os.write((int) (i & 0xFF));
-		os.write((int) (i >> 8) & 0xFF);
-		os.write((int) (i >> 16) & 0xFF);
-		os.write((int) (i >> 24) & 0xFF);
-		return i;
-	}
-
-	private int writeShort(OutputStream os, int i) throws java.io.IOException {
-		os.write(i & 0xFF);
-		os.write((i >> 8) & 0xFF);
-		return i;
-
-	}
-
-	/**
-	 * Writes data for the current entry to the underlying stream.
-	 * 
-	 * @exception IOException
-	 *                If an error occurs writing to the stream
-	 */
-	@Override
+    private long writeLong(OutputStream os, long i) throws java.io.IOException {
+        // Write out the long value as an unsigned int
+        os.write((int) (i & 0xFF));
+        os.write((int) (i >> 8) & 0xFF);
+        os.write((int) (i >> 16) & 0xFF);
+        os.write((int) (i >> 24) & 0xFF);
+        return i;
+    }
+
+    private int writeShort(OutputStream os, int i) throws java.io.IOException {
+        os.write(i & 0xFF);
+        os.write((i >> 8) & 0xFF);
+        return i;
+
+    }
+
+    /**
+     * Writes data for the current entry to the underlying stream.
+     * 
+     * @exception IOException
+     *                If an error occurs writing to the stream
+     */
+    @Override
     public void write(byte[] buffer, int off, int nbytes)
-			throws java.io.IOException {
-		// avoid int overflow, check null buf
-		if ((off < 0 || (nbytes < 0) || off > buffer.length)
-				|| (buffer.length - off < nbytes)) {
-			throw new IndexOutOfBoundsException();
-		}
+            throws java.io.IOException {
+        // avoid int overflow, check null buf
+        if ((off < 0 || (nbytes < 0) || off > buffer.length)
+                || (buffer.length - off < nbytes)) {
+            throw new IndexOutOfBoundsException();
+        }
 
-		if (currentEntry == null) {
+        if (currentEntry == null) {
             /* [MSG "archive.2C", "No active entry"] */
             throw new ZipException(Messages.getString("archive.2C")); //$NON-NLS-1$
         }
 
-		if (currentEntry.getMethod() == STORED) {
+        if (currentEntry.getMethod() == STORED) {
             out.write(buffer, off, nbytes);
         } else {
             super.write(buffer, off, nbytes);
         }
-		crc.update(buffer, off, nbytes);
-	}
+        crc.update(buffer, off, nbytes);
+    }
 
-	static int utf8Count(String value) {
-		int total = 0;
-		for (int i = value.length(); --i >= 0;) {
-			char ch = value.charAt(i);
-			if (ch < 0x80) {
+    static int utf8Count(String value) {
+        int total = 0;
+        for (int i = value.length(); --i >= 0;) {
+            char ch = value.charAt(i);
+            if (ch < 0x80) {
                 total++;
             } else if (ch < 0x800) {
                 total += 2;
             } else {
                 total += 3;
             }
-		}
-		return total;
-	}
-
-	static byte[] toUTF8Bytes(String value, int length) {
-		byte[] result = new byte[length];
-		int pos = result.length;
-		for (int i = value.length(); --i >= 0;) {
-			char ch = value.charAt(i);
-			if (ch < 0x80) {
+        }
+        return total;
+    }
+
+    static byte[] toUTF8Bytes(String value, int length) {
+        byte[] result = new byte[length];
+        int pos = result.length;
+        for (int i = value.length(); --i >= 0;) {
+            char ch = value.charAt(i);
+            if (ch < 0x80) {
                 result[--pos] = (byte) ch;
             } else if (ch < 0x800) {
-				result[--pos] = (byte) (0x80 | (ch & 0x3f));
-				result[--pos] = (byte) (0xc0 | (ch >> 6));
-			} else {
-				result[--pos] = (byte) (0x80 | (ch & 0x3f));
-				result[--pos] = (byte) (0x80 | ((ch >> 6) & 0x3f));
-				result[--pos] = (byte) (0xe0 | (ch >> 12));
-			}
-		}
-		return result;
-	}
+                result[--pos] = (byte) (0x80 | (ch & 0x3f));
+                result[--pos] = (byte) (0xc0 | (ch >> 6));
+            } else {
+                result[--pos] = (byte) (0x80 | (ch & 0x3f));
+                result[--pos] = (byte) (0x80 | ((ch >> 6) & 0x3f));
+                result[--pos] = (byte) (0xe0 | (ch >> 12));
+            }
+        }
+        return result;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/nls/Messages.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/nls/Messages.java?view=diff&rev=556570&r1=556569&r2=556570
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/nls/Messages.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/internal/nls/Messages.java
Mon Jul 16 02:22:19 2007
@@ -23,7 +23,6 @@
 
 package org.apache.harmony.archive.internal.nls;
 
-
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.Locale;
@@ -138,13 +137,13 @@
             try {
                 format = bundle.getString(msg);
             } catch (MissingResourceException e) {
-                //ignore
+                // ignore
             }
         }
 
         return format(format, args);
     }
-    
+
     /**
      * Generates a formatted text string given a source string containing
      * "argument markers" of the form "{argNum}" where each argNum must be in
@@ -167,7 +166,7 @@
         String[] argStrings = new String[args.length];
         for (int i = 0; i < args.length; ++i) {
             if (args[i] == null)
-                argStrings[i] = "<null>";	//$NON-NLS-1$
+                argStrings[i] = "<null>"; //$NON-NLS-1$
             else
                 argStrings[i] = args[i].toString();
         }
@@ -191,16 +190,16 @@
                             10);
                     if (argnum < 0 || format.charAt(i + 2) != '}') {
                         // Bad format, just print and loop.
-						answer.append(format.substring(lastI, i + 1));
-						lastI = i + 1;
+                        answer.append(format.substring(lastI, i + 1));
+                        lastI = i + 1;
                     } else {
                         // Got a good one!
                         answer.append(format.substring(lastI, i));
                         if (argnum >= argStrings.length)
-                            answer.append("<missing argument>");	//$NON-NLS-1$
+                            answer.append("<missing argument>"); //$NON-NLS-1$
                         else
                             answer.append(argStrings[argnum]);
-						lastI = i + 3;
+                        lastI = i + 3;
                     }
                 }
             }
@@ -224,11 +223,12 @@
                     .doPrivileged(new PrivilegedAction<Object>() {
                         public Object run() {
                             return ResourceBundle.getBundle(resource, locale,
-                                    loader != null ? loader : ClassLoader.getSystemClassLoader());
+                                    loader != null ? loader : ClassLoader
+                                            .getSystemClassLoader());
                         }
                     });
         } catch (MissingResourceException e) {
-            //ignore
+            // ignore
         }
         return null;
     }

Modified: harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java?view=diff&rev=556570&r1=556569&r2=556570
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/archive/src/main/java/org/apache/harmony/archive/util/Util.java
Mon Jul 16 02:22:19 2007
@@ -65,19 +65,19 @@
         }
         return buffer.toString();
     }
-    
-    public static final boolean equalsIgnoreCase(String s1, String s2){
+
+    public static final boolean equalsIgnoreCase(String s1, String s2) {
         if (s1 == s2) {
             return true;
         }
-        
+
         if (s1 == null || s2 == null || s1.length() != s2.length()) {
             return false;
         }
 
         char c1, c2;
-        
-        for (int i=0; i< s1.length(); i++) {
+
+        for (int i = 0; i < s1.length(); i++) {
             if ((c1 = s1.charAt(i)) != (c2 = s2.charAt(i))
                     && toASCIIUpperCase(c1) != toASCIIUpperCase(c2)) {
                 return false;



Mime
View raw message