avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1598146 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/io/Encoder.java lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryEncoderFidelity.java
Date Wed, 28 May 2014 21:26:30 GMT
Author: cutting
Date: Wed May 28 21:26:30 2014
New Revision: 1598146

URL: http://svn.apache.org/r1598146
Log:
AVRO-1457. Java: Fix Encoder so that offset in non-array-backed ByteBuffers is not altered
when written. Contributed by Rob Turner.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/Encoder.java
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryEncoderFidelity.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1598146&r1=1598145&r2=1598146&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed May 28 21:26:30 2014
@@ -62,6 +62,9 @@ Trunk (not yet released)
     AVRO-1459. Ruby: Fix a typo in Rakefile that breaks 'gem install'.
     (Tomas Svarovsky via cutting)
 
+    AVRO-1457. Java: Fix Encoder so that offset in non-array-backed
+    ByteBuffers is not altered when written. (Rob Turner via cutting)
+
 Avro 1.7.6 (15 January 2014)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/Encoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/Encoder.java?rev=1598146&r1=1598145&r2=1598146&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/Encoder.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/Encoder.java Wed May 28 21:26:30
2014
@@ -174,7 +174,7 @@ public abstract class Encoder implements
       writeFixed(bytes.array(), bytes.arrayOffset() + pos, len);
     } else {
       byte[] b = new byte[len];
-      bytes.get(b, 0, len);
+      bytes.duplicate().get(b, 0, len);
       writeFixed(b, 0, len);
     }
   }

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java?rev=1598146&r1=1598145&r2=1598146&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java Wed May 28
21:26:30 2014
@@ -200,9 +200,7 @@ public class JsonEncoder extends Parsing
       writeBytes(bytes.array(), bytes.position(), bytes.remaining());
     } else {
       byte[] b = new byte[bytes.remaining()];
-      for (int i = 0; i < b.length; i++) {
-        b[i] = bytes.get();
-      }
+      bytes.duplicate().get(b);
       writeBytes(b);
     }
   }

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryEncoderFidelity.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryEncoderFidelity.java?rev=1598146&r1=1598145&r2=1598146&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryEncoderFidelity.java
(original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryEncoderFidelity.java
Wed May 28 21:26:30 2014
@@ -32,19 +32,27 @@ public class TestBinaryEncoderFidelity {
   static byte[] legacydata;
   static byte[] complexdata;
   EncoderFactory factory = EncoderFactory.get();
-  public static void generateData(Encoder e) throws IOException {
+  public static void generateData(Encoder e, boolean useReadOnlyByteBuffer) throws IOException
{
     // generate a bunch of data that should test the bounds of a BinaryEncoder
     Random r = new Random(665321);
     e.writeNull();
     e.writeBoolean(true);
     e.writeBoolean(false);
     byte[] bytes = new byte[10];
+    ByteBuffer bb;
+    if (useReadOnlyByteBuffer) {
+      bb = ByteBuffer.wrap(bytes, 4, 4).asReadOnlyBuffer();
+    } else {
+      bb = ByteBuffer.wrap(bytes, 4, 4);
+    }
     r.nextBytes(bytes);
     e.writeBytes(bytes);
     e.writeBytes(new byte[0]);
     e.writeBytes(bytes, 3, 3);
     e.writeBytes(new byte[0], 0, 0);
     e.writeBytes(ByteBuffer.wrap(bytes, 2, 2));
+    e.writeBytes(bb);
+    e.writeBytes(bb);
     e.writeDouble(0.0);
     e.writeDouble(-0.0);
     e.writeDouble(Double.NaN);
@@ -133,7 +141,7 @@ public class TestBinaryEncoderFidelity {
   public static void generateLegacyData() throws IOException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     Encoder e = new LegacyBinaryEncoder(baos);
-    generateData(e);
+    generateData(e, false);
     legacydata = baos.toByteArray();
     baos.reset();
     generateComplexData(e);
@@ -144,7 +152,7 @@ public class TestBinaryEncoderFidelity {
   public void testBinaryEncoder() throws IOException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     BinaryEncoder e = factory.binaryEncoder(baos, null);
-    generateData(e);
+    generateData(e, true);
     byte[] result = baos.toByteArray();
     Assert.assertEquals(legacydata.length, result.length);
     Assert.assertArrayEquals(legacydata, result);
@@ -159,7 +167,7 @@ public class TestBinaryEncoderFidelity {
   public void testDirectBinaryEncoder() throws IOException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     BinaryEncoder e = factory.directBinaryEncoder(baos, null);
-    generateData(e);
+    generateData(e, true);
     byte[] result = baos.toByteArray();
     Assert.assertEquals(legacydata.length, result.length);
     Assert.assertArrayEquals(legacydata, result);
@@ -175,7 +183,7 @@ public class TestBinaryEncoderFidelity {
   public void testBlockingBinaryEncoder() throws IOException {
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     BinaryEncoder e = factory.blockingBinaryEncoder(baos, null);
-    generateData(e);
+    generateData(e, true);
     byte[] result = baos.toByteArray();
     Assert.assertEquals(legacydata.length, result.length);
     Assert.assertArrayEquals(legacydata, result);



Mime
View raw message