本文整理了Java中io.netty.buffer.ByteBuf.discardReadBytes()
方法的一些代码示例,展示了ByteBuf.discardReadBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.discardReadBytes()
方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:discardReadBytes
[英]Discards the bytes between the 0th index and readerIndex. It moves the bytes between readerIndex and writerIndexto the 0th index, and sets readerIndex and writerIndexto 0 and oldWriterIndex - oldReaderIndex respectively.
Please refer to the class documentation for more detailed explanation.
[中]丢弃第0个索引和readerIndex之间的字节。它将readerIndex和WriterIndex之间的字节移动到第0个索引,并将readerIndex和WriterIndex分别设置为0和oldWriterIndex-oldReaderIndex。
有关更详细的解释,请参阅课堂文档。
代码示例来源:origin: apache/incubator-dubbo
@Override
public void discardReadBytes() {
buffer.discardReadBytes();
}
代码示例来源:origin: netty/netty
@Override
public ByteBuf discardReadBytes() {
buf.discardReadBytes();
return this;
}
代码示例来源:origin: netty/netty
@Override
public ByteBuf discardReadBytes() {
buf.discardReadBytes();
return this;
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuf discardReadBytes() {
buf.discardReadBytes();
return this;
}
代码示例来源:origin: redisson/redisson
@Override
public ByteBuf discardReadBytes() {
buf.discardReadBytes();
return this;
}
代码示例来源:origin: wildfly/wildfly
@Override
public ByteBuf discardReadBytes() {
buf.discardReadBytes();
return this;
}
代码示例来源:origin: wildfly/wildfly
@Override
public ByteBuf discardReadBytes() {
buf.discardReadBytes();
return this;
}
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public ByteBuf discardReadBytes() {
byteBuf.discardReadBytes();
return this;
}
代码示例来源:origin: wildfly/wildfly
@Override
public void discardReadBytes() {
buffer.discardReadBytes();
}
代码示例来源:origin: alibaba/canal
public void close() {
if (channel != null) {
channel.close();
}
channel = null;
// A fatal error has been detected by the Java Runtime Environment:
// EXCEPTION_ACCESS_VIOLATION (0xc0000005)
synchronized (lock) {
cache.discardReadBytes();// 回收已占用的内存
cache.release();// 释放整个内存
cache = null;
}
}
代码示例来源:origin: docker-java/docker-java
private int read(byte[] buf, int offset, int length) {
length = Math.min(rawBuffer.readableBytes(), length);
rawBuffer.readBytes(buf, offset, length);
rawBuffer.discardReadBytes();
return length;
}
代码示例来源:origin: docker-java/docker-java
private String getBodyAsMessage(ByteBuf body) {
String result = body.readBytes(body.readableBytes()).toString(Charset.forName("UTF-8"));
body.discardReadBytes();
body.release();
return result;
}
}
代码示例来源:origin: docker-java/docker-java
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
byte[] buffer = new byte[msg.readableBytes()];
msg.readBytes(buffer);
msg.discardReadBytes();
T object = null;
try {
object = objectMapper.readValue(buffer, typeReference);
} catch (Exception e) {
callback.onError(e);
throw new RuntimeException(e);
}
callback.onNext(object);
}
代码示例来源:origin: lettuce-io/lettuce-core
/**
* Try to discard read bytes when buffer usage reach a higher usage ratio.
*
* @param buffer
*/
private void discardReadBytesIfNecessary(ByteBuf buffer) {
float usedRatio = (float) buffer.readerIndex() / buffer.capacity();
if (usedRatio >= discardReadBytesRatio && buffer.refCnt() != 0) {
buffer.discardReadBytes();
}
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Decode ByteBuf to AckEvent objects.
*
* @param in byte buf
* @param decodedOut list of AckEvent objects
*/
private static void decodeAckEvent(ByteBuf in, List<Object> decodedOut) throws IOException {
int readerIndex = in.readerIndex();
int writerIndex = in.writerIndex();
for (; readerIndex < writerIndex; ++readerIndex) {
// Read one byte at a time to avoid incrementing reader index
byte c = in.getByte(readerIndex);
if (NEW_LINE == c) {
ByteBuf json = extractObject(in, in.readerIndex(), readerIndex - in.readerIndex());
if (json != null) {
decodedOut.add(unmarshall(json));
}
in.readerIndex(readerIndex + 1);
in.discardReadBytes();
// Reader and writer index shift after discard. Update them
readerIndex = in.readerIndex();
writerIndex = in.writerIndex();
ReferenceCountUtil.release(json);
}
}
}
代码示例来源:origin: wildfly/wildfly
@Override
void decode(ByteBufAllocator alloc, ByteBuf headerBlock, SpdyHeadersFrame frame) throws Exception {
if (headerBlock == null) {
throw new NullPointerException("headerBlock");
}
if (frame == null) {
throw new NullPointerException("frame");
}
if (cumulation == null) {
decodeHeaderBlock(headerBlock, frame);
if (headerBlock.isReadable()) {
cumulation = alloc.buffer(headerBlock.readableBytes());
cumulation.writeBytes(headerBlock);
}
} else {
cumulation.writeBytes(headerBlock);
decodeHeaderBlock(cumulation, frame);
if (cumulation.isReadable()) {
cumulation.discardReadBytes();
} else {
releaseBuffer();
}
}
}
代码示例来源:origin: wildfly/wildfly
/**
* Initialized the internals from a new chunk
*
* @param content
* the new received chunk
* @throws ErrorDataDecoderException
* if there is a problem with the charset decoding or other
* errors
*/
@Override
public HttpPostMultipartRequestDecoder offer(HttpContent content) {
checkDestroyed();
// Maybe we should better not copy here for performance reasons but this will need
// more care by the caller to release the content in a correct manner later
// So maybe something to optimize on a later stage
ByteBuf buf = content.content();
if (undecodedChunk == null) {
undecodedChunk = buf.copy();
} else {
undecodedChunk.writeBytes(buf);
}
if (content instanceof LastHttpContent) {
isLastChunk = true;
}
parseBody();
if (undecodedChunk != null && undecodedChunk.writerIndex() > discardThreshold) {
undecodedChunk.discardReadBytes();
}
return this;
}
代码示例来源:origin: wildfly/wildfly
/**
* Initialized the internals from a new chunk
*
* @param content
* the new received chunk
* @throws ErrorDataDecoderException
* if there is a problem with the charset decoding or other
* errors
*/
@Override
public HttpPostStandardRequestDecoder offer(HttpContent content) {
checkDestroyed();
// Maybe we should better not copy here for performance reasons but this will need
// more care by the caller to release the content in a correct manner later
// So maybe something to optimize on a later stage
ByteBuf buf = content.content();
if (undecodedChunk == null) {
undecodedChunk = buf.copy();
} else {
undecodedChunk.writeBytes(buf);
}
if (content instanceof LastHttpContent) {
isLastChunk = true;
}
parseBody();
if (undecodedChunk != null && undecodedChunk.writerIndex() > discardThreshold) {
undecodedChunk.discardReadBytes();
}
return this;
}
代码示例来源:origin: wildfly/wildfly
private int decompress(ByteBufAllocator alloc, SpdyHeadersFrame frame) throws Exception {
ensureBuffer(alloc);
byte[] out = decompressed.array();
int off = decompressed.arrayOffset() + decompressed.writerIndex();
try {
int numBytes = decompressor.inflate(out, off, decompressed.writableBytes());
if (numBytes == 0 && decompressor.needsDictionary()) {
try {
decompressor.setDictionary(SPDY_DICT);
} catch (IllegalArgumentException ignored) {
throw INVALID_HEADER_BLOCK;
}
numBytes = decompressor.inflate(out, off, decompressed.writableBytes());
}
if (frame != null) {
decompressed.writerIndex(decompressed.writerIndex() + numBytes);
decodeHeaderBlock(decompressed, frame);
decompressed.discardReadBytes();
}
return numBytes;
} catch (DataFormatException e) {
throw new SpdyProtocolException("Received invalid header block", e);
}
}
代码示例来源:origin: lettuce-io/lettuce-core
@SuppressWarnings("unchecked")
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf buffer) throws InterruptedException {
if (output.type() != null && !output.isCompleted()) {
if (!super.decode(buffer, output)) {
return;
}
RedisCommand<?, ?, ?> peek = getStack().peek();
canComplete(peek);
endpoint.notifyMessage(output);
output = new PubSubOutput<>(codec);
}
if (!getStack().isEmpty()) {
super.decode(ctx, buffer);
}
ReplayOutput<K, V> replay;
while ((replay = queue.poll()) != null) {
replay.replay(output);
endpoint.notifyMessage(output);
output = new PubSubOutput<>(codec);
}
while (super.getStack().isEmpty() && buffer.isReadable()) {
if (!super.decode(buffer, output)) {
return;
}
endpoint.notifyMessage(output);
output = new PubSubOutput<>(codec);
}
buffer.discardReadBytes();
}
内容来源于网络,如有侵权,请联系作者删除!