You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2010/12/10 21:24:26 UTC
svn commit: r1044498 - in /avro/trunk: CHANGES.txt
lang/java/src/java/org/apache/avro/io/DirectBinaryDecoder.java
lang/java/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
Author: cutting
Date: Fri Dec 10 20:24:26 2010
New Revision: 1044498
URL: http://svn.apache.org/viewvc?rev=1044498&view=rev
Log:
AVRO-705. Java: Fix DirectBinaryDecoder to correctly reinitialize. Contributed by Gilles Gaillard and thiru.
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/src/java/org/apache/avro/io/DirectBinaryDecoder.java
avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1044498&r1=1044497&r2=1044498&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Dec 10 20:24:26 2010
@@ -67,6 +67,9 @@ Avro 1.5.0 (unreleased)
AVRO-704. Java: Fix SocketServer connection threads to exit rather
than busywait when client closes connection. (cutting)
+ AVRO-705. Java: Fix DirectBinaryDecoder to correctly reinitialize.
+ (thiru via cutting)
+
Avro 1.4.1 (13 October 2010)
NEW FEATURES
Modified: avro/trunk/lang/java/src/java/org/apache/avro/io/DirectBinaryDecoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/io/DirectBinaryDecoder.java?rev=1044498&r1=1044497&r2=1044498&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/io/DirectBinaryDecoder.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/io/DirectBinaryDecoder.java Fri Dec 10 20:24:26 2010
@@ -69,18 +69,18 @@ class DirectBinaryDecoder extends Binary
}
- private final ByteReader byteReader;
+ private ByteReader byteReader;
DirectBinaryDecoder(InputStream in) {
super();
- this.in = in;
- byteReader = (in instanceof ByteBufferInputStream) ?
- new ReuseByteReader((ByteBufferInputStream) in) : new ByteReader();
+ init(in);
}
@Override
public void init(InputStream in) {
this.in = in;
+ byteReader = (in instanceof ByteBufferInputStream) ?
+ new ReuseByteReader((ByteBufferInputStream) in) : new ByteReader();
}
@Override
Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestBinaryDecoder.java?rev=1044498&r1=1044497&r2=1044498&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestBinaryDecoder.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/io/TestBinaryDecoder.java Fri Dec 10 20:24:26 2010
@@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -30,6 +31,8 @@ import org.apache.avro.RandomData;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
+import org.apache.avro.ipc.ByteBufferInputStream;
+import org.apache.avro.ipc.ByteBufferOutputStream;
import org.apache.avro.util.Utf8;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -121,6 +124,31 @@ public class TestBinaryDecoder {
newDecoderWithNoData().readEnum();
}
+ @Test
+ public void testReuse() throws IOException {
+ ByteBufferOutputStream bbo1 = new ByteBufferOutputStream();
+ ByteBufferOutputStream bbo2 = new ByteBufferOutputStream();
+ byte[] b1 = new byte[] { 1, 2 };
+
+ BinaryEncoder e1 = new BinaryEncoder(bbo1);
+ e1.writeBytes(b1);
+ e1.flush();
+
+ BinaryEncoder e2 = new BinaryEncoder(bbo2);
+ e2.writeBytes(b1);
+ e2.flush();
+
+ DirectBinaryDecoder d = new DirectBinaryDecoder(
+ new ByteBufferInputStream(bbo1.getBufferList()));
+ ByteBuffer bb1 = d.readBytes(null);
+ Assert.assertEquals(b1.length, bb1.limit() - bb1.position());
+
+ d.init(new ByteBufferInputStream(bbo2.getBufferList()));
+ ByteBuffer bb2 = d.readBytes(null);
+ Assert.assertEquals(b1.length, bb2.limit() - bb2.position());
+
+ }
+
private static byte[] data = null;
private static int seed = -1;
private static Schema schema = null;