本文整理汇总了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;
}
}
示例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;
}
示例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;
}
}
示例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();
}
}
}
};
}
示例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;
}
示例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;
}
示例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();
}
}
};
}
};
}
示例8: forEachByteDesc
import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public int forEachByteDesc(ByteBufProcessor processor) {
if (terminated) {
return buffer.forEachByteDesc(processor);
} else {
reject();
return 0;
}
}
示例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));
}
示例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));
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例15: forEachByte
import io.netty.buffer.ByteBufProcessor; //导入依赖的package包/类
@Override
public int forEachByte(ByteBufProcessor byteBufProcessor)
{
return byteBuf.forEachByte(byteBufProcessor);
}