@Test public void testResponseToFrame() throws IOException { final long txnr = 123456789; final int code = RELPResponse.OK; final String message = "this is a message"; final String data = "this is some data"; final RELPResponse response = new RELPResponse(txnr, code, message, data); final RELPFrame frame = response.toFrame(StandardCharsets.UTF_8); Assert.assertEquals(txnr, frame.getTxnr()); Assert.assertEquals(RELPResponse.RSP_CMD, frame.getCommand()); final String result = new String(frame.getData(), StandardCharsets.UTF_8); final String expected = code + " " + message + "\n" + data; Assert.assertEquals(expected, result); Assert.assertEquals(expected.length(), frame.getDataLength()); }
public RELPFrame toFrame(final Charset charset) { final StringBuilder builder = new StringBuilder(); builder.append(code); if (message != null && !message.isEmpty()) { builder.append((char)RELPFrame.SEPARATOR); builder.append(message); } if (data != null) { builder.append((char)RELPFrame.DELIMITER); builder.append(data); } final byte[] data = builder.toString().getBytes(charset); return new RELPFrame.Builder() .txnr(txnr).command(RSP_CMD) .dataLength(data.length).data(data) .build(); }
RELPResponse { public RELPFrame toFrame(final Charset charset) { final StringBuilder builder = new StringBuilder(); builder.append(code); if (message != null && !message.isEmpty()) { builder.append((char)RELPFrame.SEPARATOR); builder.append(message); } if (data != null) { builder.append((char)RELPFrame.DELIMITER); builder.append(data); } final byte[] data = builder.toString().getBytes(charset); return new RELPFrame.Builder() .txnr(txnr).command(RSP_CMD) .dataLength(data.length).data(data) .build(); } }
RELPResponse { public RELPFrame toFrame(final Charset charset) { final StringBuilder builder = new StringBuilder(); builder.append(code); if (message != null && !message.isEmpty()) { builder.append((char)RELPFrame.SEPARATOR); builder.append(message); } if (data != null) { builder.append((char)RELPFrame.DELIMITER); builder.append(data); } final byte[] data = builder.toString().getBytes(charset); return new RELPFrame.Builder() .txnr(txnr).command(RSP_CMD) .dataLength(data.length).data(data) .build(); } RELPResponse(final long txnr, final int code);  RELPResponse(final long txnr, final int code, final String message, final String data); }
RELPResponse { public RELPFrame toFrame(final Charset charset) { final StringBuilder builder = new StringBuilder(); builder.append(code); if (message != null && !message.isEmpty()) { builder.append((char)RELPFrame.SEPARATOR); builder.append(message); } if (data != null) { builder.append((char)RELPFrame.DELIMITER); builder.append(data); } final byte[] data = builder.toString().getBytes(charset); return new RELPFrame.Builder() .txnr(txnr).command(RSP_CMD) .dataLength(data.length).data(data) .build(); } RELPResponse(final long txnr, final int code);  RELPResponse(final long txnr, final int code, final String message, final String data); RELPFrame toFrame(final Charset charset); static RELPResponse open(final long txnr, final Map<String,String> offers); static RELPResponse ok(final long txnr); static RELPResponse error(final long txnr); static Map<String,String> parseOffers(final byte[] data, final Charset charset); }
RELPResponse { public RELPFrame toFrame(final Charset charset) { final StringBuilder builder = new StringBuilder(); builder.append(code); if (message != null && !message.isEmpty()) { builder.append((char)RELPFrame.SEPARATOR); builder.append(message); } if (data != null) { builder.append((char)RELPFrame.DELIMITER); builder.append(data); } final byte[] data = builder.toString().getBytes(charset); return new RELPFrame.Builder() .txnr(txnr).command(RSP_CMD) .dataLength(data.length).data(data) .build(); } RELPResponse(final long txnr, final int code);  RELPResponse(final long txnr, final int code, final String message, final String data); RELPFrame toFrame(final Charset charset); static RELPResponse open(final long txnr, final Map<String,String> offers); static RELPResponse ok(final long txnr); static RELPResponse error(final long txnr); static Map<String,String> parseOffers(final byte[] data, final Charset charset); static final int OK; static final int ERROR; static final String RSP_CMD; }