You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2006/07/31 21:54:13 UTC

svn commit: r427234 - /lucene/hadoop/trunk/src/java/org/apache/hadoop/io/Text.java

Author: cutting
Date: Mon Jul 31 12:54:12 2006
New Revision: 427234

URL: http://svn.apache.org/viewvc?rev=427234&view=rev
Log:
HADOOP-302.  Fix a bug in Text.toString().  Contributed by Hairong.

Modified:
    lucene/hadoop/trunk/src/java/org/apache/hadoop/io/Text.java

Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/io/Text.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/io/Text.java?rev=427234&r1=427233&r2=427234&view=diff
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/io/Text.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/io/Text.java Mon Jul 31 12:54:12 2006
@@ -208,7 +208,7 @@
    */
   public String toString() {
     try {
-      return decode(bytes);
+      return decode(bytes, 0, length);
     } catch (CharacterCodingException e) { 
       //bytes is supposed to contain valid utf8, therefore, 
       // this should never happen
@@ -308,6 +308,11 @@
     return decode(ByteBuffer.wrap(utf8), false);
   }
   
+  public static String decode(byte[] utf8, int start, int length) 
+      throws CharacterCodingException {
+      return decode(ByteBuffer.wrap(utf8, start, length), false);
+  }
+  
   /**
    * Converts the provided byte array to a String using the
    * UTF-8 encoding. If <code>replace</code> is true, then
@@ -315,9 +320,9 @@
    * substitution character, which is U+FFFD. Otherwise the
    * method throws a MalformedInputException.
    */
-  public static String decode(byte[] utf8, boolean replace) 
+  public static String decode(byte[] utf8, int start, int length, boolean replace) 
     throws CharacterCodingException {
-    return decode(ByteBuffer.wrap(utf8), replace);
+    return decode(ByteBuffer.wrap(utf8, start, length), replace);
   }
   
   private static String decode(ByteBuffer utf8, boolean replace)