Schema schema = avroDatastream.getSchema();
DatumWriter<Object> avroWriter = new GenericDatumWriter<Object>(schema);
JsonGenerator g = new JsonFactory().createJsonGenerator(outputStream, JsonEncoding.UTF8);
g.useDefaultPrettyPrinter();
Encoder encoder = new JsonEncoder(schema, g);
int lineno = 1; // line number starts from 1
while(avroDatastream.hasNext() && lineno <= endLine) {
Object datum = avroDatastream.next();
if(lineno >= startLine) {
String record = "\n\n Record " + lineno + ":\n";
outputStream.write(record.getBytes("UTF-8"));
avroWriter.write(datum, encoder);
encoder.flush();
}
lineno++;
}
} catch(IOException e) {
outputStream.write(("Error in display avro file: " + e.getLocalizedMessage()).getBytes("UTF-8"));