List of usage examples for io.netty.buffer ByteBufOutputStream ByteBufOutputStream
public ByteBufOutputStream(ByteBuf buffer)
From source file:org.opendaylight.netconf.nettyutil.handler.NetconfMessageToXMLEncoder.java
License:Open Source License
@Override @VisibleForTesting// w w w.java2 s. c om public void encode(final ChannelHandlerContext ctx, final NetconfMessage msg, final ByteBuf out) throws IOException, TransformerException { LOG.trace("Sent to encode : {}", msg); if (clientId.isPresent()) { Comment comment = msg.getDocument().createComment("clientId:" + clientId.get()); msg.getDocument().appendChild(comment); } try (OutputStream os = new ByteBufOutputStream(out)) { // Wrap OutputStreamWriter with BufferedWriter as suggested in javadoc for OutputStreamWriter // Using custom BufferedWriter that does not provide newLine method as performance improvement // see javadoc for BufferedWriter StreamResult result = new StreamResult(new BufferedWriter(new OutputStreamWriter(os))); DOMSource source = new DOMSource(msg.getDocument()); ThreadLocalTransformers.getPrettyTransformer().transform(source, result); } }
From source file:org.quartzpowered.protocol.codec.v1_8_R1.play.client.UpdateEntityNbtCodec.java
License:Open Source License
@Override public void encode(Buffer buffer, UpdateEntityNbtPacket packet) { buffer.writeVarInt(packet.getEntityId()); try {/* w w w. j a v a2 s . com*/ NBTOutputStream nos = new NBTOutputStream(new ByteBufOutputStream(buffer)); nos.writeTag(packet.getTag()); nos.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.robotbrains.support.web.server.netty.NettyHttpResponse.java
License:Apache License
@Override public OutputStream getOutputStream() { if (outputStream == null) { outputStream = new ByteBufOutputStream(channelBuffer); }/*from w w w . j av a2 s . c om*/ return outputStream; }
From source file:org.spongepowered.clean.util.ByteBufUtil.java
License:MIT License
public static void writeNBT(ByteBuf buffer, DataView data) { DataOutputStream out = new DataOutputStream(new ByteBufOutputStream(buffer)); try {/*from w ww . j a v a 2 s .c om*/ NbtIO.write(data, out); } catch (IOException e) { SGame.getLogger().error("Error writing nbt to network stream"); e.printStackTrace(); } }
From source file:org.springframework.core.io.buffer.NettyDataBuffer.java
License:Apache License
@Override public OutputStream asOutputStream() { return new ByteBufOutputStream(this.byteBuf); }
From source file:org.springframework.http.client.Netty4ClientHttpRequest.java
License:Apache License
public Netty4ClientHttpRequest(Bootstrap bootstrap, URI uri, HttpMethod method, int maxRequestSize) { this.bootstrap = bootstrap; this.uri = uri; this.method = method; this.body = new ByteBufOutputStream(Unpooled.buffer(maxRequestSize)); }
From source file:org.teiid.transport.ObjectEncoder.java
License:Apache License
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ByteBuf out = allocateBuffer(ctx, this.estimatedLength, this.preferDirect); int startIdx = out.writerIndex(); ByteBufOutputStream bout = new ByteBufOutputStream(out); bout.write(LENGTH_PLACEHOLDER);//from w w w. j a v a 2 s. c om final CompactObjectOutputStream oout = new CompactObjectOutputStream(bout); try { oout.writeObject(msg); ExternalizeUtil.writeCollection(oout, oout.getReferences()); oout.flush(); oout.close(); int endIdx = out.writerIndex(); out.setInt(startIdx, endIdx - startIdx - 4); if (out.isReadable()) { ctx.write(out, promise); for (InputStream is : oout.getStreams()) { ctx.write(new AnonymousChunkedStream(new BufferedInputStream(is, CHUNK_SIZE)), promise); } } else { out.release(); ctx.write(Unpooled.EMPTY_BUFFER, promise); } ctx.flush(); out = null; } catch (Throwable t) { throw new FailedWriteException(msg, t); } finally { if (out != null) { out.release(); } } }
From source file:org.teiid.transport.PgBackendProtocol.java
License:Open Source License
private void initBuffer(int estimatedLength) { this.dataOut = Unpooled.buffer(estimatedLength).order(ByteOrder.BIG_ENDIAN); ByteBufOutputStream cbos = new ByteBufOutputStream(this.dataOut); this.writer = new OutputStreamWriter(cbos, this.encoding); }
From source file:org.tinygroup.nettyremote.codec.serialization.HessianEncoder.java
License:GNU General Public License
@Override protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { int startIdx = out.writerIndex(); ByteBufOutputStream bout = new ByteBufOutputStream(out); bout.write(LENGTH_PLACEHOLDER);//w w w .ja v a2 s . co m // ObjectOutputStream oout = new CompactObjectOutputStream(bout); // oout.writeObject(msg); // oout.flush(); // oout.close(); SerializerFactory serializerFactory = new SerializerFactory(); serializerFactory.addFactory(new BigDecimalSerializerFactory()); HessianOutput hout = new HessianOutput(bout); hout.setSerializerFactory(serializerFactory); hout.writeObject(msg); int endIdx = out.writerIndex(); out.setInt(startIdx, endIdx - startIdx - 4); }
From source file:org.wso2.carbon.mss.internal.router.AbstractHttpResponder.java
License:Open Source License
@Override public void sendJson(HttpResponseStatus status, Object object, Type type, Gson gson) { try {/* w w w . jav a2 s. c o m*/ ByteBuf channelBuffer = Unpooled.buffer(); try (JsonWriter jsonWriter = new JsonWriter( new OutputStreamWriter(new ByteBufOutputStream(channelBuffer), Charsets.UTF_8))) { gson.toJson(object, type, jsonWriter); } sendContent(status, channelBuffer, "application/json", ImmutableMultimap.<String, String>of()); } catch (IOException e) { throw Throwables.propagate(e); } }