List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer()
From source file:com.github.subalakr.yasjl.AutoBenchRowPerf.java
License:Apache License
private void parseResults(String file, String path) throws Exception { String response = getResource(file); StringBuilder sb = new StringBuilder(); sb.append("size: " + humanReadableByteCount(response.length(), true) + ",\t\t"); sb.append("level-depth: " + path.split("/").length + ",\t\t"); sb.append("time: "); JsonPointer[] jsonPointers = { new JsonPointer(path, new JsonPointerCB1() { public void call(ByteBuf buf) { buf.release();//from ww w. j a v a 2 s . c om } }) }; ByteBuf buf = Unpooled.buffer(); parser.initialize(buf, jsonPointers); buf.writeBytes(response.getBytes()); long start = System.currentTimeMillis(); parser.parse(); long end = System.currentTimeMillis(); sb.append((end - start) + "ms"); System.out.println(sb.toString()); }
From source file:com.github.subalakr.yasjl.Bench.java
License:Apache License
public void run() throws Exception { for (int i = 0; i < iterations; i++) { ByteBuf inBuf = Unpooled.buffer(); JsonPointer[] jsonPointers = { new JsonPointer("/metrics/resultCount", new JsonPointerCB1() { public void call(ByteBuf buf) { buf.release();// ww w. jav a 2s . c o m } }), new JsonPointer("/metrics/warningCount", new JsonPointerCB1() { public void call(ByteBuf buf) { buf.release(); } }), new JsonPointer("/metrics/errorCount", new JsonPointerCB1() { public void call(ByteBuf buf) { buf.release(); } }), new JsonPointer("/results/-", new JsonPointerCB1() { public void call(ByteBuf buf) { rowsEmitted.getAndIncrement(); buf.release(); } }), new JsonPointer("/errors/-", new JsonPointerCB1() { public void call(ByteBuf buf) { buf.release(); } }), new JsonPointer("/warnings/-", new JsonPointerCB1() { public void call(ByteBuf buf) { buf.release(); } }), }; parser.initialize(inBuf, jsonPointers); inBuf.writeBytes(inJson.getBytes()); long start = System.currentTimeMillis(); parser.parse(); long currentRun = System.currentTimeMillis() - start; totalDuration += currentRun; totalBytesRead += inJsonSz; inBuf.discardReadBytes(); inBuf.release(); } }
From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpDownloadHandlerTest.java
License:Open Source License
private void downloadShouldWork(boolean casDownload, EmbeddedChannel ch) throws IOException { ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream()); DownloadCommand cmd = new DownloadCommand(CACHE_URI, casDownload, "abcdef", out); ChannelPromise writePromise = ch.newPromise(); ch.writeOneOutbound(cmd, writePromise); HttpRequest request = ch.readOutbound(); assertThat(request.method()).isEqualTo(HttpMethod.GET); assertThat(request.headers().get(HttpHeaderNames.HOST)) .isEqualTo(CACHE_URI.getHost() + ":" + CACHE_URI.getPort()); if (casDownload) { assertThat(request.uri()).isEqualTo("/cache-bucket/cas/abcdef"); } else {/*from w w w. jav a 2 s . co m*/ assertThat(request.uri()).isEqualTo("/cache-bucket/ac/abcdef"); } assertThat(writePromise.isDone()).isFalse(); HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK); response.headers().set(HttpHeaders.CONTENT_LENGTH, 5); response.headers().set(HttpHeaders.CONNECTION, HttpHeaderValues.KEEP_ALIVE); ch.writeInbound(response); ByteBuf content = Unpooled.buffer(); content.writeBytes(new byte[] { 1, 2, 3, 4, 5 }); ch.writeInbound(new DefaultLastHttpContent(content)); assertThat(writePromise.isDone()).isTrue(); assertThat(out.toByteArray()).isEqualTo(new byte[] { 1, 2, 3, 4, 5 }); verify(out, never()).close(); assertThat(ch.isActive()).isTrue(); }
From source file:com.jfastnet.peers.netty.KryoNettyPeer.java
License:Apache License
public ByteBuf getByteBuf(Message message) { ByteBuf data = Unpooled.buffer(); config.serialiser.serialiseWithStream(message, new ByteBufOutputStream(data)); int length = data.writerIndex(); log.trace("Message size of {} is {}", message, length); // if (length > config.maximumUdpPacketSize) { // log.error("Message {} exceeds maximum size of {}! Size is {} byte", new Object[]{message, config.maximumUdpPacketSize, length}); // return null; // }//from w w w . ja v a 2s .c o m return data.retain(); }
From source file:com.kaijin.AdvPowerMan.tileentities.TECommon.java
License:Open Source License
/** * Does the bulk of the work of creating the description packet. Performs a * callback to addUniqueDescriptionData. That method must be overridden. * We're not overriding getDescriptionPacket in this class because not all * of our tile entities need such packets. * /* ww w . j a v a 2 s .co m*/ * @return The completed Packet250. */ protected Packet createDescPacket() { // if (ChargingBench.isDebugging) // System.out.println("TE getAuxillaryInfoPacket()"); // ByteArrayOutputStream bytes = new ByteArrayOutputStream(); // DataOutputStream data = new DataOutputStream(bytes); ByteBuf data = Unpooled.buffer(); try { data.writeInt(0); data.writeInt(xCoord); data.writeInt(yCoord); data.writeInt(zCoord); addUniqueDescriptionData(data); } catch (IOException e) { FMLLog.getLogger().info("[AdvancedPowerManagement] " + "Server failed to create description packet. (Details: " + e.toString() + ")"); } // ChannelHandler.instance.sendToPlayer(new // AdvPacket(bytes.toByteArray()), player); return new S3FPacketCustomPayload("Test", data); }
From source file:com.kanbekotori.keycraft.network.RewriteNetwork.java
License:Open Source License
public static FMLProxyPacket createSyncAuroraPointPacket(EntityPlayer player) { ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer()); FMLProxyPacket packet = null;/*from www. j ava 2s . c om*/ try { stream.writeInt(SYNC_AURORA_POINT_CODE); stream.writeInt(RewriteHelper.getAuroraPoint(player)); packet = new FMLProxyPacket(stream.buffer(), REWRITE_CHANNEL); stream.close(); } catch (IOException e) { e.printStackTrace(); } return packet; }
From source file:com.kanbekotori.keycraft.network.RewriteNetwork.java
License:Open Source License
public static FMLProxyPacket createSyncSkillPacket(EntityPlayer player) { ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer()); FMLProxyPacket packet = null;/*from w w w .j a v a 2 s . c om*/ try { stream.writeInt(SYNC_SKILL_CODE); for (RewriteHelper.Skill i : RewriteHelper.SKILLS) { stream.writeBoolean(RewriteHelper.hasSkill(player, i.id)); } packet = new FMLProxyPacket(stream.buffer(), REWRITE_CHANNEL); stream.close(); } catch (IOException e) { e.printStackTrace(); } return packet; }
From source file:com.kanbekotori.keycraft.network.RewriteNetwork.java
License:Open Source License
public static FMLProxyPacket createLearnSkillPacket(int skillId) { ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer()); FMLProxyPacket packet = null;/* ww w. jav a2 s .co m*/ try { stream.writeInt(LEARN_SKILL_CODE); stream.writeInt(skillId); packet = new FMLProxyPacket(stream.buffer(), REWRITE_CHANNEL); stream.close(); } catch (IOException e) { e.printStackTrace(); } return packet; }
From source file:com.kanbekotori.keycraft.network.RewriteNetwork.java
License:Open Source License
public static FMLProxyPacket createUseSkillPacket() { ByteBufOutputStream stream = new ByteBufOutputStream(Unpooled.buffer()); FMLProxyPacket packet = null;/*from ww w . j a va2s . c o m*/ try { stream.writeInt(USE_SKILL_CODE); packet = new FMLProxyPacket(stream.buffer(), REWRITE_CHANNEL); stream.close(); } catch (IOException e) { e.printStackTrace(); } return packet; }
From source file:com.kixeye.kixmpp.p2p.serialization.SerializationTest.java
License:Apache License
@Test public void envelopSerializeTest() throws IOException { MessageRegistry messageRegistry = new MessageRegistry(); messageRegistry.addCustomMessage(1, Envelop.class); messageRegistry.addCustomMessage(2, DataObject.class); NodeId nid = new NodeId(); DataObject message = new DataObject(42, "Testing..1..2..3"); Envelop envelop = new Envelop(nid, message); ByteBuf buf = ProtostuffEncoder.serializeToByteBuf(messageRegistry, Unpooled.buffer(), envelop); Envelop result = (Envelop) ProtostuffDecoder.deserializeFromByteBuf(messageRegistry, buf); Assert.assertEquals(nid, result.getSenderId()); Assert.assertEquals(message, result.getMessage()); }