avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r818637 - in /hadoop/avro/trunk: ./ src/java/org/apache/avro/io/ src/java/org/apache/avro/io/parsing/ src/test/java/org/apache/avro/
Date Thu, 24 Sep 2009 21:42:08 GMT
Author: cutting
Date: Thu Sep 24 21:42:08 2009
New Revision: 818637

URL: http://svn.apache.org/viewvc?rev=818637&view=rev
Log:
AVRO-118.  JSON codec now permits one to read and write multiple instances without flushing
or explicitly resetting the codec between each instance.  Contributed by Thiruvalluvan M.
G.

Modified:
    hadoop/avro/trunk/.gitignore
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/java/org/apache/avro/io/JsonEncoder.java
    hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/JsonGrammarGenerator.java
    hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Parser.java
    hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Symbol.java
    hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java

Modified: hadoop/avro/trunk/.gitignore
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/.gitignore?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/.gitignore (original)
+++ hadoop/avro/trunk/.gitignore Thu Sep 24 21:42:08 2009
@@ -1,2 +1,4 @@
 build
 *.pyc
+.svn
+test-output

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Thu Sep 24 21:42:08 2009
@@ -25,6 +25,10 @@
     AVRO-119.  Add Java GenericData.Array#toString() implementation,
     to facillitate debugging. (cutting)
 
+    AVRO-118.  JSON encoder and decoder now permit one to write
+    multiple instances without flushing or explicitly resetting the
+    codec between each instance.  (Thiruvalluvan M. G. via cutting)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/avro/trunk/src/java/org/apache/avro/io/JsonEncoder.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/io/JsonEncoder.java?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/io/JsonEncoder.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/io/JsonEncoder.java Thu Sep 24 21:42:08 2009
@@ -53,9 +53,7 @@
 
   @Override
   public void flush() throws IOException {
-    if (parser.depth() > 1) {
-      parser.advance(Symbol.END);
-    }
+    parser.processImplicitActions();
     out.flush();
   }
 

Modified: hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/JsonGrammarGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/JsonGrammarGenerator.java?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/JsonGrammarGenerator.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/JsonGrammarGenerator.java Thu Sep
24 21:42:08 2009
@@ -34,8 +34,7 @@
    * for the grammar for the grammar for the given schema <tt>sc</tt>.
    */
   public Symbol generate(Schema schema) {
-    return Symbol.root(Symbol.END,
-        generate(schema, new HashMap<LitS, Symbol>()));
+    return Symbol.root(generate(schema, new HashMap<LitS, Symbol>()));
   }
 
   /**

Modified: hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Parser.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Parser.java?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Parser.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Parser.java Thu Sep 24 21:42:08
2009
@@ -87,6 +87,27 @@
       }
     }
   }
+  
+  /**
+   * Performs any implicit actions at the top the stack, expanding any
+   * production (other than the root) that may be encountered.
+   * This method will fail if there are any repeaters on the stack.
+   * @throws IOException
+   */
+  public final void processImplicitActions() throws IOException {
+     while (pos > 1) {
+      Symbol top = stack[pos - 1];
+      if (top.kind == Symbol.Kind.IMPLICIT_ACTION) {
+        pos--;
+        symbolHandler.doAction(null, top);
+      } else if (top.kind != Symbol.Kind.TERMINAL) {
+        pos--;
+        pushProduction(null, top);
+      } else {
+        break;
+      }
+    }
+  }
 
   /**
    * Pushes the production for the given symbol <tt>sym</tt>.

Modified: hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Symbol.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Symbol.java?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Symbol.java (original)
+++ hadoop/avro/trunk/src/java/org/apache/avro/io/parsing/Symbol.java Thu Sep 24 21:42:08
2009
@@ -364,7 +364,6 @@
   public static final Symbol ARRAY_END = new Symbol.Terminal("array-end");
   public static final Symbol MAP_START = new Symbol.Terminal("map-start");
   public static final Symbol MAP_END = new Symbol.Terminal("map-end");
-  public static final Symbol END = new Symbol.Terminal("end");
   public static final Symbol ITEM_END = new Symbol.Terminal("item-end");
 
   /* a pseudo terminal used by parsers */

Modified: hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java?rev=818637&r1=818636&r2=818637&view=diff
==============================================================================
--- hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java (original)
+++ hadoop/avro/trunk/src/test/java/org/apache/avro/TestSchema.java Thu Sep 24 21:42:08 2009
@@ -240,13 +240,16 @@
     Encoder encoder = new JsonEncoder(schema, out);
     writer.setSchema(schema);
     writer.write(datum, encoder);
+    writer.write(datum, encoder);
     encoder.flush();
     byte[] data = out.toByteArray();
 
     reader.setSchema(schema);
-    Object decoded =
-      reader.read(null, new JsonDecoder(schema, new ByteArrayInputStream(data)));
-      
+    Decoder decoder = new JsonDecoder(schema, new ByteArrayInputStream(data));
+    Object decoded = reader.read(null, decoder);
+    assertEquals("Decoded data does not match.", datum, decoded);
+
+    decoded = reader.read(decoded, decoder);
     assertEquals("Decoded data does not match.", datum, decoded);
   }
 



Mime
View raw message