From hadoop-commits-return-915-apmail-lucene-hadoop-commits-archive=lucene.apache.org@lucene.apache.org Wed Jan 03 20:07:25 2007 Return-Path: Delivered-To: apmail-lucene-hadoop-commits-archive@locus.apache.org Received: (qmail 27030 invoked from network); 3 Jan 2007 20:07:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jan 2007 20:07:24 -0000 Received: (qmail 8296 invoked by uid 500); 3 Jan 2007 20:07:30 -0000 Delivered-To: apmail-lucene-hadoop-commits-archive@lucene.apache.org Received: (qmail 8278 invoked by uid 500); 3 Jan 2007 20:07:30 -0000 Mailing-List: contact hadoop-commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hadoop-dev@lucene.apache.org Delivered-To: mailing list hadoop-commits@lucene.apache.org Received: (qmail 8269 invoked by uid 99); 3 Jan 2007 20:07:30 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2007 12:07:30 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Jan 2007 12:07:23 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id C20901A981A; Wed, 3 Jan 2007 12:06:26 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r492276 - in /lucene/hadoop/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FsShell.java Date: Wed, 03 Jan 2007 20:06:26 -0000 To: hadoop-commits@lucene.apache.org From: cutting@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070103200626.C20901A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cutting Date: Wed Jan 3 12:06:25 2007 New Revision: 492276 URL: http://svn.apache.org/viewvc?view=rev&rev=492276 Log: HADOOP-628. Fix a problem with 'fs -cat' command. Contributed by Wendy. Modified: lucene/hadoop/trunk/CHANGES.txt lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Modified: lucene/hadoop/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=492276&r1=492275&r2=492276 ============================================================================== --- lucene/hadoop/trunk/CHANGES.txt (original) +++ lucene/hadoop/trunk/CHANGES.txt Wed Jan 3 12:06:25 2007 @@ -168,6 +168,9 @@ 47. HADOOP-525. Add raw comparators to record types. This greatly improves record sort performance. (Milind Bhandarkar via cutting) +48. HADOOP-628. Fix a problem with 'fs -cat' command, where some + characters were replaced with question marks. (Wendy Chien via cutting) + Release 0.9.2 - 2006-12-15 Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java?view=diff&rev=492276&r1=492275&r2=492276 ============================================================================== --- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original) +++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Wed Jan 3 12:06:25 2007 @@ -40,6 +40,22 @@ } /** + * Copies from one stream to another. + */ + private void copyBytes(InputStream in, OutputStream out) throws IOException { + PrintStream ps = out instanceof PrintStream ? (PrintStream)out : null; + byte buf[] = new byte[conf.getInt("io.file.buffer.size", 4096)]; + int bytesRead = in.read(buf); + while (bytesRead >= 0) { + out.write(buf, 0, bytesRead); + if ((ps != null) && ps.checkError()) { + throw new IOException("Unable to write to output stream."); + } + bytesRead = in.read(buf); + } + } + + /** * Copies from stdin to the indicated file. */ private void copyFromStdin(Path dst) throws IOException { @@ -50,18 +66,29 @@ throw new IOException("Target " + dst.toString() + " already exists."); } FSDataOutputStream out = fs.create(dst); - byte buf[] = new byte[conf.getInt("io.file.buffer.size", 4096)]; try { - int bytesRead = System.in.read(buf); - while (bytesRead >= 0) { - out.write(buf, 0, bytesRead); - bytesRead = System.in.read(buf); - } + copyBytes(System.in, out); } finally { out.close(); } } + /** + * Print from src to stdout. + */ + private void printToStdout(Path src) throws IOException { + if (fs.isDirectory(src)) { + throw new IOException("Source must be a file."); + } + FSDataInputStream in = fs.open(src); + try { + copyBytes(in, System.out); + } finally { + in.close(); + } + + } + /** * Add a local file to the indicated FileSystem name. src is kept. */ @@ -178,38 +205,10 @@ void cat(String srcf) throws IOException { Path [] srcs = fs.globPaths( new Path( srcf ) ); for( int i=0; i