avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1027736 - in /avro/trunk: CHANGES.txt lang/java/src/java/org/apache/avro/file/DataFileStream.java lang/java/src/test/java/org/apache/avro/TestDataFileMeta.java
Date Tue, 26 Oct 2010 20:32:13 GMT
Author: cutting
Date: Tue Oct 26 20:32:13 2010
New Revision: 1027736

URL: http://svn.apache.org/viewvc?rev=1027736&view=rev
Log:
AVRO-682.  Java: Add method DataFileStream.getMetaKeys().  Contributed by Harsh J Chouraria.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileStream.java
    avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFileMeta.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1027736&r1=1027735&r2=1027736&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Oct 26 20:32:13 2010
@@ -14,6 +14,11 @@ Avro 1.5.0 (unreleased)
     moves some protected GenericDatumReader/Writer methods to
     GenericData, potentially breaking subclasses. (cutting)
 
+  IMPROVEMENTS
+
+    AVRO-682. Java: Add method DataFileStream.getMetaKeys().
+    (Harsh J Chouraria via cutting)
+
   BUG FIXES
 
     AVRO-675. C: Bytes and fixed setters don't update datum size.

Modified: avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileStream.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileStream.java?rev=1027736&r1=1027735&r2=1027736&view=diff
==============================================================================
--- avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileStream.java (original)
+++ avro/trunk/lang/java/src/java/org/apache/avro/file/DataFileStream.java Tue Oct 26 20:32:13
2010
@@ -24,8 +24,11 @@ import java.io.Closeable;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.NoSuchElementException;
 
@@ -54,6 +57,7 @@ public class DataFileStream<D> implement
   BinaryDecoder datumIn = null;
 
   Map<String,byte[]> meta = new HashMap<String,byte[]>();
+  List<String> metaKeyList = new ArrayList<String>();
 
   ByteBuffer blockBuffer;
   long blockCount;                              // # entries in block
@@ -99,9 +103,14 @@ public class DataFileStream<D> implement
           byte[] bb = new byte[value.remaining()];
           value.get(bb);
           meta.put(key, bb);
+          metaKeyList.add(key);
         }
       } while ((l = vin.mapNext()) != 0);
     }
+    
+    // Make the meta keys list unmodifiable.
+    metaKeyList = Collections.unmodifiableList(metaKeyList);
+    
     vin.readFixed(sync);                          // read sync
 
     this.codec = resolveCodec();
@@ -122,6 +131,11 @@ public class DataFileStream<D> implement
   /** Return the schema used in this file. */
   public Schema getSchema() { return schema; }
 
+  /** Return the list of keys in the metadata */
+  public List<String> getMetaKeys() {
+    return metaKeyList;
+  }
+
   /** Return the value of a metadata property. */
   public byte[] getMeta(String key) {
     return meta.get(key);

Modified: avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFileMeta.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFileMeta.java?rev=1027736&r1=1027735&r2=1027736&view=diff
==============================================================================
--- avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFileMeta.java (original)
+++ avro/trunk/lang/java/src/test/java/org/apache/avro/TestDataFileMeta.java Tue Oct 26 20:32:13
2010
@@ -18,6 +18,7 @@
 package org.apache.avro;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -49,6 +50,9 @@ public class TestDataFileMeta {
     w.close();
 
     DataFileStream<Void> r = new DataFileStream<Void>(new FileInputStream(f),
new GenericDatumReader<Void>());
+
+    assertTrue(r.getMetaKeys().contains("hello"));
+
     assertEquals("bar", r.getMetaString("hello"));
   }
 



Mime
View raw message