From common-commits-return-9574-apmail-hadoop-common-commits-archive=hadoop.apache.org@hadoop.apache.org Wed Sep 02 07:07:44 2009 Return-Path: Delivered-To: apmail-hadoop-common-commits-archive@www.apache.org Received: (qmail 60605 invoked from network); 2 Sep 2009 07:07:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Sep 2009 07:07:44 -0000 Received: (qmail 46351 invoked by uid 500); 2 Sep 2009 07:07:44 -0000 Delivered-To: apmail-hadoop-common-commits-archive@hadoop.apache.org Received: (qmail 46274 invoked by uid 500); 2 Sep 2009 07:07:43 -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 46265 invoked by uid 99); 2 Sep 2009 07:07:43 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Sep 2009 07:07:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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, 02 Sep 2009 07:07:42 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A92E923888AD; Wed, 2 Sep 2009 07:07:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r810384 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/io/WritableUtils.java Date: Wed, 02 Sep 2009 07:07:21 -0000 To: common-commits@hadoop.apache.org From: cdouglas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090902070721.A92E923888AD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cdouglas Date: Wed Sep 2 07:07:21 2009 New Revision: 810384 URL: http://svn.apache.org/viewvc?rev=810384&view=rev Log: HADOOP-6224. Add a method to WritableUtils supported a bounded read of an encoded String. Contributed by Jothi Padmanabhan Modified: hadoop/common/trunk/CHANGES.txt hadoop/common/trunk/src/java/org/apache/hadoop/io/WritableUtils.java Modified: hadoop/common/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=810384&r1=810383&r2=810384&view=diff ============================================================================== --- hadoop/common/trunk/CHANGES.txt (original) +++ hadoop/common/trunk/CHANGES.txt Wed Sep 2 07:07:21 2009 @@ -507,7 +507,10 @@ HADOOP-6184. Provide an API to dump Configuration in a JSON format. (V.V.Chaitanya Krishna via yhemanth) - + + HADOOP-6224. Add a method to WritableUtils performing a bounded read of an + encoded String. (Jothi Padmanabhan via cdouglas) + OPTIMIZATIONS HADOOP-5595. NameNode does not need to run a replicator to choose a Modified: hadoop/common/trunk/src/java/org/apache/hadoop/io/WritableUtils.java URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/io/WritableUtils.java?rev=810384&r1=810383&r2=810384&view=diff ============================================================================== --- hadoop/common/trunk/src/java/org/apache/hadoop/io/WritableUtils.java (original) +++ hadoop/common/trunk/src/java/org/apache/hadoop/io/WritableUtils.java Wed Sep 2 07:07:21 2009 @@ -415,4 +415,29 @@ } return out.getData(); } + + /** + * Read a string, but check it for sanity. The format consists of a vint + * followed by the given number of bytes. + * @param in the stream to read from + * @param maxLength the largest acceptable length of the encoded string + * @return the bytes as a string + * @throws IOException if reading from the DataInput fails + * @throws IllegalArgumentException if the encoded byte size for string + is negative or larger than maxSize. Only the vint is read. + */ + public static String readStringSafely(DataInput in, + int maxLength + ) throws IOException, + IllegalArgumentException { + int length = readVInt(in); + if (length < 0 || length > maxLength) { + throw new IllegalArgumentException("Encoded byte size for String was " + length + + ", which is outside of 0.." + + maxLength + " range."); + } + byte [] bytes = new byte[length]; + in.readFully(bytes, 0, length); + return Text.decode(bytes); + } }