当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufProcessor类代码示例

本文整理汇总了Java中io.netty.buffer.ByteBufProcessor的典型用法代码示例。如果您正苦于以下问题:Java ByteBufProcessor类的具体用法?Java ByteBufProcessor怎么用?Java ByteBufProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ByteBufProcessor类属于io.netty.buffer包,在下文中一共展示了ByteBufProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: forEachByte

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public int forEachByte(int index, int length, ByteBufProcessor processor) {
    final int writerIndex = buffer.writerIndex();
    if (index >= writerIndex) {
        throw REPLAY;
    }

    if (index <= writerIndex - length) {
        return buffer.forEachByte(index, length, processor);
    }

    int ret = buffer.forEachByte(index, writerIndex - index, processor);
    if (ret < 0) {
        throw REPLAY;
    } else {
        return ret;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:ReplayingDecoderBuffer.java

示例2: decodeString

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
private String decodeString(ByteBuf in) throws ProtocolException {
    final StringBuilder buffer = new StringBuilder();
    final MutableBoolean reachCRLF = new MutableBoolean(false);
    setReaderIndex(in, in.forEachByte(new ByteBufProcessor() {

        @Override
        public boolean process(byte value) throws Exception {
            if (value == '\n') {
                if ((byte) buffer.charAt(buffer.length() - 1) != '\r') {
                    throw new ProtocolException("Response is not ended by CRLF");
                } else {
                    buffer.setLength(buffer.length() - 1);
                    reachCRLF.setTrue();
                    return false;
                }
            } else {
                buffer.append((char) value);
                return true;
            }
        }
    }));
    return reachCRLF.booleanValue() ? buffer.toString() : null;
}
 
开发者ID:CodisLabs,项目名称:nedis,代码行数:24,代码来源:RedisResponseDecoder.java

示例3: forEachByte

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public int forEachByte(int index, int length, ByteBufProcessor processor) {
    final int writerIndex = buffer.writerIndex();
    if (index >= writerIndex) {
        throw REPLAY;
    }

    if (index + length <= writerIndex) {
        return buffer.forEachByte(index, length, processor);
    }

    int ret = buffer.forEachByte(index, writerIndex - index, processor);
    if (ret < 0) {
        throw REPLAY;
    } else {
        return ret;
    }
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:19,代码来源:ReplayingDecoderBuffer.java

示例4: split

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public Iterable<String> split(final ByteBuf buffer, final Charset charset, final boolean includeRemainingData) {
    return () -> new AbstractIterator<String>() {
        @Override
        protected String computeNext() {
            ByteBuf fullLine = null;
            try {
                if (!buffer.isReadable()) {
                    return endOfData();
                }
                final int i = buffer.forEachByte(ByteBufProcessor.FIND_CRLF);
                if (i == -1) {
                    if (includeRemainingData) {
                        final ByteBuf remaining = buffer.readBytes(buffer.readableBytes());
                        return remaining.toString(charset);
                    } else {
                        return endOfData();
                    }
                }
                fullLine = buffer.readBytes(i);
                // Strip the \r/\n bytes from the buffer.
                final byte readByte = buffer.readByte(); // the \r or \n byte
                if (readByte == '\r') {
                    buffer.readByte(); // the \n byte if previous was \r
                }
                return fullLine.toString(charset);
            } finally {
                buffer.discardReadBytes();
                if (fullLine != null) {
                    fullLine.release();
                }

            }
        }
    };
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:37,代码来源:NewlineChunkSplitter.java

示例5: process

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
protected ByteBuf process(final StreamCipher cipher, ByteBuf data) {
    final ByteBuf slice = data.slice();
    slice.writerIndex(0);
    data.forEachByte(data.readerIndex(), data.readableBytes(), new ByteBufProcessor() {
        @Override
        public boolean process(byte b) throws Exception {
            slice.writeByte(cipher.returnByte(b));
            return true;
        }
    });
    return data;
}
 
开发者ID:zhoulifu,项目名称:ss-java,代码行数:14,代码来源:AbstractBouncycastleCrypto.java

示例6: readNullTerminatedString

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
private String readNullTerminatedString(Charset charset) {
    int indexOfNull = buffer.forEachByte(ByteBufProcessor.FIND_NUL);

    if (indexOfNull == -1) {
        throw new UaSerializationException(
            StatusCodes.Bad_DecodingError, "null terminator not found");
    }

    int index = buffer.readerIndex();
    int length = indexOfNull - index;
    String str = buffer.toString(index, length, charset);
    buffer.skipBytes(length + 1);

    return str;
}
 
开发者ID:eclipse,项目名称:milo,代码行数:16,代码来源:OpcUaBinaryStreamDecoder.java

示例7: split

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public Iterable<String> split(final ByteBuf buffer, final Charset charset, final boolean includeRemainingData) {
    return new Iterable<String>() {
        @Override
        public Iterator<String> iterator() {
            return new AbstractIterator<String>() {

                @Override
                protected String computeNext() {
                    try {
                        if (!buffer.isReadable()) {
                            return endOfData();
                        }
                        final int i = buffer.forEachByte(ByteBufProcessor.FIND_CRLF);
                        if (i == -1) {
                            if (includeRemainingData) {
                                final ByteBuf remaining = buffer.readBytes(buffer.readableBytes());
                                return remaining.toString(charset);
                            } else {
                                return endOfData();
                            }
                        }
                        final ByteBuf fullLine = buffer.readBytes(i);
                        // Strip the \r/\n bytes from the buffer.
                        final byte readByte = buffer.readByte(); // the \r or \n byte
                        if (readByte == '\r') {
                            buffer.readByte(); // the \n byte if previous was \r
                        }
                        return fullLine.toString(charset);
                    } finally {
                        buffer.discardReadBytes();
                    }
                }
            };
        }
    };
}
 
开发者ID:graylog-labs,项目名称:collector,代码行数:38,代码来源:NewlineChunkSplitter.java

示例8: forEachByteDesc

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public int forEachByteDesc(ByteBufProcessor processor) {
    if (terminated) {
        return buffer.forEachByteDesc(processor);
    } else {
        reject();
        return 0;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:10,代码来源:ReplayingDecoderBuffer.java

示例9: testMultiCharFieldSplitProcessor1

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Test
public void testMultiCharFieldSplitProcessor1() throws IOException {
  String data = "abc||||de||";
  final ByteBuf buf = releaseLater(
      Unpooled.copiedBuffer(data, CharsetUtil.ISO_8859_1));

  final int len = buf.readableBytes();
  ByteBufProcessor processor = new MultiBytesFieldSplitProcessor("||".getBytes());

  assertEquals(4, buf.forEachByte(0, len, processor));
  assertEquals(6, buf.forEachByte(5, len - 5, processor));
  assertEquals(10, buf.forEachByte(7, len - 7, processor));
  assertEquals(-1, buf.forEachByte(11, len - 11, processor));
}
 
开发者ID:apache,项目名称:tajo,代码行数:15,代码来源:TestSplitProcessor.java

示例10: testMultiCharFieldSplitProcessor2

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Test
public void testMultiCharFieldSplitProcessor2() throws IOException {
  String data = "abcㅎㅎdeㅎ";
  final ByteBuf buf = releaseLater(
      Unpooled.copiedBuffer(data, CharsetUtil.UTF_8));

  final int len = buf.readableBytes();
  ByteBufProcessor processor = new MultiBytesFieldSplitProcessor("ㅎ".getBytes());

  assertEquals(5, buf.forEachByte(0, len, processor));
  assertEquals(8, buf.forEachByte(6, len - 6, processor));
  assertEquals(13, buf.forEachByte(9, len - 9, processor));
  assertEquals(-1, buf.forEachByte(14, len - 14, processor));
}
 
开发者ID:apache,项目名称:tajo,代码行数:15,代码来源:TestSplitProcessor.java

示例11: parseViewInfo

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
/**
 * Parse out the info portion from the header part of the query response.
 *
 * This includes the total rows, but also debug info if attached.
 */
private void parseViewInfo() {
    int rowsStart = -1;
    for (int i = responseContent.readerIndex(); i < responseContent.writerIndex() - 2; i++) {
        byte curr = responseContent.getByte(i);
        byte f1 = responseContent.getByte(i + 1);
        byte f2 = responseContent.getByte(i + 2);

        if (curr == '"' && f1 == 'r' && f2 == 'o') {
            rowsStart = i;
            break;
        }
    }

    if (rowsStart == -1) {
        return;
    }

    ByteBuf info = responseContent.readBytes(rowsStart - responseContent.readerIndex());
    int closingPointer = info.forEachByteDesc(new ByteBufProcessor() {
        @Override
        public boolean process(byte value) throws Exception {
            return value != ',';
        }
    });

    if (closingPointer > 0) {
        info.setByte(closingPointer, '}');
        viewInfoObservable.onNext(info);
    } else {
        //JVMCBC-360 don't forget to release the now unused info ByteBuf
        info.release();
        viewInfoObservable.onNext(Unpooled.EMPTY_BUFFER);
    }
    viewInfoObservable.onCompleted();
    viewParsingState = QUERY_STATE_ROWS;
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:42,代码来源:ViewHandler.java

示例12: parseQuerySignature

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
/**
 * Parse the signature section in the N1QL response.
 */
private void parseQuerySignature(boolean lastChunk) {
    ByteBufProcessor processor = null;
    //signature can be any valid JSON item, which get tricky to detect
    //let's try to find out what's the boundary character
    int openPos = responseContent.forEachByte(new WhitespaceSkipper()) - responseContent.readerIndex();
    if (openPos < 0) {
        //only whitespace left in the buffer, need more data
        return;
    }
    char openChar = (char) responseContent.getByte(responseContent.readerIndex() + openPos);
    if (openChar == '{') {
        processor = new ClosingPositionBufProcessor('{', '}', true);
    } else if (openChar == '[') {
        processor = new ClosingPositionBufProcessor('[', ']', true);
    } else if (openChar == '"') {
        processor = new StringClosingPositionBufProcessor();
    } //else this should be a scalar, skip processor

    int closePos;
    if (processor != null) {
        closePos = responseContent.forEachByte(processor) - responseContent.readerIndex();
    } else {
        closePos = findNextChar(responseContent, ',') - 1;
    }
    if (closePos > 0) {
        responseContent.skipBytes(openPos);
        int length = closePos - openPos + 1;
        ByteBuf signature = responseContent.readSlice(length);
        querySignatureObservable.onNext(signature.copy());
    } else {
        //wait for more data
        return;
    }
    //note: the signature section could be absent, so we'll make sure to complete the observable
    // when receiving status since this is in every well-formed response.
    sectionDone();
    queryParsingState = transitionToNextToken(lastChunk);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:42,代码来源:QueryHandler.java

示例13: parseQuerySignature

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
/**
 * Parse the signature section in the Analytics response.
 */
private void parseQuerySignature(boolean lastChunk) {
    ByteBufProcessor processor = null;
    //signature can be any valid JSON item, which get tricky to detect
    //let's try to find out what's the boundary character
    int openPos = responseContent.forEachByte(new WhitespaceSkipper()) - responseContent.readerIndex();
    if (openPos < 0) {
        //only whitespace left in the buffer, need more data
        return;
    }
    char openChar = (char) responseContent.getByte(responseContent.readerIndex() + openPos);
    if (openChar == '{') {
        processor = new ClosingPositionBufProcessor('{', '}', true);
    } else if (openChar == '[') {
        processor = new ClosingPositionBufProcessor('[', ']', true);
    } else if (openChar == '"') {
        processor = new StringClosingPositionBufProcessor();
    } //else this should be a scalar, skip processor

    int closePos;
    if (processor != null) {
        closePos = responseContent.forEachByte(processor) - responseContent.readerIndex();
    } else {
        closePos = findNextChar(responseContent, ',') - 1;
    }
    if (closePos > 0) {
        responseContent.skipBytes(openPos);
        int length = closePos - openPos + 1;
        ByteBuf signature = responseContent.readSlice(length);
        querySignatureObservable.onNext(signature.copy());
    } else {
        //wait for more data
        return;
    }
    //note: the signature section could be absent, so we'll make sure to complete the observable
    // when receiving status since this is in every well-formed response.
    sectionDone();
    queryParsingState = transitionToNextToken(lastChunk);
}
 
开发者ID:couchbase,项目名称:couchbase-jvm-core,代码行数:42,代码来源:AnalyticsHandler.java

示例14: readControlChars

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
/**
 * Reads the optional EOL (and other control characters) that are permitted
 * between the end of one frame and the start of the next frame. When a
 * non-control character is detected, the decoder state will be advanced.
 *
 * @param in the input buffer to read from
 *
 * @return the next decoder state or null if no checkpoint should be set
 */
private DecoderState readControlChars(ByteBuf in) {

  DecoderState nextState = DecoderState.READ_CONTROL_CHARS;

  int index = in.forEachByte(new ByteBufProcessor() {
    @Override
    public boolean process(byte b) throws Exception {
      switch (b) {
        // This is a little more lax than the spec which allows for only
        // EOL character(s) between frames.
        case ' ':
        case CARRIAGE_RETURN_CHAR:
        case LINE_FEED_CHAR:
        case NULL_CHAR:
          // ignore the character
          return true;

        default:
          return false;
      }
    }
  });

  if (index != -1) {
    // A non-control character was found so we skip up to that index and
    // move to the next state.
    in.readerIndex(index);
    nextState = DecoderState.READ_COMMAND;
  }
  else {
    // Discard all available bytes because we couldn't find a
    // non-control character.
    in.readerIndex(in.writerIndex());
  }

  return nextState;
}
 
开发者ID:mpilone,项目名称:hazelcastmq,代码行数:47,代码来源:StompFrameDecoder.java

示例15: forEachByte

import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public int forEachByte(ByteBufProcessor byteBufProcessor)
{
    return byteBuf.forEachByte(byteBufProcessor);
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:6,代码来源:ProtocolBuffer.java


注:本文中的io.netty.buffer.ByteBufProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。