Package org.apache.avro.generic

Examples of org.apache.avro.generic.GenericDatumWriter


    private File currentFile = null;

    public DumpEventHandler(String dir, Schema schema)
        throws IOException
    {
      DataFileWriter<GenericRecord> writeCreator = new DataFileWriter<GenericRecord>(new GenericDatumWriter(schema));
      directory = new File(dir);

      if (! directory.isDirectory())
        throw new RuntimeException("The path (" + dir + ") either does not exist or is not a directory !!");
View Full Code Here


    fileReader = new DataFileReader<GenericRecord>(in,
        new GenericDatumReader<GenericRecord>());
    fileReader.sync(pos);

    schema = fileReader.getSchema();
    datumWriter = new GenericDatumWriter(schema);
    out = new ByteArrayOutputStream();
    encoder = EncoderFactory.get().binaryEncoder(out, encoder);

    schemaHash = SchemaNormalization.parsingFingerprint("CRC-64-AVRO", schema);
    schemaHashString = Hex.encodeHexString(schemaHash);
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

      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

                    String name, Progressable prog)
    throws IOException {

    Schema schema = AvroJob.getOutputSchema(job);
   
    final DataFileWriter writer = new DataFileWriter(new GenericDatumWriter());

    if (FileOutputFormat.getCompressOutput(job)) {
      int level = job.getInt(AvroOutputFormat.DEFLATE_LEVEL_KEY,
                             CodecFactory.DEFAULT_DEFLATE_LEVEL);
      writer.setCodec(CodecFactory.deflateCodec(level));
View Full Code Here

      schema = ((GenericContainer) r).getSchema();
    } else {
      schema = new ReflectDataFactory().getReflectData().getSchema(r.getClass());
    }

    GenericDatumWriter genericDatumWriter = new GenericDatumWriter(schema);

    DataFileWriter dataFileWriter = new DataFileWriter(genericDatumWriter);
    dataFileWriter.create(schema, outputStream);

    for (Object record : genericRecords) {
View Full Code Here

      schema = ((GenericContainer) r).getSchema();
    } else {
      schema = new ReflectDataFactory().getReflectData().getSchema(r.getClass());
    }

    GenericDatumWriter genericDatumWriter = new GenericDatumWriter(schema);

    DataFileWriter dataFileWriter = new DataFileWriter(genericDatumWriter);
    dataFileWriter.create(schema, outputStream);

    for (Object record : genericRecords) {
View Full Code Here

    fileReader = new DataFileReader<GenericRecord>(in,
        new GenericDatumReader<GenericRecord>());
    fileReader.sync(pos);

    schema = fileReader.getSchema();
    datumWriter = new GenericDatumWriter(schema);
    out = new ByteArrayOutputStream();
    encoder = EncoderFactory.get().binaryEncoder(out, encoder);

    schemaHash = SchemaNormalization.parsingFingerprint("CRC-64-AVRO", schema);
    schemaHashString = Hex.encodeHexString(schemaHash);
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

  public static String toAvroJsonString(Object value, Schema schema) throws IOException {
    try {
      final ByteArrayOutputStream jsonOutputStream = new ByteArrayOutputStream();
      final JsonEncoder jsonEncoder =
          EncoderFactory.get().jsonEncoder(schema, jsonOutputStream);
      final GenericDatumWriter writer = new GenericDatumWriter(schema);
      writer.write(value, jsonEncoder);
      jsonEncoder.flush();
      return Bytes.toString(jsonOutputStream.toByteArray());
    } catch (IOException ioe) {
      throw new RuntimeException("Internal error: " + ioe);
    }
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.