@Test public void testSuccessWithInferredPrintableByteArray() throws DataConversionException, IOException { ObjectMapper objectMapper = new ObjectMapper(); byte[] record = "abrac\\adabra".getBytes(StandardCharsets.UTF_8); Metadata md = new Metadata(); md.getGlobalMetadata().setContentType("application/binary"); md.getGlobalMetadata().addTransferEncoding("base64"); RecordWithMetadataToEnvelopedRecordWithMetadata converter = new RecordWithMetadataToEnvelopedRecordWithMetadata(); Iterator<RecordWithMetadata<byte[]>> recordWithMetadataIterator = converter.convertRecord("", new RecordWithMetadata<>(record, md), null).iterator(); RecordWithMetadata recordWithMetadata = recordWithMetadataIterator.next(); JsonNode parsedElement = objectMapper.readValue((byte[]) recordWithMetadata.getRecord(), JsonNode.class); Assert.assertEquals(parsedElement.get("r").getTextValue(), new String(record, StandardCharsets.UTF_8)); }
@Override public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException { try { updateRecordMetadata(inputRecord); ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); writeHeaders(inputRecord, generator); writeRecord(inputRecord, generator); generator.writeEndObject(); } return Collections.singleton(new RecordWithMetadata<byte[]>(bOs.toByteArray(), inputRecord.getMetadata())); } catch (IOException e) { throw new DataConversionException(e); } }
RecordWithMetadataToEnvelopedRecordWithMetadata extends Converter<Object, String, RecordWithMetadata<?>, RecordWithMetadata<byte[]>> { @Override public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException { try { updateRecordMetadata(inputRecord); ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); writeHeaders(inputRecord, generator); writeRecord(inputRecord, generator); generator.writeEndObject(); } return Collections.singleton(new RecordWithMetadata<byte[]>(bOs.toByteArray(), inputRecord.getMetadata())); } catch (IOException e) { throw new DataConversionException(e); } } }
RecordWithMetadataToEnvelopedRecordWithMetadata extends Converter<Object, String, RecordWithMetadata<?>, RecordWithMetadata<byte[]>> { @Override public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException { try { updateRecordMetadata(inputRecord); ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); writeHeaders(inputRecord, generator); writeRecord(inputRecord, generator); generator.writeEndObject(); } return Collections.singleton(new RecordWithMetadata<byte[]>(bOs.toByteArray(), inputRecord.getMetadata())); } catch (IOException e) { throw new DataConversionException(e); } }  }
RecordWithMetadataToEnvelopedRecordWithMetadata extends Converter<Object, String, RecordWithMetadata<?>, RecordWithMetadata<byte[]>> { @Override public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException { try { updateRecordMetadata(inputRecord); ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); writeHeaders(inputRecord, generator); writeRecord(inputRecord, generator); generator.writeEndObject(); } return Collections.singleton(new RecordWithMetadata<byte[]>(bOs.toByteArray(), inputRecord.getMetadata())); } catch (IOException e) { throw new DataConversionException(e); } }  @Override String convertSchema(Object inputSchema, WorkUnitState workUnit); @Override Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord,
      WorkUnitState workUnit); }
RecordWithMetadataToEnvelopedRecordWithMetadata extends Converter<Object, String, RecordWithMetadata<?>, RecordWithMetadata<byte[]>> { @Override public Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord, WorkUnitState workUnit) throws DataConversionException { try { updateRecordMetadata(inputRecord); ByteArrayOutputStream bOs = new ByteArrayOutputStream(512); try (JsonGenerator generator = jsonFactory.createJsonGenerator(bOs, JsonEncoding.UTF8).setCodec(objectMapper)) { generator.writeStartObject(); writeHeaders(inputRecord, generator); writeRecord(inputRecord, generator); generator.writeEndObject(); } return Collections.singleton(new RecordWithMetadata<byte[]>(bOs.toByteArray(), inputRecord.getMetadata())); } catch (IOException e) { throw new DataConversionException(e); } }  @Override String convertSchema(Object inputSchema, WorkUnitState workUnit); @Override Iterable<RecordWithMetadata<byte[]>> convertRecord(String outputSchema, RecordWithMetadata<?> inputRecord,
      WorkUnitState workUnit);  }