本文整理匯總了Java中io.netty.buffer.ByteBuf.readSlice方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.readSlice方法的具體用法?Java ByteBuf.readSlice怎麽用?Java ByteBuf.readSlice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.readSlice方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: readBoundValue
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static ByteBuffer readBoundValue(ByteBuf cb, ProtocolVersion protocolVersion)
{
int length = cb.readInt();
if (length < 0)
{
if (protocolVersion.isSmallerThan(ProtocolVersion.V4)) // backward compatibility for pre-version 4
return null;
if (length == -1)
return null;
else if (length == -2)
return ByteBufferUtil.UNSET_BYTE_BUFFER;
else
throw new ProtocolException("Invalid ByteBuf length " + length);
}
ByteBuf slice = cb.readSlice(length);
return ByteBuffer.wrap(readRawBytes(slice));
}
示例2: readBytes
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public ByteBuffer readBytes(ByteBuf source) {
int len = readInt(source);
if (len < 0) {
return null;
}
ByteBuf slice = source.readSlice(len);
// if direct byte buffer, return underlying nioBuffer.
if (slice.isDirect()) {
return slice.nioBuffer();
}
// otherwise copy to a byte array and wrap it.
final byte[] out = new byte[slice.readableBytes()];
source.getBytes(source.readerIndex(), out, 0, len);
return ByteBuffer.wrap(out);
}
示例3: readBytes
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public ByteBuf readBytes(ByteBuf is) throws IOException {
long l = readLong(is);
if (l > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
"Java only supports arrays up to " + Integer.MAX_VALUE + " in size");
}
int size = (int) l;
if (size == -1) {
return null;
}
ByteBuf buffer = is.readSlice(size);
int cr = is.readByte();
int lf = is.readByte();
if (cr != CR || lf != LF) {
throw new IOException("Improper line ending: " + cr + ", " + lf);
}
return buffer;
}
示例4: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private Object decode(ByteBuf buf, State state, Decoder<?> decoder) throws IOException {
int keyLen;
if (PlatformDependent.isWindows()) {
keyLen = buf.readIntLE();
} else {
keyLen = (int) buf.readLongLE();
}
ByteBuf keyBuf = buf.readSlice(keyLen);
Object key = decoder.decode(keyBuf, state);
return key;
}
示例5: readValue
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static ByteBuffer readValue(ByteBuf cb)
{
int length = cb.readInt();
if (length < 0)
return null;
ByteBuf slice = cb.readSlice(length);
return ByteBuffer.wrap(readRawBytes(slice));
}
示例6: readContent
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
protected void readContent(ByteBuf in, CompletableFuture<T> promise) {
if (in.readableBytes() < length) {
return;
}
ByteBuf buf = in.readSlice((int) length);
T result = decoder.decode(buf);
promise.complete(result);
atHead = true;
}
示例7: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
List<Object> result = new ArrayList<Object>();
int keyLen;
if (PlatformDependent.isWindows()) {
keyLen = buf.readIntLE();
} else {
keyLen = (int) buf.readLongLE();
}
ByteBuf keyBuf = buf.readSlice(keyLen);
Object key = codec.getMapKeyDecoder().decode(keyBuf, state);
result.add(key);
int valueLen;
if (PlatformDependent.isWindows()) {
valueLen = buf.readIntLE();
} else {
valueLen = (int) buf.readLongLE();
}
ByteBuf valueBuf = buf.readSlice(valueLen);
Object value = codec.getMapValueDecoder().decode(valueBuf, state);
result.add(value);
if (sync) {
double syncId = buf.order(ByteOrder.LITTLE_ENDIAN).readDouble();
result.add(syncId);
}
return result;
}
示例8: readContent
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private ByteBuf readContent(int length) throws IOException {
ByteBuf content = current.content();
if (length < content.readableBytes()) {
return content.readSlice(length);
} else {
return content;
}
}
示例9: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode ( final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out ) throws Exception
{
if ( logger.isTraceEnabled () )
{
logger.trace ( "decode - bytes: {}", ByteBufUtil.hexDump ( in ) );
}
if ( in.readableBytes () < Constants.APCI_MIN_LENGTH )
{
return;
}
final byte start = in.getByte ( in.readerIndex () + 0 );
if ( start != Constants.START_BYTE )
{
throw new DecoderException ( String.format ( "ACPI must start with 0x%02x but did with 0x%02x", Constants.START_BYTE, start ) );
}
final short len = in.getUnsignedByte ( in.readerIndex () + 1 );
if ( len > Constants.APCI_MAX_DATA_LENGTH )
{
throw new DecoderException ( String.format ( "APCI has a maximum length of %s bytes, but we received %s", Constants.APCI_MAX_DATA_LENGTH, len ) );
}
if ( in.readableBytes () < len + 2 )
{
return;
}
// we have the full InformationTransfer
// skip start & len
in.skipBytes ( 2 );
// read control fields
final ByteBuf controlFields = in.readSlice ( 4 );
final ByteBuf data;
if ( len > 4 )
{
data = Unpooled.copiedBuffer ( in.readSlice ( len - 4 ) ).order ( ByteOrder.LITTLE_ENDIAN );
}
else
{
data = null;
}
// now add the PDU
out.add ( decode ( controlFields, data ) );
}
示例10: readToJsonNode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
* Decode the bytes to Json object.
* @param in input of bytes
* @param out ouput of Json object list
* @param jrContext context for the last decoding process
* @throws IOException IOException
* @throws JsonParseException JsonParseException
*/
public static void readToJsonNode(ByteBuf in, List<Object> out, JsonReadContext jrContext)
throws JsonParseException, IOException {
int lastReadBytes = jrContext.getLastReadBytes();
if (lastReadBytes == 0) {
if (in.readableBytes() < 4) {
return;
}
checkEncoding(in);
}
int i = lastReadBytes + in.readerIndex();
Stack<Byte> bufStack = jrContext.getBufStack();
for (; i < in.writerIndex(); i++) {
byte b = in.getByte(i);
switch (b) {
case '{':
if (!isDoubleQuote(bufStack)) {
bufStack.push(b);
jrContext.setStartMatch(true);
}
break;
case '}':
if (!isDoubleQuote(bufStack)) {
bufStack.pop();
}
break;
case '"':
if (in.getByte(i - 1) != '\\') {
if (!bufStack.isEmpty() && bufStack.peek() != '"') {
bufStack.push(b);
} else {
bufStack.pop();
}
}
break;
default:
break;
}
if (jrContext.isStartMatch() && bufStack.isEmpty()) {
ByteBuf buf = in.readSlice(i - in.readerIndex() + 1);
JsonParser jf = new MappingJsonFactory().createParser(new ByteBufInputStream(buf));
JsonNode jsonNode = jf.readValueAsTree();
out.add(jsonNode);
lastReadBytes = 0;
jrContext.setLastReadBytes(lastReadBytes);
break;
}
}
if (i >= in.writerIndex()) {
lastReadBytes = in.readableBytes();
jrContext.setLastReadBytes(lastReadBytes);
}
}