Author: cutting
Date: Thu Feb  4 00:24:31 2010
New Revision: 906299

URL: http://svn.apache.org/viewvc?rev=906299&view=rev
Log:
AVRO-340.  Add a constructor for Utf8 that accepts byte[].  Contributed by Jeff 
Hodges.

Added:
    hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/util/
    hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/util/TestUtf8.java
Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/lang/java/src/java/org/apache/avro/util/Utf8.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=906299&r1=906298&r2=906299&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Thu Feb  4 00:24:31 2010
@@ -281,7 +281,11 @@
 
     AVRO-386. Python implementaiton of compression (philz)
 
-    AVRO-394. Simplify and consolidate all data structures into hash tables 
(massie)
+    AVRO-394. Simplify and consolidate all data structures into hash
+    tables (massie)
+
+    AVRO-340.  Add a constructor for Utf8 that accepts byte[].
+    (Jeff Hodges via cutting)
 
   OPTIMIZATIONS
 

Modified: hadoop/avro/trunk/lang/java/src/java/org/apache/avro/util/Utf8.java
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/java/org/apache/avro/util/Utf8.java?rev=906299&r1=906298&r2=906299&view=diff
==============================================================================
--- hadoop/avro/trunk/lang/java/src/java/org/apache/avro/util/Utf8.java 
(original)
+++ hadoop/avro/trunk/lang/java/src/java/org/apache/avro/util/Utf8.java Thu Feb 
 4 00:24:31 2010
@@ -39,6 +39,11 @@
     this.length = bytes.length;
   }
 
+  public Utf8(byte[] bytes) {
+    this.bytes = bytes;
+    this.length = bytes.length;
+  }
+
   public byte[] getBytes() { return bytes; }
   public int getLength() { return length; }
 

Added: 
hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/util/TestUtf8.java
URL: 
http://svn.apache.org/viewvc/hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/util/TestUtf8.java?rev=906299&view=auto
==============================================================================
--- 
hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/util/TestUtf8.java 
(added)
+++ 
hadoop/avro/trunk/lang/java/src/test/java/org/apache/avro/util/TestUtf8.java 
Thu Feb  4 00:24:31 2010
@@ -0,0 +1,32 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.avro.util;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class TestUtf8 {
+  @Test public void testByteConstructor() throws Exception {
+    byte[] bs = "Foo".getBytes("UTF-8");
+    Utf8 u = new Utf8(bs);
+    assertEquals(bs.length, u.getLength());
+    for (int i=0; i<bs.length; i++) {
+      assertEquals(bs[i], u.getBytes()[i]);
+    }
+  }
+}


Reply via email to