You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2014/01/01 21:41:46 UTC
svn commit: r1554674 -
/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Author: bodewig
Date: Wed Jan 1 20:41:46 2014
New Revision: 1554674
URL: http://svn.apache.org/r1554674
Log:
even if those arrays are small, ensure they are read completely - also make draining more efficient.
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java?rev=1554674&r1=1554673&r2=1554674&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java Wed Jan 1 20:41:46 2014
@@ -25,6 +25,7 @@ import java.io.InputStream;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.utils.ArchiveUtils;
+import org.apache.commons.compress.utils.IOUtils;
/**
* Implements the "ar" archive format as an input stream.
@@ -81,21 +82,14 @@ public class ArArchiveInputStream extend
public ArArchiveEntry getNextArEntry() throws IOException {
if (currentEntry != null) {
final long entryEnd = entryOffset + currentEntry.getLength();
- while (offset < entryEnd) {
- int x = read();
- if (x == -1) {
- // hit EOF before previous entry was complete
- // TODO: throw an exception instead?
- return null;
- }
- }
+ IOUtils.skip(this, entryEnd - offset);
currentEntry = null;
}
if (offset == 0) {
final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.HEADER);
final byte[] realized = new byte[expected.length];
- final int read = read(realized);
+ final int read = IOUtils.readFully(this, realized);
if (read != expected.length) {
throw new IOException("failed to read header. Occured at byte: " + getBytesRead());
}
@@ -115,18 +109,18 @@ public class ArArchiveInputStream extend
return null;
}
- read(NAME_BUF);
- read(LAST_MODIFIED_BUF);
- read(ID_BUF);
+ IOUtils.readFully(this, NAME_BUF);
+ IOUtils.readFully(this, LAST_MODIFIED_BUF);
+ IOUtils.readFully(this, ID_BUF);
int userId = asInt(ID_BUF, true);
- read(ID_BUF);
- read(FILE_MODE_BUF);
- read(LENGTH_BUF);
+ IOUtils.readFully(this, ID_BUF);
+ IOUtils.readFully(this, FILE_MODE_BUF);
+ IOUtils.readFully(this, LENGTH_BUF);
{
final byte[] expected = ArchiveUtils.toAsciiBytes(ArArchiveEntry.TRAILER);
final byte[] realized = new byte[expected.length];
- final int read = read(realized);
+ final int read = IOUtils.readFully(this, realized);
if (read != expected.length) {
throw new IOException("failed to read entry trailer. Occured at byte: " + getBytesRead());
}
@@ -351,14 +345,8 @@ public class ArArchiveInputStream extend
int nameLen =
Integer.parseInt(bsdLongName.substring(BSD_LONGNAME_PREFIX_LEN));
byte[] name = new byte[nameLen];
- int read = 0, readNow = 0;
- while ((readNow = input.read(name, read, nameLen - read)) >= 0) {
- read += readNow;
- count(readNow);
- if (read == nameLen) {
- break;
- }
- }
+ int read = IOUtils.readFully(input, name);
+ count(read);
if (read != nameLen) {
throw new EOFException();
}