Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 28929 invoked from network); 27 Mar 2009 17:44:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Mar 2009 17:44:40 -0000 Received: (qmail 52843 invoked by uid 500); 27 Mar 2009 17:44:40 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 52741 invoked by uid 500); 27 Mar 2009 17:44:40 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 52715 invoked by uid 99); 27 Mar 2009 17:44:39 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2009 17:44:39 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Mar 2009 17:44:37 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AD1D52388A36; Fri, 27 Mar 2009 17:44:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r759283 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Date: Fri, 27 Mar 2009 17:44:16 -0000 To: commits@commons.apache.org From: sebb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090327174416.AD1D52388A36@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebb Date: Fri Mar 27 17:44:16 2009 New Revision: 759283 URL: http://svn.apache.org/viewvc?rev=759283&view=rev Log: Add alignmentBoundary and pad calculation methods to simplify the job for users. Update some Javadoc headerSize can only be an int. Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java?rev=759283&r1=759282&r2=759283&view=diff ============================================================================== --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java (original) +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java Fri Mar 27 17:44:16 2009 @@ -81,11 +81,16 @@ * FIFOs and directories * * All fields are unsigned short fields with 16-bit integer values + * apart from c_mtime and c_filesize which are 32-bit integer values * * + *

If necessary, the filename and file data are padded with a NUL byte to an even length

+ * *

Special files, directories, and the trailer are recorded with * the h_filesize field equal to 0.

* + *

In the ASCII version of this format, the 16-bit entries are represented as 6-byte octal numbers, + * and the 32-bit entries are represented as 11-byte octal numbers. No padding is added.

* *

NEW FORMAT

* @@ -140,12 +145,16 @@ private short fileFormat = 0; // Default chosen so checkNewFormat() and checkOldFormat() both fail /** The number of bytes in each header record; depends on the file format */ - private long headerSize = -1; + private int headerSize = -1; + + /** The boundary to which the header and data elements are aligned: 0, 2 or 4 bytes */ + private int alignmentBoundary; // Header fields private long chksum = 0; + /** Number of bytes in the file */ private long filesize = 0; private long gid = 0; @@ -227,8 +236,10 @@ /** * Get the checksum. + * Only supported for the new formats. * * @return Returns the checksum. + * @throws UnsupportedOperationException if the format is not a new format */ public long getChksum() { checkNewFormat(); @@ -265,6 +276,7 @@ * Get the minor device id * * @return Returns the minor device id. + * @throws UnsupportedOperationException if format is not a new format */ public long getDeviceMin() { checkNewFormat(); @@ -275,10 +287,6 @@ * Get the filesize. * * @return Returns the filesize. - */ - /* - * (non-Javadoc) - * * @see org.apache.commons.compress.archivers.ArchiveEntry#getSize() */ public long getSize() { @@ -304,15 +312,54 @@ } /** - * Get the size of this entry on the stream + * Get the header size for this CPIO format * - * @return Returns the size. + * @return Returns the header size in bytes. */ - public long getHeaderSize() { + public int getHeaderSize() { return this.headerSize; } /** + * Get the alignment boundary for this CPIO format + * + * @return Returns the aligment boundary (0, 2, 4) in bytes + */ + public int getAlignmentBoundary() { + return this.alignmentBoundary; + } + + /** + * Get the number of bytes needed to pad the header to the alignment boundary. + * + * @return the number of bytes needed to pad the header (0,1,2,3) + */ + public int getHeaderPadCount(){ + if (this.alignmentBoundary == 0) return 0; + int size = this.headerSize+this.name.length()+1; // Name has terminating null + int remain = size % this.alignmentBoundary; + if (remain > 0){ + return this.alignmentBoundary - remain; + } + return 0; + } + + /** + * Get the number of bytes needed to pad the data to the alignment boundary. + * + * @return the number of bytes needed to pad the data (0,1,2,3) + */ + public int getDataPadCount(){ + if (this.alignmentBoundary == 0) return 0; + long size = this.filesize; + int remain = (int) (size % this.alignmentBoundary); + if (remain > 0){ + return this.alignmentBoundary - remain; + } + return 0; + } + + /** * Set the inode. * * @return Returns the inode. @@ -556,15 +603,19 @@ switch (format) { case FORMAT_NEW: this.headerSize = 110; + this.alignmentBoundary = 4; break; case FORMAT_NEW_CRC: this.headerSize = 110; + this.alignmentBoundary = 4; break; case FORMAT_OLD_ASCII: this.headerSize = 76; + this.alignmentBoundary = 0; break; case FORMAT_OLD_BINARY: this.headerSize = 26; + this.alignmentBoundary = 2; break; default: throw new IllegalArgumentException("Unknown header type");