avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r898014 - in /hadoop/avro/trunk: ./ src/java/org/apache/avro/ipc/ src/java/org/apache/avro/reflect/ src/java/org/apache/avro/specific/ src/test/java/org/apache/avro/
Date Mon, 11 Jan 2010 19:13:18 GMT
Author: cutting
Date: Mon Jan 11 19:13:17 2010
New Revision: 898014

URL: http://svn.apache.org/viewvc?rev=898014&view=rev
Log:
AVRO-298.  Fix Java's DatumReader and DatumWriter APIs to better use generics.  Contributed
by philz.

Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/java/org/apache/avro/ipc/Requestor.java
    hadoop/avro/trunk/src/java/org/apache/avro/ipc/Responder.java
    hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumReader.java
    hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumWriter.java
    hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectRequestor.java
    hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectResponder.java
    hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumReader.java
    hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumWriter.java
    hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificRequestor.java
    hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificResponder.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestCompare.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Mon Jan 11 19:13:17 2010
@@ -188,6 +188,9 @@
     AVRO-294. Clarify that bytes and fixed are unsigned, and how their
     JSON default values are interpreted.  (Jeff Hammerbacher & cutting)
 
+    AVRO-298. Fix Java's DatumReader and DatumWriter APIs to better
+    use generics.  (philz via cutting)
+
   OPTIMIZATIONS
 
     AVRO-172. More efficient schema processing (massie)

Modified: hadoop/avro/trunk/src/java/org/apache/avro/ipc/Requestor.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/ipc/Requestor.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/ipc/Requestor.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/ipc/Requestor.java Mon Jan 11 19:13:17 2010
@@ -144,11 +144,11 @@
   private static final Map<MD5,Protocol> REMOTE_PROTOCOLS =
     Collections.synchronizedMap(new HashMap<MD5,Protocol>());
 
-  private static final SpecificDatumWriter HANDSHAKE_WRITER =
-    new SpecificDatumWriter(HandshakeRequest.class);
+  private static final SpecificDatumWriter<HandshakeRequest> HANDSHAKE_WRITER =
+    new SpecificDatumWriter<HandshakeRequest>(HandshakeRequest.class);
 
-  private static final SpecificDatumReader HANDSHAKE_READER =
-    new SpecificDatumReader(HandshakeResponse.class);
+  private static final SpecificDatumReader<HandshakeResponse> HANDSHAKE_READER =
+    new SpecificDatumReader<HandshakeResponse>(HandshakeResponse.class);
 
   private void writeHandshake(Encoder out) throws IOException {
     MD5 localHash = new MD5();
@@ -175,11 +175,9 @@
     HANDSHAKE_WRITER.write(handshake, out);
   }
 
-  @SuppressWarnings("unchecked")
   private boolean readHandshake(Decoder in) throws IOException {
     boolean established = false;
-    HandshakeResponse handshake =
-      (HandshakeResponse)HANDSHAKE_READER.read(null, in);
+    HandshakeResponse handshake = HANDSHAKE_READER.read(null, in);
     switch (handshake.match) {
     case BOTH:
       established = true;

Modified: hadoop/avro/trunk/src/java/org/apache/avro/ipc/Responder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/ipc/Responder.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/ipc/Responder.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/ipc/Responder.java Mon Jan 11 19:13:17 2010
@@ -153,12 +153,11 @@
     return bbo.getBufferList();
   }
 
-  private SpecificDatumWriter handshakeWriter =
-    new SpecificDatumWriter(HandshakeResponse.class);
-  private SpecificDatumReader handshakeReader =
-    new SpecificDatumReader(HandshakeRequest.class);
+  private SpecificDatumWriter<HandshakeResponse> handshakeWriter =
+    new SpecificDatumWriter<HandshakeResponse>(HandshakeResponse.class);
+  private SpecificDatumReader<HandshakeRequest> handshakeReader =
+    new SpecificDatumReader<HandshakeRequest>(HandshakeRequest.class);
 
-  @SuppressWarnings("unchecked")
   private Protocol handshake(Decoder in, Encoder out)
     throws IOException {
     HandshakeRequest request = (HandshakeRequest)handshakeReader.read(null, in);

Modified: hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumReader.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumReader.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumReader.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumReader.java Mon Jan 11
19:13:17 2010
@@ -33,10 +33,10 @@
  * {@link org.apache.avro.io.DatumReader DatumReader} for existing classes via
  * Java reflection.
  */
-public class ReflectDatumReader extends SpecificDatumReader {
+public class ReflectDatumReader<T> extends SpecificDatumReader<T> {
   public ReflectDatumReader() {}
 
-  public ReflectDatumReader(Class c) {
+  public ReflectDatumReader(Class<T> c) {
     this(ReflectData.get().getSchema(c));
   }
 
@@ -66,7 +66,7 @@
   @SuppressWarnings(value="unchecked")
   protected Object newArray(Object old, int size, Schema schema) {
     ReflectData data = ReflectData.get();
-    Class collectionClass = data.getClassProp(schema, ReflectData.CLASS_PROP);
+    Class collectionClass = ReflectData.getClassProp(schema, ReflectData.CLASS_PROP);
     if (collectionClass != null) {
       if (old instanceof Collection) {
         ((Collection)old).clear();
@@ -76,7 +76,7 @@
         return new ArrayList();
       return newInstance(collectionClass);
     }
-    Class elementClass = data.getClassProp(schema, ReflectData.ELEMENT_PROP);
+    Class elementClass = ReflectData.getClassProp(schema, ReflectData.ELEMENT_PROP);
     if (elementClass == null)
       elementClass = data.getClass(schema.getElementType());
     return Array.newInstance(elementClass, size);

Modified: hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumWriter.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumWriter.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumWriter.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectDatumWriter.java Mon Jan 11
19:13:17 2010
@@ -32,16 +32,16 @@
  * {@link org.apache.avro.io.DatumWriter DatumWriter} for existing classes
  * via Java reflection.
  */
-public class ReflectDatumWriter extends SpecificDatumWriter {
+public class ReflectDatumWriter<T> extends SpecificDatumWriter<T> {
   public ReflectDatumWriter() {
     this(ReflectData.get());
   }
 
-  public ReflectDatumWriter(Class c) {
+  public ReflectDatumWriter(Class<T> c) {
     this(c, ReflectData.get());
   }
 
-  public ReflectDatumWriter(Class c, ReflectData data) {
+  public ReflectDatumWriter(Class<T> c, ReflectData data) {
     this(data.getSchema(c), data);
   }
 

Modified: hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectRequestor.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectRequestor.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectRequestor.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectRequestor.java Mon Jan 11 19:13:17
2010
@@ -43,12 +43,12 @@
     
   @Override
   protected DatumWriter<Object> getDatumWriter(Schema schema) {
-    return new ReflectDatumWriter(schema);
+    return new ReflectDatumWriter<Object>(schema);
   }
 
   @Override
   protected DatumReader<Object> getDatumReader(Schema schema) {
-    return new ReflectDatumReader(schema);
+    return new ReflectDatumReader<Object>(schema);
   }
 
   /** Create a proxy instance whose methods invoke RPCs. */

Modified: hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectResponder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectResponder.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectResponder.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/reflect/ReflectResponder.java Mon Jan 11 19:13:17
2010
@@ -36,12 +36,12 @@
 
   @Override
   protected DatumWriter<Object> getDatumWriter(Schema schema) {
-    return new ReflectDatumWriter(schema);
+    return new ReflectDatumWriter<Object>(schema);
   }
 
   @Override
   protected DatumReader<Object> getDatumReader(Schema schema) {
-    return new ReflectDatumReader(schema);
+    return new ReflectDatumReader<Object>(schema);
   }
 
 }

Modified: hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumReader.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumReader.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumReader.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumReader.java Mon Jan 11
19:13:17 2010
@@ -25,10 +25,10 @@
 import org.apache.avro.generic.GenericDatumReader;
 
 /** {@link org.apache.avro.io.DatumReader DatumReader} for generated Java classes. */
-public class SpecificDatumReader extends GenericDatumReader<Object> {
+public class SpecificDatumReader<T> extends GenericDatumReader<T> {
   public SpecificDatumReader() {}
 
-  public SpecificDatumReader(Class c) {
+  public SpecificDatumReader(Class<T> c) {
     this(SpecificData.get().getSchema(c));
   }
 

Modified: hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumWriter.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumWriter.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumWriter.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificDatumWriter.java Mon Jan 11
19:13:17 2010
@@ -24,10 +24,10 @@
 import org.apache.avro.io.Encoder;
 
 /** {@link org.apache.avro.io.DatumWriter DatumWriter} for generated Java classes. */
-public class SpecificDatumWriter extends GenericDatumWriter<Object> {
+public class SpecificDatumWriter<T> extends GenericDatumWriter<T> {
   public SpecificDatumWriter() {}
 
-  public SpecificDatumWriter(Class c) {
+  public SpecificDatumWriter(Class<T> c) {
     super(SpecificData.get().getSchema(c), SpecificData.get());
   }
   

Modified: hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificRequestor.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificRequestor.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificRequestor.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificRequestor.java Mon Jan 11
19:13:17 2010
@@ -54,11 +54,11 @@
   }
 
   protected DatumWriter<Object> getDatumWriter(Schema schema) {
-    return new SpecificDatumWriter(schema);
+    return new SpecificDatumWriter<Object>(schema);
   }
 
   protected DatumReader<Object> getDatumReader(Schema schema) {
-    return new SpecificDatumReader(schema);
+    return new SpecificDatumReader<Object>(schema);
   }
 
   @Override

Modified: hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificResponder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificResponder.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificResponder.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/specific/SpecificResponder.java Mon Jan 11
19:13:17 2010
@@ -55,11 +55,11 @@
   }
 
   protected DatumWriter<Object> getDatumWriter(Schema schema) {
-    return new SpecificDatumWriter(schema);
+    return new SpecificDatumWriter<Object>(schema);
   }
 
   protected DatumReader<Object> getDatumReader(Schema schema) {
-    return new SpecificDatumReader(schema);
+    return new SpecificDatumReader<Object>(schema);
   }
 
   @Override

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestCompare.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestCompare.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestCompare.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestCompare.java Mon Jan 11 19:13:17 2010
@@ -172,28 +172,28 @@
     s2.hash.bytes(new byte[] {0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,6});
     Schema schema = SpecificData.get().getSchema(TestRecord.class);
 
-    check(schema, s1, s2, true, new SpecificDatumWriter(schema),
+    check(schema, s1, s2, true, new SpecificDatumWriter<TestRecord>(schema),
           SpecificData.get());
     s2.kind = Kind.BAZ;
-    check(schema, s1, s2, true, new SpecificDatumWriter(schema),
+    check(schema, s1, s2, true, new SpecificDatumWriter<TestRecord>(schema),
           SpecificData.get());
   }  
 
-  private static void check(String schemaJson, Object o1, Object o2)
+  private static <T> void check(String schemaJson, T o1, T o2)
     throws Exception {
     check(schemaJson, o1, o2, true);
   }
 
-  private static void check(String schemaJson, Object o1, Object o2,
+  private static <T> void check(String schemaJson, T o1, T o2,
                             boolean comparable)
     throws Exception {
     check(Schema.parse(schemaJson), o1, o2, comparable,
-          new GenericDatumWriter<Object>(), GenericData.get());
+          new GenericDatumWriter<T>(), GenericData.get());
   }
 
-  private static void check(Schema schema, Object o1, Object o2,
+  private static <T> void check(Schema schema, T o1, T o2,
                             boolean comparable,
-                            DatumWriter<Object> writer,
+                            DatumWriter<T> writer,
                             GenericData comparator)
     throws Exception {
 
@@ -229,8 +229,8 @@
       : comparator.compare(o1, o2, schema);
   }
 
-  private static byte[] render(Object datum, Schema schema,
-                               DatumWriter<Object> writer)
+  private static <T> byte[] render(T datum, Schema schema,
+                               DatumWriter<T> writer)
     throws IOException {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     writer.setSchema(schema);

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFile.java Mon Jan 11 19:13:17
2010
@@ -180,7 +180,7 @@
 
   @Test
     public void testGeneratedSpecific() throws IOException {
-      readFiles(new SpecificDatumReader());
+      readFiles(new SpecificDatumReader<Object>());
     }
 
   // Can't use same Interop.java as specific for reflect, since its stringField

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestDataFileReflect.java Mon Jan 11 19:13:17
2010
@@ -53,18 +53,18 @@
         reflectData.getSchema(BarRecord.class) });
     Schema union = Schema.createUnion(schemas);
     DataFileWriter<Object> writer =
-      new DataFileWriter<Object>(new ReflectDatumWriter(union))
+      new DataFileWriter<Object>(new ReflectDatumWriter<Object>(union))
       .create(union, fos);
 
     // test writing to a file
-    CheckList check = new CheckList();
+    CheckList<Object> check = new CheckList<Object>();
     write(writer, new BarRecord("One beer please"), check);
     write(writer, new FooRecord(10), check);
     write(writer, new BarRecord("Two beers please"), check);
     write(writer, new FooRecord(20), check);
     writer.close();
 
-    ReflectDatumReader din = new ReflectDatumReader();
+    ReflectDatumReader<Object> din = new ReflectDatumReader<Object>();
     SeekableFileInput sin = new SeekableFileInput(FILE);
     DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
     int count = 0;
@@ -83,23 +83,23 @@
 
     ReflectData reflectData = ReflectData.AllowNull.get();
     Schema schema = reflectData.getSchema(BarRecord.class);
-    DataFileWriter<Object> writer = new DataFileWriter<Object>
-      (new ReflectDatumWriter(BarRecord.class, reflectData))
+    DataFileWriter<BarRecord> writer = new DataFileWriter<BarRecord>
+      (new ReflectDatumWriter<BarRecord>(BarRecord.class, reflectData))
       .create(schema, fos);
 
     // test writing to a file
-    CheckList check = new CheckList();
+    CheckList<BarRecord> check = new CheckList<BarRecord>();
     write(writer, new BarRecord("One beer please"), check);
     // null record here, fails when using the default reflectData instance
     write(writer, new BarRecord(), check);
     write(writer, new BarRecord("Two beers please"), check);
     writer.close();
 
-    ReflectDatumReader din = new ReflectDatumReader();
+    ReflectDatumReader<BarRecord> din = new ReflectDatumReader<BarRecord>();
     SeekableFileInput sin = new SeekableFileInput(FILE);
-    DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
+    DataFileReader<BarRecord> reader = new DataFileReader<BarRecord>(sin, din);
     int count = 0;
-    for (Object datum : reader)
+    for (BarRecord datum : reader)
       check.assertEquals(datum, count++);
     Assert.assertEquals(count, check.size());
     reader.close();
@@ -113,34 +113,34 @@
     FileOutputStream fos = new FileOutputStream(FILE);
 
     Schema schema = ReflectData.get().getSchema(BazRecord.class);
-    DataFileWriter<Object> writer =
-      new DataFileWriter<Object>(new ReflectDatumWriter(schema))
+    DataFileWriter<BazRecord> writer =
+      new DataFileWriter<BazRecord>(new ReflectDatumWriter<BazRecord>(schema))
       .create(schema, fos);
 
     // test writing to a file
-    CheckList check = new CheckList();
+    CheckList<BazRecord> check = new CheckList<BazRecord>();
     write(writer, new BazRecord(10), check);
     write(writer, new BazRecord(20), check);
     writer.close();
 
-    ReflectDatumReader din = new ReflectDatumReader();
+    ReflectDatumReader<BazRecord> din = new ReflectDatumReader<BazRecord>();
     SeekableFileInput sin = new SeekableFileInput(FILE);
-    DataFileReader<Object> reader = new DataFileReader<Object>(sin, din);
+    DataFileReader<BazRecord> reader = new DataFileReader<BazRecord>(sin, din);
     int count = 0;
-    for (Object datum : reader)
+    for (BazRecord datum : reader)
       check.assertEquals(datum, count++);
     Assert.assertEquals(count, check.size());
     reader.close();
   }
 
-  private void write(DataFileWriter<Object> writer, Object o, CheckList l)
+  private <T> void write(DataFileWriter<T> writer, T o, CheckList<T> l)
       throws IOException {
     writer.append(l.addAndReturn(o));
   }
 
   @SuppressWarnings("serial")
-  private static class CheckList extends ArrayList<Object> {
-    Object addAndReturn(Object check) {
+  private static class CheckList<T> extends ArrayList<T> {
+    T addAndReturn(T check) {
       add(check);
       return check;
     }

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java?rev=898014&r1=898013&r2=898014&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestReflect.java Mon Jan 11 19:13:17 2010
@@ -268,10 +268,10 @@
     checkReadWrite(object, ReflectData.get().getSchema(object.getClass()));
   }
   void checkReadWrite(Object object, Schema s) throws Exception {
-    ReflectDatumWriter writer = new ReflectDatumWriter(s);
+    ReflectDatumWriter<Object> writer = new ReflectDatumWriter<Object>(s);
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     writer.write(object, new BinaryEncoder(out));
-    ReflectDatumReader reader = new ReflectDatumReader(s);
+    ReflectDatumReader<Object> reader = new ReflectDatumReader<Object>(s);
     Object after =
       reader.read(null, new BinaryDecoder
                   (new ByteArrayInputStream(out.toByteArray())));
@@ -303,14 +303,16 @@
   @Test
   public void testRecordIO() throws IOException {
     Schema schm = ReflectData.get().getSchema(SampleRecord.class);
-    ReflectDatumWriter writer = new ReflectDatumWriter(schm);
+    ReflectDatumWriter<SampleRecord> writer = 
+      new ReflectDatumWriter<SampleRecord>(schm);
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     SampleRecord record = new SampleRecord();
     record.x = 5;
     record.y = 10;
     writer.write(record, new BinaryEncoder(out));
-    ReflectDatumReader reader = new ReflectDatumReader(schm);
-    Object decoded =
+    ReflectDatumReader<SampleRecord> reader = 
+      new ReflectDatumReader<SampleRecord>(schm);
+    SampleRecord decoded =
       reader.read(null, new BinaryDecoder
                   (new ByteArrayInputStream(out.toByteArray())));
     assertEquals(record, decoded);
@@ -320,16 +322,18 @@
   public void testRecordWithNullIO() throws IOException {
     ReflectData reflectData = ReflectData.AllowNull.get();
     Schema schm = reflectData.getSchema(AnotherSampleRecord.class);
-    ReflectDatumWriter writer = new ReflectDatumWriter(schm);
+    ReflectDatumWriter<AnotherSampleRecord> writer = 
+      new ReflectDatumWriter<AnotherSampleRecord>(schm);
     ByteArrayOutputStream out = new ByteArrayOutputStream();
     // keep record.a null and see if that works
     AnotherSampleRecord a = new AnotherSampleRecord();
     writer.write(a, new BinaryEncoder(out));
     AnotherSampleRecord b = new AnotherSampleRecord(10);
     writer.write(b, new BinaryEncoder(out));
-    ReflectDatumReader reader = new ReflectDatumReader(schm);
+    ReflectDatumReader<AnotherSampleRecord> reader = 
+      new ReflectDatumReader<AnotherSampleRecord>(schm);
     ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
-    Object decoded = reader.read(null, new BinaryDecoder(in));
+    AnotherSampleRecord decoded = reader.read(null, new BinaryDecoder(in));
     assertEquals(a, decoded);
     decoded = reader.read(null, new BinaryDecoder(in));
     assertEquals(b, decoded);



Mime
View raw message