hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1050070 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/io/BytesWritable.java src/java/org/apache/hadoop/io/Text.java src/test/core/org/apache/hadoop/io/TestBytesWritable.java src/test/core/org/apache/hadoop/io/TestText.java
Date Thu, 16 Dec 2010 17:43:47 GMT
Author: omalley
Date: Thu Dec 16 17:43:47 2010
New Revision: 1050070

URL: http://svn.apache.org/viewvc?rev=1050070&view=rev
Log:
HADOOP-6298. Add copyBytes to Text and BytesWritable. (omalley)

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/io/BytesWritable.java
    hadoop/common/trunk/src/java/org/apache/hadoop/io/Text.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestBytesWritable.java
    hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestText.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=1050070&r1=1050069&r2=1050070&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Thu Dec 16 17:43:47 2010
@@ -211,8 +211,8 @@ Release 0.22.0 - Unreleased
     HADOOP-7009. MD5Hash provides a public factory method that creates an
     instance of thread local MessageDigest. (hairong)
 
-    HADOOP-7008. Enable test-patch.sh to have a configured number of acceptable 
-    findbugs and javadoc warnings. (nigel and gkesavan)
+    HADOOP-7008. Enable test-patch.sh to have a configured number of 
+    acceptable findbugs and javadoc warnings. (nigel and gkesavan)
 
     HADOOP-6818. Provides a JNI implementation of group resolution. (ddas)
 
@@ -227,17 +227,22 @@ Release 0.22.0 - Unreleased
     HADOOP-7024. Create a test method for adding file systems during tests.
     (Kan Zhang via jghoman)
 
-    HADOOP-6903. Make AbstractFSileSystem methods and some FileContext methods to be public.
(Sanjay Radia via Sanjay Radia)
+    HADOOP-6903. Make AbstractFSileSystem methods and some FileContext methods
+    to be public. (Sanjay Radia)
 
-    HADOOP-7034. Add TestPath tests to cover dot, dot dot, and slash normalization. (eli)
+    HADOOP-7034. Add TestPath tests to cover dot, dot dot, and slash 
+    normalization. (eli)
 
     HADOOP-7032. Assert type constraints in the FileStatus constructor. (eli)
 
-    HADOOP-6562. FileContextSymlinkBaseTest should use FileContextTestHelper. (eli)
+    HADOOP-6562. FileContextSymlinkBaseTest should use FileContextTestHelper. 
+    (eli)
 
     HADOOP-7028. ant eclipse does not include requisite ant.jar in the 
     classpath. (Patrick Angeles via eli)
 
+    HADOOP-6298. Add copyBytes to Text and BytesWritable. (omalley)
+
   OPTIMIZATIONS
 
     HADOOP-6884. Add LOG.isDebugEnabled() guard for each LOG.debug(..).

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/io/BytesWritable.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/io/BytesWritable.java?rev=1050070&r1=1050069&r2=1050070&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/io/BytesWritable.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/io/BytesWritable.java Thu Dec 16 17:43:47
2010
@@ -22,8 +22,6 @@ import java.io.IOException;
 import java.io.DataInput;
 import java.io.DataOutput;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
@@ -37,7 +35,6 @@ import org.apache.hadoop.classification.
 @InterfaceStability.Stable
 public class BytesWritable extends BinaryComparable
     implements WritableComparable<BinaryComparable> {
-  private static final Log LOG = LogFactory.getLog(BytesWritable.class);
   private static final int LENGTH_BYTES = 4;
   private static final byte[] EMPTY_BYTES = {};
 
@@ -59,7 +56,18 @@ public class BytesWritable extends Binar
   }
   
   /**
-   * Get the data from the BytesWritable.
+   * Get a copy of the bytes that is exactly the length of the data.
+   * See {@link #getBytes()} for faster access to the underlying array.
+   */
+  public byte[] copyBytes() {
+    byte[] result = new byte[size];
+    System.arraycopy(bytes, 0, result, 0, size);
+    return result;
+  }
+  
+  /**
+   * Get the data backing the BytesWritable. Please use {@link #copyBytes()}
+   * if you need the returned array to be precisely the length of the data.
    * @return The data is only valid between 0 and getLength() - 1.
    */
   public byte[] getBytes() {

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/io/Text.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/io/Text.java?rev=1050070&r1=1050069&r2=1050070&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/io/Text.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/io/Text.java Thu Dec 16 17:43:47 2010
@@ -35,8 +35,6 @@ import java.util.Arrays;
 
 import org.apache.avro.reflect.Stringable;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
 
@@ -54,7 +52,6 @@ import org.apache.hadoop.classification.
 @InterfaceStability.Stable
 public class Text extends BinaryComparable
     implements WritableComparable<BinaryComparable> {
-  private static final Log LOG= LogFactory.getLog(Text.class);
   
   private static ThreadLocal<CharsetEncoder> ENCODER_FACTORY =
     new ThreadLocal<CharsetEncoder>() {
@@ -101,8 +98,19 @@ public class Text extends BinaryComparab
   }
   
   /**
+   * Get a copy of the bytes that is exactly the length of the data.
+   * See {@link #getBytes()} for faster access to the underlying array.
+   */
+  public byte[] copyBytes() {
+    byte[] result = new byte[length];
+    System.arraycopy(bytes, 0, result, 0, length);
+    return result;
+  }
+  
+  /**
    * Returns the raw bytes; however, only data up to {@link #getLength()} is
-   * valid.
+   * valid. Please use {@link #copyBytes()} if you
+   * need the returned array to be precisely the length of the data.
    */
   public byte[] getBytes() {
     return bytes;

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestBytesWritable.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestBytesWritable.java?rev=1050070&r1=1050069&r2=1050070&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestBytesWritable.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestBytesWritable.java Thu Dec
16 17:43:47 2010
@@ -40,6 +40,8 @@ public class TestBytesWritable extends T
     for(int i=0; i < size*2; ++i) {
       assertEquals(hadoop[i%size], buf.getBytes()[i]);
     }
+    // ensure that copyBytes is exactly the right length
+    assertEquals(size*4, buf.copyBytes().length);
     // shrink the buffer
     buf.setCapacity(1);
     // make sure the size has been cut down too

Modified: hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestText.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestText.java?rev=1050070&r1=1050069&r2=1050070&view=diff
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestText.java (original)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestText.java Thu Dec 16 17:43:47
2010
@@ -215,6 +215,10 @@ public class TestText extends TestCase {
     a.append("xdefgxxx".getBytes(), 1, 4);
     assertEquals("modified aliased string", "abc", b.toString());
     assertEquals("appended string incorrectly", "abcdefg", a.toString());
+    // add an extra byte so that capacity = 14 and length = 8
+    a.append(new byte[]{'d'}, 0, 1);
+    assertEquals(14, a.getBytes().length);
+    assertEquals(8, a.copyBytes().length);
   }
   
   private class ConcurrentEncodeDecodeThread extends Thread {



Mime
View raw message