List of usage examples for io.netty.buffer ByteBufInputStream ByteBufInputStream
public ByteBufInputStream(ByteBuf buffer)
From source file:org.restexpress.serialization.xml.XstreamXmlProcessor.java
License:Apache License
@Override @SuppressWarnings("unchecked") public <T> T deserialize(ByteBuf xml, Class<T> type) { if (!xml.isReadable()) return null; return (T) xstream.fromXML(new ByteBufInputStream(xml)); }
From source file:org.restnext.server.ServerHandler.java
License:Apache License
private void write(ChannelHandlerContext ctx, Response response, boolean keepAlive) { HttpVersion version = fromVersion(response.getVersion()); HttpResponseStatus status = fromStatus(response.getStatus()); ByteBuf content = response.hasContent() ? Unpooled.wrappedBuffer(response.getContent()) : Unpooled.EMPTY_BUFFER;// w w w .j a v a2 s .c o m boolean chunked = response.isChunked(); // create netty response HttpResponse resp; HttpChunkedInput chunkedResp = chunked ? new HttpChunkedInput(new ChunkedStream(new ByteBufInputStream(content), response.getChunkSize())) : null; if (chunked) { resp = new DefaultHttpResponse(version, status); HttpUtil.setTransferEncodingChunked(resp, true); createOutboutHeaders(resp, response, keepAlive); // Write the initial line and the header. ctx.write(resp); } else { resp = new DefaultFullHttpResponse(version, status, content); createOutboutHeaders(resp, response, keepAlive); } if (keepAlive) { if (chunked) { ctx.write(chunkedResp); } else { HttpUtil.setContentLength(resp, content.readableBytes()); ctx.write(resp); } } else { ChannelFuture channelFuture; if (chunked) { channelFuture = ctx.writeAndFlush(chunkedResp); } else { channelFuture = ctx.writeAndFlush(resp); } // Close the connection after the write operation is done if necessary. channelFuture.addListener(ChannelFutureListener.CLOSE); } }
From source file:org.spongepowered.clean.util.ByteBufUtil.java
License:MIT License
public static DataContainer readNBT(ByteBuf buffer) { DataInputStream in = new DataInputStream(new ByteBufInputStream(buffer)); try {/*from w w w.j a v a 2s .c o m*/ return NbtIO.read(in); } catch (IOException e) { SGame.getLogger().error("Error reading nbt from network stream"); e.printStackTrace(); } return null; }
From source file:org.springframework.core.io.buffer.NettyDataBuffer.java
License:Apache License
@Override public InputStream asInputStream() { return new ByteBufInputStream(this.byteBuf); }
From source file:org.springframework.http.client.Netty4ClientHttpResponse.java
License:Apache License
public Netty4ClientHttpResponse(ChannelHandlerContext context, FullHttpResponse nettyResponse) { Assert.notNull(context, "ChannelHandlerContext must not be null"); Assert.notNull(nettyResponse, "FullHttpResponse must not be null"); this.context = context; this.nettyResponse = nettyResponse; this.body = new ByteBufInputStream(this.nettyResponse.content()); this.nettyResponse.retain(); }
From source file:org.teiid.transport.ObjectDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception { if (result == null) { ByteBuf frame = null;/*w w w.j a v a 2 s . co m*/ try { frame = (ByteBuf) super.decode(ctx, buffer); } catch (TooLongFrameException e) { throw new IOException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40166), e); } if (frame == null) { return null; } CompactObjectInputStream cois = new CompactObjectInputStream(new ByteBufInputStream(frame), classLoader); result = cois.readObject(); streams = ExternalizeUtil.readList(cois, StreamFactoryReference.class); streamIndex = 0; } while (streamIndex < streams.size()) { //read the new chunk size if (streamDataToRead == -1) { if (buffer.readableBytes() < 2) { return null; } streamDataToRead = buffer.readUnsignedShort(); } if (stream == null) { store = storageManager.createFileStore("temp-stream"); //$NON-NLS-1$ StreamFactoryReference sfr = streams.get(streamIndex); sfr.setStreamFactory(new FileStoreInputStreamFactory(store, Streamable.ENCODING)); this.stream = new BufferedOutputStream(store.createOutputStream()); } //end of stream if (streamDataToRead == 0) { stream.close(); stream = null; streamIndex++; streamDataToRead = -1; continue; } if (store.getLength() + streamDataToRead > maxLobSize) { if (error == null) { error = new StreamCorruptedException("lob too big: " + (store.getLength() + streamDataToRead) //$NON-NLS-1$ + " (max: " + maxLobSize + ')'); //$NON-NLS-1$ } } int toRead = Math.min(buffer.readableBytes(), streamDataToRead); if (toRead == 0) { return null; } if (error == null) { buffer.readBytes(this.stream, toRead); } else { buffer.skipBytes(toRead); } streamDataToRead -= toRead; if (streamDataToRead == 0) { //get the next chunk streamDataToRead = -1; } } Object toReturn = result; result = null; streams = null; stream = null; store = null; if (error != null) { StreamCorruptedException sce = error; error = null; throw sce; } return toReturn; }
From source file:org.tinygroup.nettyremote.codec.serialization.HessianDecoder.java
License:GNU General Public License
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; }//from ww w . j ava 2 s . co m SerializerFactory serializerFactory = new SerializerFactory(); serializerFactory.addFactory(new BigDecimalSerializerFactory()); HessianInput hin = new HessianInput(new ByteBufInputStream(frame)); hin.setSerializerFactory(serializerFactory); return hin.readObject(); // ObjectInputStream is = new CompactObjectInputStream(new // ByteBufInputStream(frame), classResolver); // Object result = is.readObject(); // is.close(); // return result; }
From source file:org.wso2.carbon.gateway.internal.mediation.camel.CarbonMessageTypeConverter.java
License:Open Source License
private InputStream toInputStream(ByteBuf buffer, Exchange exchange) { return new ByteBufInputStream(buffer); }
From source file:ratpack.http.internal.ByteBufBackedRequestBody.java
License:Apache License
@Override public InputStream getInputStream() { return new ByteBufInputStream(byteBuf); }
From source file:ratpack.session.internal.DefaultSession.java
License:Apache License
private void hydrate(ByteBuf bytes) throws Exception { if (bytes.readableBytes() > 0) { try {/* w w w .j a va2 s. c o m*/ SerializedForm deserialized = defaultSerializer.deserialize(SerializedForm.class, new ByteBufInputStream(bytes)); if (deserialized == null) { this.entries = new HashMap<>(); } else { entries = deserialized.entries; } } catch (Exception e) { LOGGER.warn("Exception thrown deserializing session " + getId() + " with serializer " + defaultSerializer + " (session will be discarded)", e); this.entries = new HashMap<>(); markDirty(); } } else { this.entries = new HashMap<>(); } }