Refine search
private static CompoundTag readCompound(ByteBuf buf, boolean network) { int idx = buf.readerIndex(); if (buf.readByte() == 0) { return null; } buf.readerIndex(idx); try (NbtInputStream str = new NbtInputStream(new ByteBufInputStream(buf), false)) { return str.readCompound( network ? new NbtReadLimiter(2097152L) : NbtReadLimiter.UNLIMITED); } catch (IOException e) { return null; } }
@Override public boolean readBoolean() throws IOException { checkAvailable(1); return read() != 0; }
@Override public int readUnsignedByte() throws IOException { return readByte() & 0xff; }
public static byte[] compressedFrame(ByteBuf uncompressed) { final ByteBuf compressed = Unpooled.buffer(); try (ByteBufInputStream is = new ByteBufInputStream(uncompressed, true); GZIPOutputStream os = new GZIPOutputStream(new ByteBufOutputStream(compressed))) { ByteStreams.copy(is, os); } catch (IOException e) { throw new UncheckedIOException(e); } final ByteBuf buf = Unpooled.buffer(); buf.writeByte(1); buf.writeInt(compressed.readableBytes()); buf.writeBytes(compressed); compressed.release(); final byte[] result = ByteBufUtil.getBytes(buf); buf.release(); return result; }
final ByteBufInputStream is = new ByteBufInputStream(buffer, buffer.readableBytes()); logger.debug(" post header read index {}", buffer.readerIndex()); final ByteBuf pBody = buffer.slice(buffer.readerIndex(), pBodyLength); buffer.skipBytes(pBodyLength); pBody.retain(1);
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception { final int length = in.readableBytes(); InputStream bbIn = null; ByteBufOutputStream bbOut = null; try { bbIn = new ByteBufInputStream(in); bbOut = new ByteBufOutputStream(out); bbOut.writeByte(properties); bbOut.writeInt(littleEndianDictionarySize); bbOut.writeLong(Long.reverseBytes(length)); encoder.code(bbIn, bbOut, -1, -1, null); } finally { if (bbIn != null) { bbIn.close(); } if (bbOut != null) { bbOut.close(); } } }
frame.readerIndex(frame.readableBytes()); head.setLastBinaryPacket(packet); ByteBufInputStream in = new ByteBufInputStream(frame); AckCallback<?> callback = ackManager.getCallback(head.getSessionId(), packet.getAckId()); AckArgs args = jsonSupport.readAckArgs(in, callback); ByteBufInputStream in = new ByteBufInputStream(frame); Event event = jsonSupport.readValue(packet.getNsp(), in, Event.class); packet.setName(event.getName());
private static void readSkipSlot(ByteBuf packet, int protocolVersion) { if ( (protocolVersion >= ProtocolConstants.MINECRAFT_1_13_2) ? packet.readBoolean() : packet.readShort() != -1 ) { if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13_2 ) { DefinedPacket.readVarInt( packet ); } packet.skipBytes( ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? 1 : 3 ); // byte vs byte, short int position = packet.readerIndex(); if ( packet.readByte() != 0 ) { packet.readerIndex( position ); try { new NBTInputStream( new ByteBufInputStream( packet ), false ).readTag(); } catch ( IOException ex ) { throw Throwables.propagate( ex ); } } } }
public O deserializeResponse(ByteBufOrStream message) throws IOException { InputStream messageStream = message.stream(); if (message.buf() != null) { try { switch (responseType) { case PROTOBUF: final PrototypeMarshaller<O> marshaller = (PrototypeMarshaller<O>) method.getResponseMarshaller(); // PrototypeMarshaller<I>.getMessagePrototype will always parse to I @SuppressWarnings("unchecked") final O msg = (O) deserializeProto(message.buf(), (Message) marshaller.getMessagePrototype()); return msg; default: // Fallback to using the method's stream marshaller. messageStream = new ByteBufInputStream(message.buf().retain(), true); break; } } finally { if (!unsafeWrapDeserializedBuffer) { message.buf().release(); } } } try (InputStream msg = messageStream) { return method.parseResponse(msg); } }
protected static void rewriteMetaVarInt(ByteBuf packet, int oldId, int newId, int metaIndex, int protocolVersion) int readerIndex = packet.readerIndex(); while ( ( index = packet.readUnsignedByte() ) != 0xFF ) if ( packet.readBoolean() ) try new NBTInputStream( new ByteBufInputStream( packet ), false ).readTag(); } catch ( IOException ex )
private static X509Certificate[] getCertificatesFromBuffers(ByteBuf[] certs) throws CertificateException { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate[] x509Certs = new X509Certificate[certs.length]; try { for (int i = 0; i < certs.length; i++) { InputStream is = new ByteBufInputStream(certs[i], false); try { x509Certs[i] = (X509Certificate) cf.generateCertificate(is); } finally { try { is.close(); } catch (IOException e) { // This is not expected to happen, but re-throw in case it does. throw new RuntimeException(e); } } } } finally { for (ByteBuf buf: certs) { buf.release(); } } return x509Certs; }
@Override public void channelRead(final ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { final HttpRequest req = (HttpRequest) msg; if (HttpUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE)); } isList.clear(); // clearing the content - possible leftover from previous request processing. final ContainerRequest requestContext = createContainerRequest(ctx, req); requestContext.setWriter(new NettyResponseWriter(ctx, req, container)); // must be like this, since there is a blocking read from Jersey container.getExecutorService().execute(new Runnable() { @Override public void run() { container.getApplicationHandler().handle(requestContext); } }); } if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; ByteBuf content = httpContent.content(); if (content.isReadable()) { isList.add(new ByteBufInputStream(content)); } if (msg instanceof LastHttpContent) { isList.add(NettyInputStream.END_OF_INPUT); } } }
@Override public InputStream asInputStream() { return new ByteBufInputStream(this.byteBuf); }
private Message deserializeProto(ByteBuf buf, Message prototype) throws IOException { if (GrpcSerializationFormats.isProto(serializationFormat)) { if (!buf.isReadable()) { return prototype.getDefaultInstanceForType(); stream = UnsafeByteOperations.unsafeWrap(buf.nioBuffer()).newCodedInput(); stream.enableAliasing(true); } else { stream = CodedInputStream.newInstance(buf.nioBuffer()); try (ByteBufInputStream is = new ByteBufInputStream(buf, /* releaseOnClose */ false)) { jsonMarshaller.mergeValue(is, builder);
@Override protected void readFromStream(ByteBuf data) { entityId = data.readInt(); try { packetData = CompressedStreamTools.readCompressed(new ByteBufInputStream(data)); } catch (IOException e) { e.printStackTrace(); } }
@Override public void close() throws IOException { super.close(); // let's make it actually repeatable content.readerIndex(0); } };
@Override public InputStream openInputStream() throws IOException { return new ByteBufInputStream(content.duplicate()); } };
@Override public InputStream getInput() throws IOException { responseContent.resetReaderIndex(); return new ByteBufInputStream(responseContent); } };
@Override public InputStream openStream() { return new ByteBufInputStream(byteBuf.slice()); }