From 5e049f635b8b55f64217aa350e4958654330453f Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Thu, 6 Jan 2005 18:29:38 +0000 Subject: [PATCH] checkstyle git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277305 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/zip/ZipFile.java | 110 +++++++++--------- src/main/org/apache/tools/zip/ZipLong.java | 11 +- .../org/apache/tools/zip/ZipOutputStream.java | 65 ++++++++--- src/main/org/apache/tools/zip/ZipShort.java | 11 +- 4 files changed, 114 insertions(+), 83 deletions(-) diff --git a/src/main/org/apache/tools/zip/ZipFile.java b/src/main/org/apache/tools/zip/ZipFile.java index fe964d143..f6c434653 100644 --- a/src/main/org/apache/tools/zip/ZipFile.java +++ b/src/main/org/apache/tools/zip/ZipFile.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004 The Apache Software Foundation + * Copyright 2003-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -73,7 +73,7 @@ public class ZipFile { private static final class OffsetEntry { long headerOffset = -1; - long dataOffset = - 1; + long dataOffset = -1; } /** @@ -198,11 +198,13 @@ public class ZipFile { * Returns an InputStream for reading the contents of the given entry. * @param ze the entry to get the stream for. * @return a stream to read the entry from. + * @throws IOException if unable to create an input stream from the zipenty + * @throws ZipException if the zipentry has an unsupported compression method */ public InputStream getInputStream(ZipEntry ze) throws IOException, ZipException { - OffsetEntry offsetEntry = (OffsetEntry)entries.get(ze); - if (offsetEntry == null){ + OffsetEntry offsetEntry = (OffsetEntry) entries.get(ze); + if (offsetEntry == null) { return null; } long start = offsetEntry.dataOffset; @@ -221,22 +223,22 @@ public class ZipFile { } private static final int CFH_LEN = - /* version made by */ 2 + - /* version needed to extract */ 2 + - /* general purpose bit flag */ 2 + - /* compression method */ 2 + - /* last mod file time */ 2 + - /* last mod file date */ 2 + - /* crc-32 */ 4 + - /* compressed size */ 4 + - /* uncompressed size */ 4 + - /* filename length */ 2 + - /* extra field length */ 2 + - /* file comment length */ 2 + - /* disk number start */ 2 + - /* internal file attributes */ 2 + - /* external file attributes */ 4 + - /* relative offset of local header */ 4; + /* version made by */ 2 + /* version needed to extract */ + 2 + /* general purpose bit flag */ + 2 + /* compression method */ + 2 + /* last mod file time */ + 2 + /* last mod file date */ + 2 + /* crc-32 */ + 4 + /* compressed size */ + 4 + /* uncompressed size */ + 4 + /* filename length */ + 2 + /* extra field length */ + 2 + /* file comment length */ + 2 + /* disk number start */ + 2 + /* internal file attributes */ + 2 + /* external file attributes */ + 4 + /* relative offset of local header */ + 4; /** * Reads the central directory of the given archive and populates @@ -255,8 +257,8 @@ public class ZipFile { byte[] signatureBytes = new byte[4]; archive.readFully(signatureBytes); long sig = ZipLong.getValue(signatureBytes); - final long cfh_sig = ZipLong.getValue(ZipOutputStream.CFH_SIG); - while (sig == cfh_sig) { + final long cfhSig = ZipLong.getValue(ZipOutputStream.CFH_SIG); + while (sig == cfhSig) { archive.readFully(cfh); int off = 0; ZipEntry ze = new ZipEntry(); @@ -328,30 +330,30 @@ public class ZipFile { } private static final int MIN_EOCD_SIZE = - /* end of central dir signature */ 4 + - /* number of this disk */ 2 + - /* number of the disk with the */ + - /* start of the central directory */ 2 + - /* total number of entries in */ + - /* the central dir on this disk */ 2 + - /* total number of entries in */ + - /* the central dir */ 2 + - /* size of the central directory */ 4 + - /* offset of start of central */ + - /* directory with respect to */ + - /* the starting disk number */ 4 + - /* zipfile comment length */ 2; + /* end of central dir signature */ 4 + /* number of this disk */ + 2 + /* number of the disk with the */ + /* start of the central directory */ + 2 + /* total number of entries in */ + /* the central dir on this disk */ + 2 + /* total number of entries in */ + /* the central dir */ + 2 + /* size of the central directory */ + 4 + /* offset of start of central */ + /* directory with respect to */ + /* the starting disk number */ + 4 + /* zipfile comment length */ + 2; private static final int CFD_LOCATOR_OFFSET = - /* end of central dir signature */ 4 + - /* number of this disk */ 2 + - /* number of the disk with the */ + - /* start of the central directory */ 2 + - /* total number of entries in */ + - /* the central dir on this disk */ 2 + - /* total number of entries in */ + - /* the central dir */ 2 + - /* size of the central directory */ 4; + /* end of central dir signature */ 4 + /* number of this disk */ + 2 + /* number of the disk with the */ + /* start of the central directory */ + 2 + /* total number of entries in */ + /* the central dir on this disk */ + 2 + /* total number of entries in */ + /* the central dir */ + 2 + /* size of the central directory */ + 4; /** * Searches for the "End of central dir record", parses @@ -396,15 +398,15 @@ public class ZipFile { * filename" entry. */ private static final long LFH_OFFSET_FOR_FILENAME_LENGTH = - /* local file header signature */ 4 + - /* version needed to extract */ 2 + - /* general purpose bit flag */ 2 + - /* compression method */ 2 + - /* last mod file time */ 2 + - /* last mod file date */ 2 + - /* crc-32 */ 4 + - /* compressed size */ 4 + - /* uncompressed size */ 4; + /* local file header signature */ 4 + /* version needed to extract */ + 2 + /* general purpose bit flag */ + 2 + /* compression method */ + 2 + /* last mod file time */ + 2 + /* last mod file date */ + 2 + /* crc-32 */ + 4 + /* compressed size */ + 4 + /* uncompressed size */ + 4; /** * Walks through all recorded entries and adds the data available @@ -418,7 +420,7 @@ public class ZipFile { Enumeration e = getEntries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); - OffsetEntry offsetEntry = (OffsetEntry)entries.get(ze); + OffsetEntry offsetEntry = (OffsetEntry) entries.get(ze); long offset = offsetEntry.headerOffset; archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH); byte[] b = new byte[2]; diff --git a/src/main/org/apache/tools/zip/ZipLong.java b/src/main/org/apache/tools/zip/ZipLong.java index 6eb6cfede..b1f99c757 100644 --- a/src/main/org/apache/tools/zip/ZipLong.java +++ b/src/main/org/apache/tools/zip/ZipLong.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2002,2004 The Apache Software Foundation + * Copyright 2001-2002,2004-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -78,12 +78,12 @@ public final class ZipLong implements Cloneable { * @param value the value to convert * @return value as four bytes in big endian byte order */ - public static byte[] getBytes(long value){ + public static byte[] getBytes(long value) { byte[] result = new byte[4]; result[0] = (byte) ((value & 0xFF)); result[1] = (byte) ((value & 0xFF00) >> 8); result[2] = (byte) ((value & 0xFF0000) >> 16); - result[3] = (byte) ((value & 0xFF000000l) >> 24); + result[3] = (byte) ((value & 0xFF000000L) >> 24); return result; } @@ -93,7 +93,7 @@ public final class ZipLong implements Cloneable { * @param offset the offset to start * @return the correspondanding Java long value */ - public static long getValue(byte[] bytes, int offset){ + public static long getValue(byte[] bytes, int offset) { long value = (bytes[offset + 3] << 24) & 0xFF000000L; value += (bytes[offset + 2] << 16) & 0xFF0000; value += (bytes[offset + 1] << 8) & 0xFF00; @@ -106,13 +106,14 @@ public final class ZipLong implements Cloneable { * @param bytes the array of bytes * @return the correspondanding Java long value */ - public static long getValue(byte[] bytes){ + public static long getValue(byte[] bytes) { return getValue(bytes, 0); } /** * Override to make two instances with same value equal. * @param o an object to compare + * @return true if the objects are equal * @since 1.1 */ public boolean equals(Object o) { diff --git a/src/main/org/apache/tools/zip/ZipOutputStream.java b/src/main/org/apache/tools/zip/ZipOutputStream.java index 895eb2a2f..bb530dac7 100644 --- a/src/main/org/apache/tools/zip/ZipOutputStream.java +++ b/src/main/org/apache/tools/zip/ZipOutputStream.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2004 The Apache Software Foundation + * Copyright 2001-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.Hashtable; import java.util.Vector; -import java.util.Calendar; import java.util.zip.CRC32; import java.util.zip.Deflater; import java.util.zip.ZipException; @@ -220,7 +219,7 @@ public class ZipOutputStream extends FilterOutputStream { /** * Creates a new ZIP OutputStream filtering the underlying stream. - * + * @param out the outputstream to zip * @since 1.1 */ public ZipOutputStream(OutputStream out) { @@ -230,8 +229,9 @@ public class ZipOutputStream extends FilterOutputStream { /** * Creates a new ZIP OutputStream writing to a File. Will use * random access if possible. - * + * @param file the file to zip to * @since 1.14 + * @throws IOException on error */ public ZipOutputStream(File file) throws IOException { super(null); @@ -259,7 +259,7 @@ public class ZipOutputStream extends FilterOutputStream { *

For seekable streams, you don't need to calculate the CRC or * uncompressed size for {@link #STORED} entries before * invoking {@link #putNextEntry}. - * + * @return true if seekable * @since 1.17 */ public boolean isSeekable() { @@ -272,7 +272,7 @@ public class ZipOutputStream extends FilterOutputStream { *

For a list of possible values see http://java.sun.com/products/jdk/1.2/docs/guide/internat/encoding.doc.html. * Defaults to the platform's default character encoding.

- * + * @param encoding the encoding value * @since 1.3 */ public void setEncoding(String encoding) { @@ -295,6 +295,7 @@ public class ZipOutputStream extends FilterOutputStream { * underlying stream. * * @since 1.1 + * @throws IOException on error */ public void finish() throws IOException { closeEntry(); @@ -312,6 +313,7 @@ public class ZipOutputStream extends FilterOutputStream { * Writes all necessary data for this entry. * * @since 1.1 + * @throws IOException on error */ public void closeEntry() throws IOException { if (entry == null) { @@ -376,8 +378,9 @@ public class ZipOutputStream extends FilterOutputStream { /** * Begin writing next entry. - * + * @param ze the entry to write * @since 1.1 + * @throws IOException on error */ public void putNextEntry(ZipEntry ze) throws IOException { closeEntry(); @@ -416,7 +419,7 @@ public class ZipOutputStream extends FilterOutputStream { /** * Set the file comment. - * + * @param comment the comment * @since 1.1 */ public void setComment(String comment) { @@ -427,7 +430,7 @@ public class ZipOutputStream extends FilterOutputStream { * Sets the compression level for subsequent entries. * *

Default is Deflater.DEFAULT_COMPRESSION.

- * + * @param level the compression level * @since 1.1 */ public void setLevel(int level) { @@ -439,7 +442,7 @@ public class ZipOutputStream extends FilterOutputStream { * Sets the default compression method for subsequent entries. * *

Default is DEFLATED.

- * + * @param method an int from java.util.zip.ZipEntry * @since 1.1 */ public void setMethod(int method) { @@ -448,6 +451,10 @@ public class ZipOutputStream extends FilterOutputStream { /** * Writes bytes to ZIP entry. + * @param b the byte array to write + * @param offset the start position to write from + * @param length the number of bytes to write + * @throws IOException on error */ public void write(byte[] b, int offset, int length) throws IOException { if (entry.getMethod() == DEFLATED) { @@ -470,8 +477,9 @@ public class ZipOutputStream extends FilterOutputStream { * Writes a single byte to ZIP entry. * *

Delegates to the three arg method.

- * + * @param b the byte to write * @since 1.14 + * @throws IOException on error */ public void write(int b) throws IOException { byte[] buff = new byte[1]; @@ -540,6 +548,7 @@ public class ZipOutputStream extends FilterOutputStream { /** * Writes next block of compressed data to the output stream. + * @throws IOException on error * * @since 1.14 */ @@ -552,6 +561,8 @@ public class ZipOutputStream extends FilterOutputStream { /** * Writes the local file header entry + * @param ze the entry to write + * @throws IOException on error * * @since 1.1 */ @@ -563,7 +574,7 @@ public class ZipOutputStream extends FilterOutputStream { //store method in local variable to prevent multiple method calls final int zipMethod = ze.getMethod(); - + // version needed to extract // general purpose bit flag if (zipMethod == DEFLATED && raf == null) { @@ -624,7 +635,9 @@ public class ZipOutputStream extends FilterOutputStream { } /** - * Writes the data descriptor entry + * Writes the data descriptor entry. + * @param ze the entry to write + * @throws IOException on error * * @since 1.1 */ @@ -640,7 +653,9 @@ public class ZipOutputStream extends FilterOutputStream { } /** - * Writes the central file header entry + * Writes the central file header entry. + * @param ze the entry to write + * @throws IOException on error * * @since 1.1 */ @@ -732,7 +747,8 @@ public class ZipOutputStream extends FilterOutputStream { } /** - * Writes the "End of central dir record" + * Writes the "End of central dir record". + * @throws IOException on error * * @since 1.1 */ @@ -767,7 +783,8 @@ public class ZipOutputStream extends FilterOutputStream { /** * Convert a Date object to a DOS date/time field. - * + * @param time the Date to convert + * @return the date as a ZipLong * @since 1.1 */ protected static ZipLong toDosTime(Date time) { @@ -778,7 +795,8 @@ public class ZipOutputStream extends FilterOutputStream { * Convert a Date object to a DOS date/time field. * *

Stolen from InfoZip's fileio.c

- * + * @param t number of milliseconds since the epoch + * @return the date as a byte array * @since 1.26 */ protected static byte[] toDosTime(long t) { @@ -800,6 +818,9 @@ public class ZipOutputStream extends FilterOutputStream { /** * Retrieve the bytes for the given String in the encoding set for * this Stream. + * @param name the string to get bytes from + * @return the bytes as a byte array + * @throws ZipException on error * * @since 1.3 */ @@ -816,7 +837,9 @@ public class ZipOutputStream extends FilterOutputStream { } /** - * Write bytes to output or random access file + * Write bytes to output or random access file. + * @param data the byte array to write + * @throws IOException on error * * @since 1.14 */ @@ -825,7 +848,11 @@ public class ZipOutputStream extends FilterOutputStream { } /** - * Write bytes to output or random access file + * Write bytes to output or random access file. + * @param data the byte array to write + * @param offset the start position to write from + * @param length the number of bytes to write + * @throws IOException on error * * @since 1.14 */ diff --git a/src/main/org/apache/tools/zip/ZipShort.java b/src/main/org/apache/tools/zip/ZipShort.java index fee9181ff..c289ddd4e 100644 --- a/src/main/org/apache/tools/zip/ZipShort.java +++ b/src/main/org/apache/tools/zip/ZipShort.java @@ -1,5 +1,5 @@ /* - * Copyright 2001-2002,2004 The Apache Software Foundation + * Copyright 2001-2002,2004-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ public final class ZipShort implements Cloneable { * @param value the Java int to convert to bytes * @return the converted int as a byte array in big endian byte order */ - public static byte[] getBytes(int value){ + public static byte[] getBytes(int value) { byte[] result = new byte[2]; result[0] = (byte) (value & 0xFF); result[1] = (byte) ((value & 0xFF00) >> 8); @@ -94,7 +94,7 @@ public final class ZipShort implements Cloneable { * @param offset the offset to start * @return the correspondanding java int value */ - public static int getValue(byte[] bytes, int offset){ + public static int getValue(byte[] bytes, int offset) { int value = (bytes[offset + 1] << 8) & 0xFF00; value += (bytes[offset] & 0xFF); return value; @@ -105,13 +105,14 @@ public final class ZipShort implements Cloneable { * @param bytes the array of bytes * @return the correspondanding java int value */ - public static int getValue(byte[] bytes){ - return getValue(bytes, 0); + public static int getValue(byte[] bytes) { + return getValue(bytes, 0); } /** * Override to make two instances with same value equal. * @param o an object to compare + * @return true if the objects are equal * @since 1.1 */ public boolean equals(Object o) {