當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBufInputStream類代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBufInputStream的典型用法代碼示例。如果您正苦於以下問題:Java ByteBufInputStream類的具體用法?Java ByteBufInputStream怎麽用?Java ByteBufInputStream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ByteBufInputStream類屬於io.netty.buffer包,在下文中一共展示了ByteBufInputStream類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decode

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    Kryo kryo = null;
    try {
        kryo = kryoPool.get();
        return kryo.readClassAndObject(new Input(new ByteBufInputStream(buf)));
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new RedissonKryoCodecException(e);
    } finally {
        if (kryo != null) {
            kryoPool.yield(kryo);
        }
    }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:18,代碼來源:KryoCodec.java

示例2: readNBTTagCompoundFromBuffer

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
/**
 * Reads a compressed NBTTagCompound from this buffer
 */
public NBTTagCompound readNBTTagCompoundFromBuffer() throws IOException
{
    int i = this.readerIndex();
    byte b0 = this.readByte();

    if (b0 == 0)
    {
        return null;
    }
    else
    {
        this.readerIndex(i);
        return CompressedStreamTools.read(new ByteBufInputStream(this), new NBTSizeTracker(2097152L));
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:19,代碼來源:PacketBuffer.java

示例3: processRequest

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
private HttpResponse processRequest(FullHttpRequest request) throws JsonProcessingException {
    HttpResponse response;
    ByteBuf responseContent = Unpooled.buffer();
    HttpResponseStatus responseStatus = HttpResponseStatus.OK;
    try (ByteBufOutputStream os = new ByteBufOutputStream(responseContent);
         ByteBufInputStream is = new ByteBufInputStream(request.content().retain())){
        int result = jsonRpcServer.handleRequest(is, os);
        responseStatus = HttpResponseStatus.valueOf(DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result));
    } catch (Exception e) {
        LOGGER.error("Unexpected error", e);
        responseContent = buildErrorContent(JSON_RPC_SERVER_ERROR_HIGH_CODE, HttpResponseStatus.INTERNAL_SERVER_ERROR.reasonPhrase());
        responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
    } finally {
        response = new DefaultFullHttpResponse(
            HttpVersion.HTTP_1_1,
            responseStatus,
            responseContent
        );
    }
    return response;
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:22,代碼來源:JsonRpcWeb3ServerHandler.java

示例4: decode

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
@Override
protected final Object decode(ChannelHandlerContext ctx,
                        ByteBuf buffer) throws Exception {
    /* This is initialized to null because the decode function must return
     * null if the buffer does not contain a complete frame and cannot be
     * decoded.
     */
    List<T> ms = null;
    ByteBuf frame = null;
    while (null != (frame = (ByteBuf) super.decode(ctx, buffer))) {
        if (ms == null) ms = new ArrayList<T>();
        ByteBufInputStream is = new ByteBufInputStream(frame);
        TCompactProtocol thriftProtocol =
                new TCompactProtocol(new TIOStreamTransport(is));
        T message = allocateMessage();
        message.read(thriftProtocol);
        ms.add(message);
    }
    return ms;
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:21,代碼來源:ThriftFrameDecoder.java

示例5: readFromClientData

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
@SuppressWarnings("resource")
@Override
public void readFromClientData(Connection connection, ByteBuf clientData) {
	protocolVersion = clientData.readInt(); //protocol version

	ByteBuf logindata = Unpooled.wrappedBuffer(ArraySerializer.readByteArray(clientData, connection.getVersion()));

	// skip chain data
	logindata.skipBytes(logindata.readIntLE());

	// decode skin data
	try {
		InputStream inputStream = new ByteBufInputStream(logindata, logindata.readIntLE());
		ByteArrayOutputStream result = new ByteArrayOutputStream();
		byte[] buffer = new byte[1024];
		int length;
		while ((length = inputStream.read(buffer)) != -1) {
			result.write(buffer, 0, length);
		}
		clientPayload = decodeToken(result.toString("UTF-8"));
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
開發者ID:ProtocolSupport,項目名稱:ProtocolSupportPocketStuff,代碼行數:25,代碼來源:ClientLoginPacket.java

示例6: readNBTTagCompoundFromBuffer

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
/**
 * Reads a compressed NBTTagCompound from this buffer
 */
@Nullable
public NBTTagCompound readNBTTagCompoundFromBuffer() throws IOException
{
    int i = this.readerIndex();
    byte b0 = this.readByte();

    if (b0 == 0)
    {
        return null;
    }
    else
    {
        this.readerIndex(i);

        try
        {
            return CompressedStreamTools.read(new ByteBufInputStream(this), new NBTSizeTracker(2097152L));
        }
        catch (IOException ioexception)
        {
            throw new EncoderException(ioexception);
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:28,代碼來源:PacketBuffer.java

示例7: read

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
@Override
public CompoundTag read(ByteBuf buffer) throws Exception {
    Preconditions.checkArgument(buffer.readableBytes() <= 2097152, "Cannot read NBT (got %s bytes)", buffer.readableBytes());

    int readerIndex = buffer.readerIndex();
    byte b = buffer.readByte();
    if (b == 0) {
        return null;
    } else {
        buffer.readerIndex(readerIndex);
        ByteBufInputStream bytebufStream = new ByteBufInputStream(buffer);
        try (DataInputStream dataInputStream = new DataInputStream(bytebufStream)) {
            return (CompoundTag) NBTIO.readTag((DataInput) dataInputStream);
        }
    }
}
 
開發者ID:MylesIsCool,項目名稱:ViaVersion,代碼行數:17,代碼來源:NBTType.java

示例8: fromBytes

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
@Override
public void fromBytes(ByteBuf buf)
{
    ByteBufInputStream input = new ByteBufInputStream(buf);
    List<Frame> frames = new ArrayList<Frame>();

    try
    {
        this.filename = input.readUTF();
        int count = input.readInt();

        for (int i = 0; i < count; i++)
        {
            Frame frame = new Frame();

            frame.fromBytes(input);
            frames.add(frame);
        }
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }

    this.frames = frames;
}
 
開發者ID:mchorse,項目名稱:blockbuster,代碼行數:27,代碼來源:PacketFrames.java

示例9: readNbtTagCompound

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
public NbtTagCompound readNbtTagCompound()
{
    final int currIndex = this.readerIndex();
    final byte firstTag = this.readByte();
    if (firstTag == NbtTagType.END.getTypeID())
    {
        return null;
    }
    this.readerIndex(currIndex);
    try
    {
        return (NbtTagCompound) NbtInputStream.readTag(new ByteBufInputStream(this), NbtLimiter.getDefault());
    } catch (final IOException e)
    {
        throw new RuntimeException("Can't decode nbt.", e);
    }
}
 
開發者ID:Diorite,項目名稱:Diorite-old,代碼行數:18,代碼來源:PacketDataSerializer.java

示例10: parseToNode

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
/**
 * Parses the passed channel buffer into a JsonNode
 * @param buff The buffer to parse
 * @param nullIfNoContent If true, returns null if no content is available to parse
 * @return the parsed JsonNode
 */
public static JsonNode parseToNode(final ByteBuf buff, final boolean nullIfNoContent) {
	if (buff == null || buff.readableBytes() < 1) {
		if(nullIfNoContent) return null;
		throw new IllegalArgumentException("Incoming data was null");
	}
	final InputStream is = new ByteBufInputStream(buff);
	try {
		return parseToNode(is);
	} catch (Exception e) {
		if(nullIfNoContent) return null;
		throw new JSONException(e);
	} finally {
		try { is.close(); } catch (Exception x) {/* No Op */}
	}
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:22,代碼來源:JSONOps.java

示例11: serializeOffHeapLoopBack

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
/**
 * Serializes the passed object to an off-heap buffer and returns an InputStream to read it back
 * @param obj The object to serialize
 * @return an InputStream to read back the JSON serialized object 
 */
public static InputStream serializeOffHeapLoopBack(final Object obj) {
	if(obj==null) throw new IllegalArgumentException("The passed object was null");
	final ByteBuf cb = byteBufAllocator.buffer();
	final OutputStream os = new ByteBufOutputStream(cb);
	
	try {
		serialize(obj, os);
		os.flush();
		os.close();
	} catch (Exception ex) {
		throw new RuntimeException("Failed to write object to buffer", ex);
	}
	
	return new ByteBufInputStream(cb) {
		@Override
		public void close() throws IOException {				
			super.close();
			try { cb.release(); } catch (Exception x) {/* No Op */}
		}
	};
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:27,代碼來源:JSONOps.java

示例12: decodeFrame0

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
private Object decodeFrame0(ByteBuf buffer) throws Exception {
    final Protocol0.Message message;

    final InputStream inputStream = new ByteBufInputStream(buffer);

    try {
        message = Protocol0.Message.parseFrom(inputStream);
    } catch (final InvalidProtocolBufferException e) {
        throw new Exception("Invalid protobuf message", e);
    }

    if (message.hasEvent()) {
        return decodeEvent0(message.getEvent());
    }

    if (message.hasMetric()) {
        return decodeMetric0(message.getMetric());
    }

    return null;
}
 
開發者ID:spotify,項目名稱:ffwd,代碼行數:22,代碼來源:ProtobufDecoder.java

示例13: decode0

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
private Object decode0(ByteBuf in, List<Object> out)
    throws IOException, JsonProcessingException {
    final JsonNode tree;

    try (final InputStream input = new ByteBufInputStream(in)) {
        tree = mapper.readTree(input);
    }

    final JsonNode typeNode = tree.get("type");

    if (typeNode == null) {
        throw new IllegalArgumentException("Missing field 'type'");
    }

    final String type = typeNode.asText();

    if ("event".equals(type)) {
        return decodeEvent(tree, out);
    }

    if ("metric".equals(type)) {
        return decodeMetric(tree, out);
    }

    throw new IllegalArgumentException("Invalid metric type '" + type + "'");
}
 
開發者ID:spotify,項目名稱:ffwd,代碼行數:27,代碼來源:JsonObjectMapperDecoder.java

示例14: postBatch

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
private void postBatch(
    final ChannelHandlerContext ctx, final FullHttpRequest in, final List<Object> out
) {
    final Batch batch;
    try (final InputStream inputStream = new ByteBufInputStream(in.content())) {
        batch = mapper.readValue(inputStream, Batch.class);
    } catch (final IOException e) {
        throw new HttpException(HttpResponseStatus.BAD_REQUEST);
    }

    out.add(batch);

    ctx
        .channel()
        .writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK))
        .addListener((ChannelFutureListener) future -> future.channel().close());
}
 
開發者ID:spotify,項目名稱:ffwd,代碼行數:18,代碼來源:HttpDecoder.java

示例15: getValueDecoder

import io.netty.buffer.ByteBufInputStream; //導入依賴的package包/類
@Override
public Decoder<Object> getValueDecoder() {
    return new Decoder<Object>() {

        @Override
        public Object decode(ByteBuf buf, State state) throws IOException {
            Kryo kryo = null;
            try {
                kryo = kryoPool.get();
                return kryo.readClassAndObject(new Input(new ByteBufInputStream(buf)));
            } catch (Exception e) {
                if (e instanceof RuntimeException) {
                    throw (RuntimeException) e;
                }
                throw new RedissonKryoCodecException(e);
            } finally {
                if (kryo != null) {
                    kryoPool.yield(kryo);
                }
            }
        }
    };
}
 
開發者ID:rollenholt-SourceReading,項目名稱:redisson,代碼行數:24,代碼來源:KryoCodec.java


注:本文中的io.netty.buffer.ByteBufInputStream類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。