### Question:
AbstractConnectorHandler implements RequestStreamHandler { @SuppressWarnings("UnstableApiUsage") void writeDataOut(OutputStream output, Typed dataOut, String ifNoneMatch) { try { byte[] bytes = dataOut == null ? null : dataOut.serialize().getBytes(); if (bytes == null) { return; } logger.info("{} - Writing data out for response with type: {}", streamId, dataOut.getClass().getSimpleName()); String hash = Hashing.murmur3_128().newHasher().putBytes(bytes).hash().toString(); byte[] etagBytes = ETAG_STRING.replace("_", hash).getBytes(); if (hash.equals(ifNoneMatch)) { bytes = new NotModifiedResponse().serialize().getBytes(); } try (ByteArrayOutputStream os = new ByteArrayOutputStream(bytes.length + etagBytes.length - 1)) { OutputStream targetOs = (!embedded && bytes.length > MIN_COMPRESS_SIZE ? Payload.gzip(os) : os); targetOs.write(bytes, 0, bytes.length - 1); targetOs.write(etagBytes); os.close(); targetOs.close(); bytes = os.toByteArray(); } if (!embedded && bytes.length > MAX_RESPONSE_SIZE) { bytes = relocationClient.relocate(streamId, bytes); } output.write(bytes); } catch (Exception e) { logger.error("{} - Unexpected exception occurred: {}\n{}", streamId, e.getMessage(), e.getStackTrace()); } } AbstractConnectorHandler(); @SuppressWarnings("unused") void setEmbedded(boolean embedded); @Override void handleRequest(InputStream input, OutputStream output, Context context); @SuppressWarnings("WeakerAccess")
  static final String RESPONSE; static final String ENV_DECRYPTOR; @SuppressWarnings("WeakerAccess")
  static int MAX_RESPONSE_SIZE; @SuppressWarnings("WeakerAccess")
  static int MIN_COMPRESS_SIZE; }### Answer:
@Test public void writeDataOut() throws ErrorResponseException { TestStorageConnector testStorageConnector = new TestStorageConnector(); HealthCheckEvent healthCheckEvent = new HealthCheckEvent().withStreamId("TEST_STREAM_ID"); ByteArrayOutputStream os = new ByteArrayOutputStream(); testStorageConnector.writeDataOut(os, healthCheckEvent, healthCheckEvent.getIfNoneMatch()); byte[] outputBytes = os.toByteArray(); Event<?> outputEvent = testStorageConnector.readEvent(new ByteArrayInputStream(outputBytes)); assertTrue(outputEvent instanceof HealthCheckEvent); }
@Test public void testWriteLargeDataOut() throws IOException { TestStorageConnector testStorageConnector = new TestStorageConnector(); FeatureCollection fc = generateRandomFeatures(417, 100); ByteArrayOutputStream os = new ByteArrayOutputStream(); testStorageConnector.writeDataOut(os, fc, null); byte[] outputBytes = os.toByteArray(); InputStream is = new ByteArrayInputStream(outputBytes); is = Payload.prepareInputStream(is); StringBuilder stringBuilder = new StringBuilder(); String line; try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is))) { while ((line = bufferedReader.readLine()) != null) { stringBuilder.append(line); } } FeatureCollection result = XyzSerializable.deserialize(stringBuilder.toString()); assertNotNull(result); }