Search in sources :

Example 1 with DatumReader

use of org.apache.avro.io.DatumReader in project trevni by cutting.

the class TestCases method fromJson.

private List<Object> fromJson(Schema schema, File file) throws Exception {
    InputStream in = new FileInputStream(file);
    List<Object> data = new ArrayList<Object>();
    try {
        DatumReader reader = new GenericDatumReader(schema);
        Decoder decoder = DecoderFactory.get().jsonDecoder(schema, in);
        while (true) data.add(reader.read(null, decoder));
    } catch (EOFException e) {
    } finally {
        in.close();
    }
    return data;
}
Also used : DatumReader(org.apache.avro.io.DatumReader) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GenericDatumReader(org.apache.avro.generic.GenericDatumReader) ArrayList(java.util.ArrayList) EOFException(java.io.EOFException) Decoder(org.apache.avro.io.Decoder) FileInputStream(java.io.FileInputStream)

Aggregations

EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 GenericDatumReader (org.apache.avro.generic.GenericDatumReader)1 DatumReader (org.apache.avro.io.DatumReader)1 Decoder (org.apache.avro.io.Decoder)1