Author: sebb Date: Mon Mar 30 17:17:58 2009 New Revision: 760053 URL: http://svn.apache.org/viewvc?rev=760053&view=rev Log: Initial Javadoc Implement common write(byte) method
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java?rev=760053&r1=760052&r2=760053&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveOutputStream.java Mon Mar 30 17:17:58 2009 @@ -21,9 +21,46 @@ import java.io.IOException; import java.io.OutputStream; +/** + * Archive output stream implementations are expected to override the + * {...@link #write(byte[], int, int)} method to improve performance. + * They should also override {...@link #close()} to ensure that any necessary + * trailers are added. + * <p> + * Example usage:<br/> + * TBA + */ public abstract class ArchiveOutputStream extends OutputStream { + + /** Temporary buffer used for the {...@link #write(int)} method */ + private final byte[] oneByte = new byte[1]; + static final int BYTE_MASK = 0xFF; public abstract void putArchiveEntry(ArchiveEntry entry) throws IOException; + /** + * Closes the archive entry, writing any trailer information that may + * be required. + * @throws IOException + */ public abstract void closeArchiveEntry() throws IOException; + + // Generic implementations of OutputStream methods that may be useful to sub-classes + + /** + * Writes a byte to the current archive entry. + * + * This method simply calls write( byte[], 0, 1 ). + * + * MUST be overridden if the {...@link #write(byte[], int, int)} method + * is not overridden; may be overridden otherwise. + * + * @param b The byte to be written. + * @throws IOException on error + */ + public void write(int b) throws IOException { + oneByte[0] = (byte) (b & BYTE_MASK); + write(oneByte, 0, 1); + } + }