You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/30 19:32:28 UTC

svn commit: r760062 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers: cpio/CpioArchiveOutputStream.java jar/JarArchiveOutputStream.java tar/TarArchiveOutputStream.java zip/ZipArchiveOutputStream.java

Author: sebb
Date: Mon Mar 30 17:32:27 2009
New Revision: 760062

URL: http://svn.apache.org/viewvc?rev=760062&view=rev
Log:
Replace specific methods with generic ones
Remove code that is provided by the parent class

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java?rev=760062&r1=760061&r2=760062&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java Mon Mar 30 17:32:27 2009
@@ -132,13 +132,15 @@
      * the default header format will be used if no other format is specified in
      * the entry.
      * 
-     * @param e
+     * @param entry
      *            the CPIO cpioEntry to be written
      * @throws IOException
      *             if an I/O error has occurred or if a CPIO file error has
      *             occurred
+     * @throws ClassCastException if entry is not an instance of CpioArchiveEntry
      */
-    public void putNextEntry(final CpioArchiveEntry e) throws IOException {
+    public void putArchiveEntry(ArchiveEntry entry) throws IOException {
+        CpioArchiveEntry e = (CpioArchiveEntry) entry;
         ensureOpen();
         if (this.entry != null) {
             closeArchiveEntry(); // close previous entry
@@ -377,23 +379,4 @@
         out.write('\0');
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.commons.compress.archivers.ArchiveOutputStream#putArchiveEntry
-     * (org.apache.commons.compress.archivers.ArchiveEntry)
-     */
-    public void putArchiveEntry(ArchiveEntry entry) throws IOException {
-        this.putNextEntry((CpioArchiveEntry) entry);
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see java.io.OutputStream#write(int)
-     */
-    public void write(int b) throws IOException {
-        out.write(b);
-    }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java?rev=760062&r1=760061&r2=760062&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStream.java Mon Mar 30 17:32:27 2009
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.OutputStream;
 
+import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.zip.JarMarker;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
@@ -40,11 +41,12 @@
         super(out);
     }
 
-    public void putNextEntry(ZipArchiveEntry ze) throws IOException {
+    // @throws ClassCastException if entry is not an instance of ZipArchiveEntry
+    public void putArchiveEntry(ArchiveEntry ze) throws IOException {
         if (!jarMarkerAdded) {
-            ze.addAsFirstExtraField(JarMarker.getInstance());
+            ((ZipArchiveEntry)ze).addAsFirstExtraField(JarMarker.getInstance());
             jarMarkerAdded = true;
         }
-        super.putNextEntry(ze);
+        super.putArchiveEntry(ze);
     }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=760062&r1=760061&r2=760062&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java Mon Mar 30 17:32:27 2009
@@ -43,7 +43,6 @@
     private long      currSize;
     private String    currName;
     private long      currBytes;
-    private final byte[]    oneBuf;
     private final byte[]    recordBuf;
     private int       assemLen;
     private final byte[]    assemBuf;
@@ -85,7 +84,6 @@
         this.assemLen = 0;
         this.assemBuf = new byte[recordSize];
         this.recordBuf = new byte[recordSize];
-        this.oneBuf = new byte[1];
     }
 
     /**
@@ -159,14 +157,16 @@
      * header record and positions the output stream for writing
      * the contents of the entry. Once this method is called, the
      * stream is ready for calls to write() to write the entry's
-     * contents. Once the contents are written, closeEntry()
+     * contents. Once the contents are written, closeArchiveEntry()
      * <B>MUST</B> be called to ensure that all buffered data
      * is completely written to the output stream.
      *
-     * @param entry The TarEntry to be written to the archive.
+     * @param archiveEntry The TarEntry to be written to the archive.
      * @throws IOException on error
+     * @throws ClassCastException if archiveEntry is not an instance of TarArchiveEntry
      */
-    public void putNextEntry(TarArchiveEntry entry) throws IOException {
+    public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {
+        TarArchiveEntry entry = (TarArchiveEntry) archiveEntry;
         if (entry.getName().length() >= TarConstants.NAMELEN) {
 
             if (longFileMode == LONGFILE_GNU) {
@@ -176,10 +176,10 @@
                                                                     TarConstants.LF_GNUTYPE_LONGNAME);
 
                 longLinkEntry.setSize(entry.getName().length() + 1);
-                putNextEntry(longLinkEntry);
+                putArchiveEntry(longLinkEntry);
                 write(entry.getName().getBytes());
                 write(0);
-                closeEntry();
+                closeArchiveEntry();
             } else if (longFileMode != LONGFILE_TRUNCATE) {
                 throw new RuntimeException("file name '" + entry.getName()
                                            + "' is too long ( > "
@@ -210,7 +210,7 @@
      * next entry written.
      * @throws IOException on error
      */
-    public void closeEntry() throws IOException {
+    public void closeArchiveEntry() throws IOException {
         if (assemLen > 0) {
             for (int i = assemLen; i < assemBuf.length; ++i) {
                 assemBuf[i] = 0;
@@ -231,32 +231,6 @@
     }
 
     /**
-     * Writes a byte to the current tar archive entry.
-     *
-     * This method simply calls read( byte[], int, int ).
-     *
-     * @param b The byte written.
-     * @throws IOException on error
-     */
-    public void write(int b) throws IOException {
-        oneBuf[0] = (byte) b;
-
-        write(oneBuf, 0, 1);
-    }
-
-    /**
-     * Writes bytes to the current tar archive entry.
-     *
-     * This method simply calls write( byte[], int, int ).
-     *
-     * @param wBuf The buffer to write to the archive.
-     * @throws IOException on error
-     */
-    public void write(byte[] wBuf) throws IOException {
-        write(wBuf, 0, wBuf.length);
-    }
-
-    /**
      * Writes bytes to the current tar archive entry. This method
      * is aware of the current entry and will throw an exception if
      * you attempt to write bytes past the length specified for the
@@ -354,14 +328,6 @@
 
     // ArchiveOutputStream
 
-    public void closeArchiveEntry() throws IOException {
-        closeEntry();
-    }
-
-    public void putArchiveEntry(ArchiveEntry entry) throws IOException {
-        putNextEntry((TarArchiveEntry) entry);
-    }
-
     public String getDefaultFileExtension() {
         return "tar";
     }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=760062&r1=760061&r2=760062&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Mon Mar 30 17:32:27 2009
@@ -52,7 +52,7 @@
  * calculate them yourself.  Unfortunately this is not possible for
  * the {@link #STORED STORED} method, here setting the CRC and
  * uncompressed size information is required before {@link
- * #putNextEntry putNextEntry} can be called.</p>
+ * #putArchiveEntry(ArchiveEntry)} can be called.</p>
  * @NotThreadSafe
  */
 public class ZipArchiveOutputStream extends ArchiveOutputStream {
@@ -268,7 +268,7 @@
      *
      * <p>For seekable streams, you don't need to calculate the CRC or
      * uncompressed size for {@link #STORED} entries before
-     * invoking {@link #putNextEntry}.
+     * invoking {@link #putArchiveEntry(ArchiveEntry)}.
      * @return true if seekable
      */
     public boolean isSeekable() {
@@ -334,7 +334,7 @@
      * @throws IOException on error
      */
     public void finish() throws IOException {
-        closeEntry();
+        closeArchiveEntry();
         cdOffset = written;
         for (Iterator i = entries.iterator(); i.hasNext(); ) {
             writeCentralFileHeader((ZipArchiveEntry) i.next());
@@ -349,7 +349,7 @@
      * Writes all necessary data for this entry.
      * @throws IOException on error
      */
-    public void closeEntry() throws IOException {
+    public void closeArchiveEntry() throws IOException {
         if (entry == null) {
             return;
         }
@@ -410,15 +410,12 @@
         entry = null;
     }
 
-    /**
-     * Begin writing next entry.
-     * @param ze the entry to write
-     * @throws IOException on error
-     */
-    public void putNextEntry(ZipArchiveEntry ze) throws IOException {
-        closeEntry();
+    /** {@inheritDoc} */
+ // @throws ClassCastException if entry is not an instance of ZipArchiveEntry
+    public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {
+        closeArchiveEntry();
 
-        entry = ze;
+        entry = ((ZipArchiveEntry) archiveEntry);
         entries.add(entry);
 
         if (entry.getMethod() == -1) { // not specified
@@ -523,19 +520,6 @@
     }
 
     /**
-     * Writes a single byte to ZIP entry.
-     *
-     * <p>Delegates to the three arg method.</p>
-     * @param b the byte to write
-     * @throws IOException on error
-     */
-    public void write(int b) throws IOException {
-        byte[] buff = new byte[1];
-        buff[0] = (byte) (b & BYTE_MASK);
-        write(buff, 0, 1);
-    }
-
-    /**
      * Closes this output stream and releases any system resources
      * associated with the stream.
      *
@@ -564,22 +548,6 @@
         }
     }
 
-    public void putArchiveEntry(ArchiveEntry entry) throws IOException {
-        putNextEntry((ZipArchiveEntry) entry);
-    }
-
-    public void closeArchiveEntry() {
-        // do nothing
-    }
-
-    // used to be implemented via FilterOutputStream
-    /**
-     * Invokes the {@link #write(byte[],int,int)} three-arg version.
-     */
-    public void write(byte[] b) throws IOException {
-        write(b, 0, b.length);
-    }
-
     /*
      * Various ZIP constants
      */