Examples of DatumWriter


Examples of org.apache.avro.io.DatumWriter

    AvroType avroType = (AvroType)recordCollection.getPType();
    if (avroType == null) {
      throw new IllegalStateException("Can't write a non-typed Avro collection");
    }
    DatumWriter datumWriter = Avros.newWriter((AvroType)recordCollection.getPType());
    DataFileWriter dataFileWriter = new DataFileWriter(datumWriter);
    dataFileWriter.create(avroType.getSchema(), outputStream);

    for (Object record : recordCollection.materialize()) {
      dataFileWriter.append(avroType.getOutputMapFn().map(record));
View Full Code Here

Examples of org.apache.avro.io.DatumWriter

    AvroType avroType = (AvroType)recordCollection.getPType();
    if (avroType == null) {
      throw new IllegalStateException("Can't write a non-typed Avro collection");
    }
    DatumWriter datumWriter = Avros.newWriter((AvroType)recordCollection.getPType());
    DataFileWriter dataFileWriter = new DataFileWriter(datumWriter);
    dataFileWriter.create(avroType.getSchema(), outputStream);

    for (Object record : recordCollection.materialize()) {
      dataFileWriter.append(avroType.getOutputMapFn().map(record));
View Full Code Here

Examples of org.apache.avro.io.DatumWriter

    AvroType avroType = (AvroType)recordCollection.getPType();
    if (avroType == null) {
      throw new IllegalStateException("Can't write a non-typed Avro collection");
    }
    DatumWriter datumWriter = Avros.newWriter((AvroType)recordCollection.getPType());
    DataFileWriter dataFileWriter = new DataFileWriter(datumWriter);
    dataFileWriter.create(avroType.getSchema(), outputStream);

    for (Object record : recordCollection.materialize()) {
      dataFileWriter.append(avroType.getOutputMapFn().map(record));
View Full Code Here

Examples of org.apache.avro.io.DatumWriter

        } catch (UnsupportedEncodingException e) {
          throw new DatasetIOException("Failed to encode value: " + value, e);
        }
      default:
        // otherwise, encode as Avro binary and then base64
        DatumWriter writer = ReflectData.get().createDatumWriter(schema);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BinaryEncoder encoder = EncoderFactory.get().binaryEncoder(out, null);
        try {
          writer.write(value, encoder);
          encoder.flush();
        } catch (IOException e) {
          throw new DatasetIOException("Cannot encode Avro value", e);
        }
        return Base64.encodeBase64URLSafeString(out.toByteArray());
View Full Code Here

Examples of org.apache.avro.io.DatumWriter

  }

  /**
   */
  void emitData(File outData, Schema schema, int numRecords, Instantiator inster) throws IOException, InstantiationException {
    DatumWriter dout = new ReflectDatumWriter(schema);

    DataFileWriter out = new DataFileWriter(dout);
    out = out.create(schema, outData);
    try {
      for (int i = 0; i < numRecords; i++) {
View Full Code Here

Examples of org.apache.avro.io.DatumWriter

  /**
   */
  public void generateData(boolean encodeJson, File outfile, int numRecords) throws IOException {
    Schema schema = ReflectData.get().getSchema(TestRecord.class);
    DatumWriter dout = new ReflectDatumWriter(schema);

    if (encodeJson) {
      BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outfile));
      try {
        Encoder encoder = EncoderFactory.get().jsonEncoder(schema, (OutputStream) out);
        for (int i = 0; i < numRecords; i++) {
          TestRecord tr = new TestRecord();
          dout.write(tr, encoder);
        }
        encoder.flush();
      } finally {
        out.close();
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.