Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericDatumWriter


      if (morphlineConfigFile.contains("Json")) {
        encoder = EncoderFactory.get().jsonEncoder(schema, bout);
      } else {
        encoder = EncoderFactory.get().binaryEncoder(bout, null);
      }
      GenericDatumWriter datumWriter = new GenericDatumWriter(schema);
      for (GenericData.Record record : expecteds) {
        datumWriter.write(record, encoder);
      }
      encoder.flush();
      bytes = bout.toByteArray();
    }
View Full Code Here


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

      void write(Object o, Encoder encoder) throws IOException {
         GenericDatumWriter<Object> writer = new GenericDatumWriter(schema); // TODO: Could this be cached? Maybe, but ctor is very cheap
         encoder.writeInt(id);
         write(writer, o, encoder);
      }
View Full Code Here

    }

    GenerateRandomData grd = new GenerateRandomData();
    Schema schema = Schema.parse(inputSchemaFile);

    GenericDatumWriter datum = new GenericDatumWriter(schema);
    DataFileWriter out = new DataFileWriter(datum);
    out.create(schema, outputDataFile);
    try {
      for (int i = 0; i < numToEmit; i++) {
        out.append((GenericData.Record) grd.generateData(schema));
View Full Code Here

    //
    // Apply the typetree's parser.
    //
    if (jsonDataFile != null) {
      Schema schema = typeTree.getAvroSchema();
      GenericDatumWriter jsonGDWriter = new GenericDatumWriter(schema);     
      BufferedOutputStream outJson = new BufferedOutputStream(fs2.create(jsonDataFile));
      JsonEncoder encoder = EncoderFactory.get().jsonEncoder(schema, outJson);
      try {
        in = new BufferedReader(new InputStreamReader(fs.open(p)));
        try {
          String str = in.readLine();
          while (str != null) {
            GenericContainer gct = typeTree.parse(str);

            if (gct != null) {
              jsonGDWriter.write(gct, encoder);
            }
            str = in.readLine();
          }     
        } finally {
          in.close();
        }
      } finally {
        encoder.flush();
        outJson.close();
      }
    }

    if (avroDataFile != null) {
      int numGoodParses = 0;
      int lineno = 0;
      Schema schema = typeTree.getAvroSchema();

      GenericDatumWriter gdWriter = new GenericDatumWriter(schema);
      DataFileWriter outData = new DataFileWriter(gdWriter);
      outData = outData.create(schema, fs2.create(avroDataFile));

      try {
        in = new BufferedReader(new InputStreamReader(fs.open(p)));
View Full Code Here

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

      void write(Object o, Encoder encoder) throws IOException {
         GenericDatumWriter<Object> writer = new GenericDatumWriter(schema); // TODO: Could this be cached? Maybe, but ctor is very cheap
         encoder.writeInt(id);
         write(writer, o, encoder);
      }
View Full Code Here

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

      void write(Object o, Encoder encoder) throws IOException {
         GenericDatumWriter<Object> writer = new GenericDatumWriter(schema); // TODO: Could this be cached? Maybe, but ctor is very cheap
         encoder.writeInt(id);
         write(writer, o, encoder);
      }
View Full Code Here

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

      void write(Object o, Encoder encoder) throws IOException {
         GenericDatumWriter writer = new GenericDatumWriter(schema); // TODO: Could this be cached? Maybe, but ctor is very cheap
         encoder.writeInt(id);
         write(writer, o, encoder);
      }
View Full Code Here

      final String typeName,
      final StageToHdfsPlugin plugin ) {
    if (!cachedWriters.containsKey(typeName)) {
      FSDataOutputStream out = null;
      final DataFileWriter dfw = new DataFileWriter(
          new GenericDatumWriter());
      cachedWriters.put(
          typeName,
          dfw);
      dfw.setCodec(CodecFactory.snappyCodec());
      try {
View Full Code Here

TOP

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

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.