Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericDatumReader


    String recordJson =
      "{\"type\":\"record\", \"name\":\"Foo\", \"fields\":[{\"name\":\"f\", "
    +"\"type\":"+schemaJson+", "
    +"\"default\":"+defaultJson+"}]}";
    Schema expected = Schema.parse(recordJson);
    DatumReader in = new GenericDatumReader(ACTUAL, expected);
    GenericData.Record record = (GenericData.Record)
      in.read(null, DecoderFactory.defaultFactory().createBinaryDecoder(
          new byte[0], null));
    assertEquals("Wrong default.", defaultValue, record.get("f"));
    assertEquals("Wrong toString", expected, Schema.parse(expected.toString()));
  }
View Full Code Here


         this.type = type;
      }

      @Override
      Object read(Decoder decoder) throws IOException {
         GenericData.Array<T> avroArray = (GenericData.Array<T>) new GenericDatumReader(schema).read(null, decoder);
         List<T> list = new ArrayList<T>((int) avroArray.size());
         for (T t : avroArray)
            list.add(t);
         T[] array = (T[]) Array.newInstance(type, list.size());
         return toArray(list, array);
View Full Code Here

         this.schema = schema;
         this.id = id;
      }

      Object read(Decoder decoder) throws IOException {
         return new GenericDatumReader(schema).read(null, decoder);
      }
View Full Code Here

         super(STRING_SCHEMA, id);
      }

      @Override
      Object read(Decoder decoder) throws IOException {
         return new GenericDatumReader(schema).read(null, decoder).toString();
      }
View Full Code Here

         super(BYTES_SCHEMA, id);
      }

      @Override
      Object read(Decoder decoder) throws IOException {
         java.nio.ByteBuffer byteBuffer = (java.nio.ByteBuffer) new GenericDatumReader(schema).read(null, decoder);
         byte[] bytes = new byte[byteBuffer.limit()]; // TODO: Limit or capacity ? Limit works
         byteBuffer.get(bytes);
         return bytes;
      }
View Full Code Here

         super(STRING_ARRAY_SCHEMA, id);
      }

      @Override
      Object read(Decoder decoder) throws IOException {
         GenericData.Array<Utf8> utf8s = (GenericData.Array<Utf8>) new GenericDatumReader(schema).read(null, decoder);
         List<String> strings = new ArrayList<String>((int) utf8s.size());
         for (Utf8 utf8 : utf8s)
            strings.add(utf8.toString());
         return strings.toArray(new String[0]);
      }
View Full Code Here

                    inStream = new BufferedInputStream(fs.open(path));
                } catch(IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                GenericDatumReader datum = new GenericDatumReader();

                DataFileStream reader = null;
                try {
                    reader = new DataFileStream(inStream, datum);
                } catch(IOException e) {
View Full Code Here

         this.schema = schema;
         this.id = id;
      }

      Object read(Decoder decoder) throws IOException {
         return new GenericDatumReader(schema).read(null, decoder);
      }
View Full Code Here

         super(STRING_SCHEMA, id);
      }

      @Override
      Object read(Decoder decoder) throws IOException {
         return new GenericDatumReader(schema).read(null, decoder).toString();
      }
View Full Code Here

         super(BYTES_SCHEMA, id);
      }

      @Override
      Object read(Decoder decoder) throws IOException {
         java.nio.ByteBuffer byteBuffer = (java.nio.ByteBuffer) new GenericDatumReader(schema).read(null, decoder);
         byte[] bytes = new byte[byteBuffer.limit()]; // TODO: Limit or capacity ? Limit works
         byteBuffer.get(bytes);
         return bytes;
      }
View Full Code Here

TOP

Related Classes of org.apache.avro.generic.GenericDatumReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.