@Test(expected = UncheckedIOException.class) public void testMergedPayloadInvalidPayload() throws Exception { byte[] payload = " {}".getBytes(Charsets.UTF_8); ObjectNode node = Json.createObjectNode(); NestedMetadata.mergedPayload(payload, Json.asBytes(node)); }
public static byte[] mergedPayload(byte[] payload, byte[] metadata) throws UncheckedIOException { if (payload.length < 2 || payload[0] != '{') { throw new UncheckedIOException(new IOException("invalid json object: must start with {")); } final ByteArrayOutputStream payloadWithMetadata = new ByteArrayOutputStream( metadata.length + payload.length); payloadWithMetadata.write(metadata, 0, metadata.length - 1); if (payload.length > 2) { payloadWithMetadata.write(','); } payloadWithMetadata.write(payload, 1, payload.length - 1); return payloadWithMetadata.toByteArray(); }
NestedMetadata { public static byte[] mergedPayload(byte[] payload, byte[] metadata) throws UncheckedIOException { if (payload.length < 2 || payload[0] != '{') { throw new UncheckedIOException(new IOException("invalid json object: must start with {")); } final ByteArrayOutputStream payloadWithMetadata = new ByteArrayOutputStream( metadata.length + payload.length); payloadWithMetadata.write(metadata, 0, metadata.length - 1); if (payload.length > 2) { payloadWithMetadata.write(','); } payloadWithMetadata.write(payload, 1, payload.length - 1); return payloadWithMetadata.toByteArray(); } }
NestedMetadata { public static byte[] mergedPayload(byte[] payload, byte[] metadata) throws UncheckedIOException { if (payload.length < 2 || payload[0] != '{') { throw new UncheckedIOException(new IOException("invalid json object: must start with {")); } final ByteArrayOutputStream payloadWithMetadata = new ByteArrayOutputStream( metadata.length + payload.length); payloadWithMetadata.write(metadata, 0, metadata.length - 1); if (payload.length > 2) { payloadWithMetadata.write(','); } payloadWithMetadata.write(payload, 1, payload.length - 1); return payloadWithMetadata.toByteArray(); } private  NestedMetadata(); }
NestedMetadata { public static byte[] mergedPayload(byte[] payload, byte[] metadata) throws UncheckedIOException { if (payload.length < 2 || payload[0] != '{') { throw new UncheckedIOException(new IOException("invalid json object: must start with {")); } final ByteArrayOutputStream payloadWithMetadata = new ByteArrayOutputStream( metadata.length + payload.length); payloadWithMetadata.write(metadata, 0, metadata.length - 1); if (payload.length > 2) { payloadWithMetadata.write(','); } payloadWithMetadata.write(payload, 1, payload.length - 1); return payloadWithMetadata.toByteArray(); } private  NestedMetadata(); static byte[] mergedPayload(byte[] payload, byte[] metadata); static ObjectNode attributesToMetadataPayload(Map<String, String> attributes); static void stripPayloadMetadataToAttributes(Map<String, String> attributes,
      ObjectNode payload); }
NestedMetadata { public static byte[] mergedPayload(byte[] payload, byte[] metadata) throws UncheckedIOException { if (payload.length < 2 || payload[0] != '{') { throw new UncheckedIOException(new IOException("invalid json object: must start with {")); } final ByteArrayOutputStream payloadWithMetadata = new ByteArrayOutputStream( metadata.length + payload.length); payloadWithMetadata.write(metadata, 0, metadata.length - 1); if (payload.length > 2) { payloadWithMetadata.write(','); } payloadWithMetadata.write(payload, 1, payload.length - 1); return payloadWithMetadata.toByteArray(); } private  NestedMetadata(); static byte[] mergedPayload(byte[] payload, byte[] metadata); static ObjectNode attributesToMetadataPayload(Map<String, String> attributes); static void stripPayloadMetadataToAttributes(Map<String, String> attributes,
      ObjectNode payload);  }