@Test public void testToString() throws Exception { String str = TestUtils.randomUnicodeString(100); Buffer buff = new Buffer(str); assertEquals(str, buff.toString()); // TODO toString with encoding }
@Test public void testAppendString1() throws Exception { String str = TestUtils.randomUnicodeString(100); byte[] sb = str.getBytes("UTF-8"); Buffer b = new Buffer(); b.appendString(str); assertEquals(b.length(), sb.length); assertTrue(str.equals(b.toString("UTF-8"))); }
@Test public void testCreateBuffers() throws Exception { Buffer buff = new Buffer(1000); assertEquals(0, buff.length()); String str = TestUtils.randomUnicodeString(100); buff = new Buffer(str); assertEquals(buff.length(), str.getBytes("UTF-8").length); assertEquals(str, buff.toString()); // TODO create with string with encoding byte[] bytes = TestUtils.generateRandomByteArray(100); buff = new Buffer(bytes); assertEquals(buff.length(), bytes.length); assertTrue(TestUtils.buffersEqual(new Buffer(bytes), new Buffer(buff.getBytes()))); }
private void parseConfigAndStart(final Buffer buffer) { final JsonObject config = new JsonObject(buffer.toString()); container.deployModule( METRICS_MODULE, config.getObject("metrics"), ar -> { if (ar.succeeded()) { container .logger() .fatal("Deployed: " + METRICS_MODULE + " with id: " + ar.result(), ar.cause()); start(config); } else { container.logger().fatal("Failed to deploy: " + METRICS_MODULE, ar.cause()); } }); }
private void handleSocketData( SockJSSocket sock, Buffer data, Map<String, Handler<Message>> handlers) { JsonObject msg = new JsonObject(data.toString()); String type = getMandatoryString(msg, "type"); String address = getMandatoryString(msg, "address"); switch (type) { case "send": internalHandleSendOrPub(sock, true, msg, address); break; case "publish": internalHandleSendOrPub(sock, false, msg, address); break; case "register": internalHandleRegister(sock, address, handlers); break; case "unregister": internalHandleUnregister(sock, address, handlers); break; default: throw new IllegalStateException("Invalid type: " + type); } }
public void handle(Buffer data) { ws.writeTextFrame(data.toString()); }