hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject svn commit: r1050108 - in /hadoop/common/branches/branch-0.22: ./ src/contrib/ec2/ src/docs/ src/java/ src/java/org/apache/hadoop/io/ src/test/core/ src/test/core/org/apache/hadoop/io/
Date Thu, 16 Dec 2010 19:23:24 GMT
Author: omalley
Date: Thu Dec 16 19:23:23 2010
New Revision: 1050108

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

Modified:
    hadoop/common/branches/branch-0.22/   (props changed)
    hadoop/common/branches/branch-0.22/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/branch-0.22/src/contrib/ec2/   (props changed)
    hadoop/common/branches/branch-0.22/src/docs/   (props changed)
    hadoop/common/branches/branch-0.22/src/java/   (props changed)
    hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/BytesWritable.java
    hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/Text.java
    hadoop/common/branches/branch-0.22/src/test/core/   (props changed)
    hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestBytesWritable.java
    hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestSequenceFile.java
  (props changed)
    hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestText.java

Propchange: hadoop/common/branches/branch-0.22/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,2 +1,2 @@
-/hadoop/common/trunk:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.19/core:713112

Modified: hadoop/common/branches/branch-0.22/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/CHANGES.txt?rev=1050108&r1=1050107&r2=1050108&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.22/CHANGES.txt Thu Dec 16 19:23:23 2010
@@ -161,8 +161,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)
 
@@ -177,17 +177,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(..).

Propchange: hadoop/common/branches/branch-0.22/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,4 +1,4 @@
-/hadoop/common/trunk/CHANGES.txt:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk/CHANGES.txt:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Propchange: hadoop/common/branches/branch-0.22/src/contrib/ec2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/contrib/ec2:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk/src/contrib/ec2:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.19/core/src/contrib/ec2:713112
 /hadoop/core/trunk/src/contrib/ec2:776175-784663

Propchange: hadoop/common/branches/branch-0.22/src/docs/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,2 +1,2 @@
-/hadoop/common/trunk/src/docs:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk/src/docs:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.19/src/docs:713112

Propchange: hadoop/common/branches/branch-0.22/src/java/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/java:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk/src/java:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.19/core/src/java:713112
 /hadoop/core/trunk/src/core:776175-785643,785929-786278

Modified: hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/BytesWritable.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/BytesWritable.java?rev=1050108&r1=1050107&r2=1050108&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/BytesWritable.java (original)
+++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/BytesWritable.java Thu
Dec 16 19:23:23 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/branches/branch-0.22/src/java/org/apache/hadoop/io/Text.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/Text.java?rev=1050108&r1=1050107&r2=1050108&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/Text.java (original)
+++ hadoop/common/branches/branch-0.22/src/java/org/apache/hadoop/io/Text.java Thu Dec 16
19:23:23 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;

Propchange: hadoop/common/branches/branch-0.22/src/test/core/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/test/core:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk/src/test/core:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.19/core/src/test/core:713112
 /hadoop/core/trunk/src/test/core:776175-785643,785929-786278

Modified: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestBytesWritable.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestBytesWritable.java?rev=1050108&r1=1050107&r2=1050108&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestBytesWritable.java
(original)
+++ hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestBytesWritable.java
Thu Dec 16 19:23:23 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

Propchange: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestSequenceFile.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Dec 16 19:23:23 2010
@@ -1,3 +1,3 @@
-/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSequenceFile.java:1037901,1039952,1040408,1040849,1044490
+/hadoop/common/trunk/src/test/core/org/apache/hadoop/io/TestSequenceFile.java:1037901,1039952,1040408,1040849,1044490,1050070
 /hadoop/core/branches/branch-0.19/mapred/src/test/mapred/org/apache/hadoop/io/TestSequenceFile.java:713112
 /hadoop/core/trunk/src/test/mapred/org/apache/hadoop/io/TestSequenceFile.java:776175-785643

Modified: hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestText.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestText.java?rev=1050108&r1=1050107&r2=1050108&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestText.java (original)
+++ hadoop/common/branches/branch-0.22/src/test/core/org/apache/hadoop/io/TestText.java Thu
Dec 16 19:23:23 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