/** * Write the supplied array to bytes using UTF-8. * @param array the array to be written; may not be null * @return the bytes containing the output JSON-formatted array; never null */ default byte[] writeAsBytes( Array array ) { try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { write(array, stream); return stream.toByteArray(); } catch ( IOException e ) { // This really should never happen ... e.printStackTrace(); return new byte[]{}; } }
@Override public byte[] serialize(String topic, Array data) { return ARRAY_WRITER.writeAsBytes(data); }
protected void appendCommand(Path results, Document command) throws IOException { assertThat(command).isNotNull(); assertThat(Files.exists(results)).isTrue(); Array arrayOfDocuments = readResults(results.toFile()); arrayOfDocuments.add(command); try (OutputStream stream = new FileOutputStream(results.toFile())) { ArrayWriter.prettyWriter().write(arrayOfDocuments, stream); } if (Testing.Debug.isEnabled()) { String content = IoUtil.read(results.toFile()); Testing.debug("expected results file '" + results + "' after appending command:"); Testing.debug(content); } }
protected void appendCommand(Path results, Document command) throws IOException { assertThat(command).isNotNull(); assertThat(Files.exists(results)).isTrue(); Array arrayOfDocuments = readResults(results.toFile()); arrayOfDocuments.add(command); try (OutputStream stream = new FileOutputStream(results.toFile())) { ArrayWriter.prettyWriter().write(arrayOfDocuments, stream); } if (Testing.Debug.isEnabled()) { String content = IoUtil.read(results.toFile()); Testing.debug("expected results file '" + results + "' after appending command:"); Testing.debug(content); } }
/** * Write the supplied array to bytes using UTF-8. * @param array the array to be written; may not be null * @return the bytes containing the output JSON-formatted array; never null */ default byte[] writeAsBytes( Array array ) { try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { write(array, stream); return stream.toByteArray(); } catch ( IOException e ) { // This really should never happen ... e.printStackTrace(); return new byte[]{}; } }
@Override public byte[] serialize(String topic, Array data) { return ARRAY_WRITER.writeAsBytes(data); }