Return-Path: X-Original-To: apmail-hadoop-common-commits-archive@www.apache.org Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6405AD79E for ; Tue, 21 Aug 2012 14:28:47 +0000 (UTC) Received: (qmail 84593 invoked by uid 500); 21 Aug 2012 14:28:47 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 84508 invoked by uid 500); 21 Aug 2012 14:28:46 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: common-dev@hadoop.apache.org Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 84499 invoked by uid 99); 21 Aug 2012 14:28:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Aug 2012 14:28:46 +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; Tue, 21 Aug 2012 14:28:43 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 5E96923889EC; Tue, 21 Aug 2012 14:27:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1375572 - in /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common: CHANGES.txt src/main/java/org/apache/hadoop/io/IOUtils.java src/test/java/org/apache/hadoop/io/TestIOUtils.java Date: Tue, 21 Aug 2012 14:27:59 -0000 To: common-commits@hadoop.apache.org From: bobby@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120821142759.5E96923889EC@eris.apache.org> Author: bobby Date: Tue Aug 21 14:27:58 2012 New Revision: 1375572 URL: http://svn.apache.org/viewvc?rev=1375572&view=rev Log: svn merge -c 1375216 FIXES: HADOOP-8614. IOUtils#skipFully hangs forever on EOF. Contributed by Colin Patrick McCabe Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1375572&r1=1375571&r2=1375572&view=diff ============================================================================== --- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt (original) +++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt Tue Aug 21 14:27:58 2012 @@ -182,6 +182,9 @@ Release 0.23.3 - UNRELEASED HADOOP-8611. Allow fall-back to the shell-based implementation when JNI-based users-group mapping fails (Robert Parker via bobby) + HADOOP-8614. IOUtils#skipFully hangs forever on EOF. + (Colin Patrick McCabe via eli) + Release 0.23.2 - UNRELEASED NEW FEATURES Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java?rev=1375572&r1=1375571&r2=1375572&view=diff ============================================================================== --- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java (original) +++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/IOUtils.java Tue Aug 21 14:27:58 2012 @@ -181,12 +181,20 @@ public class IOUtils { * for any reason (including EOF) */ public static void skipFully(InputStream in, long len) throws IOException { - while (len > 0) { - long ret = in.skip(len); - if (ret < 0) { - throw new IOException( "Premature EOF from inputStream"); + long amt = len; + while (amt > 0) { + long ret = in.skip(amt); + if (ret == 0) { + // skip may return 0 even if we're not at EOF. Luckily, we can + // use the read() method to figure out if we're at the end. + int b = in.read(); + if (b == -1) { + throw new EOFException( "Premature EOF from inputStream after " + + "skipping " + (len - amt) + " byte(s)."); + } + ret = 1; } - len -= ret; + amt -= ret; } } Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java?rev=1375572&r1=1375571&r2=1375572&view=diff ============================================================================== --- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java (original) +++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/io/TestIOUtils.java Tue Aug 21 14:27:58 2012 @@ -21,6 +21,8 @@ package org.apache.hadoop.io; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.ByteArrayInputStream; +import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -110,4 +112,41 @@ public class TestIOUtils { Mockito.verify(outputStream, Mockito.atLeastOnce()).close(); } + + @Test + public void testSkipFully() throws IOException { + byte inArray[] = new byte[] {0, 1, 2, 3, 4}; + ByteArrayInputStream in = new ByteArrayInputStream(inArray); + try { + in.mark(inArray.length); + IOUtils.skipFully(in, 2); + IOUtils.skipFully(in, 2); + try { + IOUtils.skipFully(in, 2); + fail("expected to get a PrematureEOFException"); + } catch (EOFException e) { + assertEquals(e.getMessage(), "Premature EOF from inputStream " + + "after skipping 1 byte(s)."); + } + in.reset(); + try { + IOUtils.skipFully(in, 20); + fail("expected to get a PrematureEOFException"); + } catch (EOFException e) { + assertEquals(e.getMessage(), "Premature EOF from inputStream " + + "after skipping 5 byte(s)."); + } + in.reset(); + IOUtils.skipFully(in, 5); + try { + IOUtils.skipFully(in, 10); + fail("expected to get a PrematureEOFException"); + } catch (EOFException e) { + assertEquals(e.getMessage(), "Premature EOF from inputStream " + + "after skipping 0 byte(s)."); + } + } finally { + in.close(); + } + } }