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/27 02:41:28 UTC
svn commit: r758956 - in
/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio:
CpioArchiveInputStream.java CpioArchiveOutputStream.java
Author: sebb
Date: Fri Mar 27 01:41:27 2009
New Revision: 758956
URL: http://svn.apache.org/viewvc?rev=758956&view=rev
Log:
Add some TODOs and implementation notes
Rename pad => skip as that is what it does.
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveOutputStream.java
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=758956&r1=758955&r2=758956&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java Fri Mar 27 01:41:27 2009
@@ -200,10 +200,11 @@
return this.entry;
}
- private long pad(final long count, final int border) throws IOException {
+ private long skip(final long count, final int border) throws IOException {
long skip = count % border;
if (skip > 0) {
skip = this.in.skip(border - skip);
+ // TODO - what if not enough bytes are skipped?
}
return skip;
}
@@ -250,12 +251,13 @@
if (this.entry == null || this.entryEOF) {
return -1;
}
+ // N.B. These checks assume format is not 0 - otherwise condition is always true
if (this.entryBytesRead == this.entry.getSize()) {
if ((this.entry.getFormat() | FORMAT_NEW_MASK) == FORMAT_NEW_MASK) {
- pad(this.entry.getSize(), 4);
+ skip(this.entry.getSize(), 4);
} else if ((this.entry.getFormat() | FORMAT_OLD_BINARY) == FORMAT_OLD_BINARY) {
- pad(this.entry.getSize(), 2);
- }
+ skip(this.entry.getSize(), 2);
+ } // No need to skip for FORMAT_OLD_ASCII
this.entryEOF = true;
if ((this.entry.getFormat() | FORMAT_NEW_CRC) == FORMAT_NEW_CRC) {
if (this.crc != this.entry.getChksum()) {
@@ -271,6 +273,7 @@
}
int tmpread = this.in.read(b, off, tmplength);
+ // TODO - what about EOF or short reads?
if ((this.entry.getFormat() | FORMAT_NEW_CRC) == FORMAT_NEW_CRC) {
for (int pos = 0; pos < tmpread; pos++) {
this.crc += b[pos] & 0xFF;
@@ -342,7 +345,7 @@
// TODO - change this to throw
new IOException("Mode 0 only allowed in the trailer. Found: "+name).printStackTrace();
}
- pad(ret.getHeaderSize() + namesize, 4);
+ skip(ret.getHeaderSize() + namesize, 4);
return ret;
}
@@ -380,7 +383,7 @@
long namesize = readBinaryLong(2, swapHalfWord);
ret.setSize(readBinaryLong(4, swapHalfWord));
ret.setName(readCString((int) namesize));
- pad(ret.getHeaderSize() + namesize, 2);
+ skip(ret.getHeaderSize() + namesize, 2);
return ret;
}
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=758956&r1=758955&r2=758956&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 Fri Mar 27 01:41:27 2009
@@ -248,11 +248,12 @@
+ this.cpioEntry.getSize() + " but got " + this.written
+ " bytes)");
}
+ // N.B. These checks assume format is not 0
if ((this.cpioEntry.getFormat() | FORMAT_NEW_MASK) == FORMAT_NEW_MASK) {
pad(this.cpioEntry.getSize(), 4);
} else if ((this.cpioEntry.getFormat() | FORMAT_OLD_BINARY) == FORMAT_OLD_BINARY) {
pad(this.cpioEntry.getSize(), 2);
- }
+ } // No need to pad for FORMAT_OLD_ASCII
if ((this.cpioEntry.getFormat() | FORMAT_NEW_CRC) == FORMAT_NEW_CRC) {
if (this.crc != this.cpioEntry.getChksum()) {
throw new IOException("CRC Error");
@@ -294,6 +295,7 @@
}
out.write(b, off, len);
this.written += len;
+ // format is assumed non-zero here, otherwise the condition is always true
if ((this.cpioEntry.getFormat() | FORMAT_NEW_CRC) == FORMAT_NEW_CRC) {
for (int pos = 0; pos < len; pos++) {
this.crc += b[pos] & 0xFF;
@@ -342,9 +344,9 @@
}
private void pad(final long count, final int border) throws IOException {
- long skip = count % border;
- if (skip > 0) {
- byte tmp[] = new byte[(int) (border - skip)];
+ long pad = count % border;
+ if (pad > 0) {
+ byte tmp[] = new byte[(int) (border - pad)];
out.write(tmp);
}
}