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 E6BE56A0A for ; Thu, 30 Jun 2011 07:05:41 +0000 (UTC) Received: (qmail 54344 invoked by uid 500); 30 Jun 2011 07:05:41 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 54050 invoked by uid 500); 30 Jun 2011 07:05:27 -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 54035 invoked by uid 99); 30 Jun 2011 07:05:22 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jun 2011 07:05:22 +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; Thu, 30 Jun 2011 07:05:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AF2A6238890D; Thu, 30 Jun 2011 07:04:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1141415 - /hadoop/common/trunk/common/src/java/org/apache/hadoop/io/IOUtils.java Date: Thu, 30 Jun 2011 07:04:58 -0000 To: common-commits@hadoop.apache.org From: eli@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110630070458.AF2A6238890D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: eli Date: Thu Jun 30 07:04:58 2011 New Revision: 1141415 URL: http://svn.apache.org/viewvc?rev=1141415&view=rev Log: Minor update to HADOOP-7429. Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/io/IOUtils.java Modified: hadoop/common/trunk/common/src/java/org/apache/hadoop/io/IOUtils.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/common/src/java/org/apache/hadoop/io/IOUtils.java?rev=1141415&r1=1141414&r2=1141415&view=diff ============================================================================== --- hadoop/common/trunk/common/src/java/org/apache/hadoop/io/IOUtils.java (original) +++ hadoop/common/trunk/common/src/java/org/apache/hadoop/io/IOUtils.java Thu Jun 30 07:04:58 2011 @@ -115,24 +115,32 @@ public class IOUtils { * @param in InputStream to read from * @param out OutputStream to write to * @param count number of bytes to copy + * @param close whether to close the streams * @throws IOException if bytes can not be read or written */ - public static void copyBytes(InputStream in, OutputStream out, long count) - throws IOException { + public static void copyBytes(InputStream in, OutputStream out, long count, + boolean close) throws IOException { byte buf[] = new byte[4096]; long bytesRemaining = count; int bytesRead; - while (bytesRemaining > 0) { - int bytesToRead = (int) - (bytesRemaining < buf.length ? bytesRemaining : buf.length); + try { + while (bytesRemaining > 0) { + int bytesToRead = (int) + (bytesRemaining < buf.length ? bytesRemaining : buf.length); - bytesRead = in.read(buf, 0, bytesToRead); - if (bytesRead == -1) - break; + bytesRead = in.read(buf, 0, bytesToRead); + if (bytesRead == -1) + break; - out.write(buf, 0, bytesRead); - bytesRemaining -= bytesRead; + out.write(buf, 0, bytesRead); + bytesRemaining -= bytesRead; + } + } finally { + if (close) { + closeStream(out); + closeStream(in); + } } }