@Test public void testEncodingNoData() throws IOException { final RELPFrame frame = new RELPFrame.Builder() .txnr(1) .command("rsp") .dataLength(0) .data(new byte[0]) .build(); final RELPEncoder encoder = new RELPEncoder(StandardCharsets.UTF_8); final byte[] result = encoder.encode(frame); final String expected = "1 rsp 0\n"; Assert.assertEquals(expected, new String(result, StandardCharsets.UTF_8)); }
public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } RELPEncoder(final Charset charset); }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } RELPEncoder(final Charset charset); Charset getCharset(); byte[] encode(final RELPFrame frame); }
RELPEncoder { public byte[] encode(final RELPFrame frame) { final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); byte[] txnr = String.format("%s", frame.getTxnr()).getBytes(charset); buffer.write(txnr, 0, txnr.length); buffer.write(RELPFrame.SEPARATOR); byte[] command = frame.getCommand().getBytes(charset); buffer.write(command, 0, command.length); buffer.write(RELPFrame.SEPARATOR); byte[] dataLength = String.format("%s", frame.getDataLength()).getBytes(charset); buffer.write(dataLength, 0, dataLength.length); if (frame.getDataLength() > 0) { buffer.write(RELPFrame.SEPARATOR); buffer.write(frame.getData(), 0, frame.getDataLength()); } buffer.write(RELPFrame.DELIMITER); return buffer.toByteArray(); } RELPEncoder(final Charset charset); Charset getCharset(); byte[] encode(final RELPFrame frame);  }