本文整理匯總了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);
}
}
}
示例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));
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
示例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 */}
}
}
示例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 */}
}
};
}
示例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;
}
示例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 + "'");
}
示例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());
}
示例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);
}
}
}
};
}