@Test public void testAvroNativeJson() throws IOException { AvroNativeFileOutputFormat format = new AvroNativeFileOutputFormat(); ByteArrayOutputStream sos = new ByteArrayOutputStream(); format.format(sos, e); format.close(); byte[] bytes = sos.toByteArray(); ReflectData reflectData = ReflectData.get(); Schema schema = reflectData.getSchema(EventImpl.class); ReflectDatumReader<EventImpl> dr = new ReflectDatumReader<EventImpl>(schema); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); DataFileStream<EventImpl> dec = new DataFileStream<EventImpl>(bais, dr); Event er = dec.next(); assertEquals(e.getHost(), er.getHost()); assertEquals(e.getNanos(), er.getNanos()); assertEquals(e.getPriority(), er.getPriority()); assertTrue(Arrays.equals(e.getBody(), er.getBody())); }
@Override public void append(Event e) throws IOException, InterruptedException { String helloWorldBody = "Hello World! -- " + new String(e.getBody()); // make a copy of the event, but with the new body string. EventImpl e2 = new EventImpl( helloWorldBody.getBytes(), e.getTimestamp(), e.getPriority(), e.getNanos(), e.getHost(), e.getAttrs()); super.append(e2); }