Browse Source

Make checkstyle a little happier.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274784 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
94ef2fbb4b
1 changed files with 45 additions and 17 deletions
  1. +45
    -17
      src/main/org/apache/tools/zip/ZipFile.java

+ 45
- 17
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -86,8 +86,6 @@ import java.util.zip.ZipException;
* <code>java.util.zip.ZipFile</code>, with a couple of exceptions: * <code>java.util.zip.ZipFile</code>, with a couple of exceptions:
* *
* <ul> * <ul>
* <li>The String-arg constructor declares to throw ZipException
* as well.</li>
* <li>There is no getName method.</li> * <li>There is no getName method.</li>
* <li>entries has been renamed to getEntries.</li> * <li>entries has been renamed to getEntries.</li>
* <li>getEntries and getEntry return * <li>getEntries and getEntry return
@@ -133,34 +131,50 @@ public class ZipFile {
/** /**
* Opens the given file for reading, assuming the platform's * Opens the given file for reading, assuming the platform's
* native encoding for file names. * native encoding for file names.
*
* @param f the archive.
*
* @throws IOException if an error occurs while reading the file.
*/ */
public ZipFile(File f) throws IOException, ZipException {
public ZipFile(File f) throws IOException {
this(f, null); this(f, null);
} }


/** /**
* Opens the given file for reading, assuming the platform's * Opens the given file for reading, assuming the platform's
* native encoding for file names. * native encoding for file names.
*
* @param name name of the archive.
*
* @throws IOException if an error occurs while reading the file.
*/ */
public ZipFile(String name) throws IOException, ZipException {
public ZipFile(String name) throws IOException {
this(new File(name), null); this(new File(name), null);
} }


/** /**
* Opens the given file for reading, assuming the specified * Opens the given file for reading, assuming the specified
* encoding for file names. * encoding for file names.
*
* @param name name of the archive.
* @param encoding the encoding to use for file names
*
* @throws IOException if an error occurs while reading the file.
*/ */
public ZipFile(String name, String encoding)
throws IOException, ZipException {
public ZipFile(String name, String encoding) throws IOException {
this(new File(name), encoding); this(new File(name), encoding);
} }


/** /**
* Opens the given file for reading, assuming the specified * Opens the given file for reading, assuming the specified
* encoding for file names. * encoding for file names.
*
* @param f the archive.
* @param encoding the encoding to use for file names
*
* @throws IOException if an error occurs while reading the file.
*/ */
public ZipFile(File f, String encoding)
throws IOException, ZipException {
public ZipFile(File f, String encoding) throws IOException {
this.encoding = encoding; this.encoding = encoding;
archive = new RandomAccessFile(f, "r"); archive = new RandomAccessFile(f, "r");
populateFromCentralDirectory(); populateFromCentralDirectory();
@@ -178,6 +192,7 @@ public class ZipFile {


/** /**
* Closes the archive. * Closes the archive.
* @throws IOException if an error occurs closing the archive.
*/ */
public void close() throws IOException { public void close() throws IOException {
archive.close(); archive.close();
@@ -186,6 +201,7 @@ public class ZipFile {
/** /**
* Returns all entries as {@link org.apache.tools.ant.ZipEntry * Returns all entries as {@link org.apache.tools.ant.ZipEntry
* ZipEntry} instances. * ZipEntry} instances.
* @return all entries as ZipEntry instances.
*/ */
public Enumeration getEntries() { public Enumeration getEntries() {
return entries.keys(); return entries.keys();
@@ -194,6 +210,9 @@ public class ZipFile {
/** /**
* Returns a named entry - or <code>null</code> if no entry by * Returns a named entry - or <code>null</code> if no entry by
* that name exists. * that name exists.
* @param name name of the entry.
* @return the ZipEntry corresponding to the given name - or
* <code>null</code> if not present.
*/ */
public ZipEntry getEntry(String name) { public ZipEntry getEntry(String name) {
return (ZipEntry) nameMap.get(name); return (ZipEntry) nameMap.get(name);
@@ -201,6 +220,8 @@ public class ZipFile {


/** /**
* Returns an InputStream for reading the contents of the given entry. * Returns an InputStream for reading the contents of the given entry.
* @param the entry to get the stream for.
* @return a stream to read the entry from.
*/ */
public InputStream getInputStream(ZipEntry ze) public InputStream getInputStream(ZipEntry ze)
throws IOException, ZipException { throws IOException, ZipException {
@@ -242,14 +263,14 @@ public class ZipFile {


/** /**
* Reads the central directory of the given archive and populates * Reads the central directory of the given archive and populates
* the interal tables with ZipEntry instances.
* the internal tables with ZipEntry instances.
* *
* <p>The ZipEntrys will know all data that can be obtained from * <p>The ZipEntrys will know all data that can be obtained from
* the central directory alone, but not the data that requires the * the central directory alone, but not the data that requires the
* local file header or additional data to be read.</p>
* local file header or additional data to be read.</p>
*/ */
private void populateFromCentralDirectory() private void populateFromCentralDirectory()
throws IOException, ZipException {
throws IOException {
positionAtCentralDirectory(); positionAtCentralDirectory();


byte[] cfh = new byte[CFH_LEN]; byte[] cfh = new byte[CFH_LEN];
@@ -266,17 +287,17 @@ public class ZipFile {
off += 2; off += 2;
ze.setPlatform((versionMadeBy.getValue() >> 8) & 0x0F); ze.setPlatform((versionMadeBy.getValue() >> 8) & 0x0F);


off += 4;// skip version info and general purpose byte
off += 4; // skip version info and general purpose byte


ze.setMethod((new ZipShort(cfh, off)).getValue()); ze.setMethod((new ZipShort(cfh, off)).getValue());
off += 2; off += 2;
ze.setTime(fromDosTime(new ZipLong(cfh, off)).getTime()); ze.setTime(fromDosTime(new ZipLong(cfh, off)).getTime());
off += 4; off += 4;
ze.setCrc((new ZipLong(cfh, off)).getValue()); ze.setCrc((new ZipLong(cfh, off)).getValue());
off += 4; off += 4;
ze.setCompressedSize((new ZipLong(cfh, off)).getValue()); ze.setCompressedSize((new ZipLong(cfh, off)).getValue());
off += 4; off += 4;


@@ -352,7 +373,7 @@ public class ZipFile {
* record. * record.
*/ */
private void positionAtCentralDirectory() private void positionAtCentralDirectory()
throws IOException, ZipException {
throws IOException {
long off = archive.length() - MIN_EOCD_SIZE; long off = archive.length() - MIN_EOCD_SIZE;
archive.seek(off); archive.seek(off);
byte[] sig = ZipOutputStream.EOCD_SIG.getBytes(); byte[] sig = ZipOutputStream.EOCD_SIG.getBytes();
@@ -430,6 +451,9 @@ public class ZipFile {


/** /**
* Convert a DOS date/time field to a Date object. * Convert a DOS date/time field to a Date object.
*
* @param l contains the stored DOS time.
* @return a Date instance corresponding to the given time.
*/ */
protected static Date fromDosTime(ZipLong l) { protected static Date fromDosTime(ZipLong l) {
long dosTime = l.getValue(); long dosTime = l.getValue();
@@ -446,6 +470,10 @@ public class ZipFile {
/** /**
* Retrieve a String from the given bytes using the encoding set * Retrieve a String from the given bytes using the encoding set
* for this ZipFile. * for this ZipFile.
*
* @param bytes the byte array to transform
* @return String obtained by using the given encoding
* @throws ZipException if the encoding cannot be recognized.
*/ */
protected String getString(byte[] bytes) throws ZipException { protected String getString(byte[] bytes) throws ZipException {
if (encoding == null) { if (encoding == null) {
@@ -502,7 +530,7 @@ public class ZipFile {
if (len <= 0) { if (len <= 0) {
return 0; return 0;
} }
if (len > remaining) { if (len > remaining) {
len = (int) remaining; len = (int) remaining;
} }


Loading…
Cancel
Save