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


Java ByteBuf.discardReadBytes方法代码示例

本文整理汇总了Java中io.netty.buffer.ByteBuf.discardReadBytes方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuf.discardReadBytes方法的具体用法?Java ByteBuf.discardReadBytes怎么用?Java ByteBuf.discardReadBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.buffer.ByteBuf的用法示例。


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

示例1: parseValue

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
private String parseValue(String path, String file) throws Exception {
    final StringBuilder sb = new StringBuilder();
    ByteBuf inBuf = Unpooled.buffer();

    JsonPointer[] jsonPointers = {
            new JsonPointer("/" + path, new JsonPointerCB1() {
                public void call(ByteBuf buf) {
                    sb.append(buf.toString(Charset.defaultCharset()));
                    buf.release();
                }
            }),
    };
    String response = getResource(file);
    parser.initialize(inBuf, jsonPointers);
    inBuf.writeBytes(response.getBytes());
    parser.parse();
    inBuf.discardReadBytes();
    inBuf.release();
    return sb.toString();
}
 
开发者ID:subalakr,项目名称:yasjl,代码行数:21,代码来源:QueryResponseByteBufJsonParserTest.java

示例2: split

import io.netty.buffer.ByteBuf; //导入方法依赖的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

示例3: split

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Iterable<String> split(final ByteBuf buffer, final Charset charset, final boolean includeRemainingData) {
    return () -> new AbstractIterator<String>() {
        // TODO Might throw an exception if multibyte charset is used and buffer is not complete.
        //      Use CharsetDecoder to create a CharBuffer and match on that!
        private final String inputAsString = buffer.toString(charset);
        final Matcher matcher = pattern.matcher(inputAsString);
        private int positionInString = 0;

        @Override
        protected String computeNext() {
            try {
                if (!buffer.isReadable()) {
                    return endOfData();
                }
                if (matcher.find()) {
                    int firstByte = matcher.start();
                    if (firstByte == 0) {
                        // advance further, the buffer begins with our pattern.
                        if (matcher.find()) {
                            firstByte = matcher.start();
                        } else {
                            if (!includeRemainingData) {
                                // couldn't find the end of the entry (i.e. there wasn't a next line yet)
                                return endOfData();
                            } else {
                                // couldn't find another line, but we are asked to finish up, include everything that remains
                                return getRemainingContent();
                            }
                        }
                    }
                    if (firstByte == 0) {
                        // still haven't found a non-zero length string, keep waiting for more data.
                        return endOfData();
                    }
                    final String substring = inputAsString.substring(positionInString, firstByte);
                    positionInString = firstByte;
                    buffer.skipBytes(substring.getBytes(charset).length); // TODO performance
                    return substring;
                } else {
                    if (includeRemainingData) {
                        return getRemainingContent();
                    }
                    return endOfData();
                }
            } catch (IllegalStateException e) {
                // the cause contains the CharacterCodingException from the ChannelBuffer.toString() methods
                // this usually means the buffer ended with an incomplete encoding of a unicode character.
                // WHY U SO SUCK CHARACTER ENCODINGS?
                // we need to wait until more data is available
                return endOfData();
            } finally {
                buffer.discardReadBytes();
            }
        }

        private String getRemainingContent() {
            final ByteBuf channelBuffer = buffer.readBytes(buffer.readableBytes());
            return channelBuffer.toString(charset);
        }
    };
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:63,代码来源:PatternChunkSplitter.java


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