Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E09BA10807 for ; Wed, 1 Jan 2014 20:42:10 +0000 (UTC) Received: (qmail 32420 invoked by uid 500); 1 Jan 2014 20:42:10 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 32360 invoked by uid 500); 1 Jan 2014 20:42:10 -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 32353 invoked by uid 99); 1 Jan 2014 20:42:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Jan 2014 20:42:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Wed, 01 Jan 2014 20:42:08 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 07D2E238889B; Wed, 1 Jan 2014 20:41:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1554674 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStream.java Date: Wed, 01 Jan 2014 20:41:46 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140101204147.07D2E238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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(); }