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


Java ByteBufHolder类代码示例

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


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

示例1: format

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
private String format(ChannelHandlerContext ctx, String event, Object obj) {
    StringBuilder sb = new StringBuilder(ctx.channel().toString()).append(" ").append(event);
    if (obj instanceof ByteBuf) {
        ByteBuf buf = (ByteBuf) obj;
        sb.append(" ").append(buf.readableBytes()).append(" bytes\n").append(ByteBufUtil.prettyHexDump(buf));
    } else if (obj instanceof ByteBufHolder) {
        ByteBufHolder holder = (ByteBufHolder) obj;
        sb.append(" ")
            .append(holder.content().readableBytes())
            .append(" bytes\n")
            .append(String.valueOf(obj))
            .append("\n")
            .append(ByteBufUtil.prettyHexDump(holder.content()));
    } else {
        sb.append("\n").append(String.valueOf(obj));
    }

    return sb.toString();
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:20,代码来源:LoggingHandler.java

示例2: onChannel

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
private void onChannel(Object object, boolean incoming) {
    ByteBuf bytes = null;
    if (object instanceof ByteBuf) {
        bytes = ((ByteBuf) object);
    } else if (object instanceof ByteBufHolder) {
        bytes = ((ByteBufHolder) object).content();
    }

    if (bytes != null) {
        int readableBytes = bytes.readableBytes();
        if (incoming) {
            incomingBytes.getAndAdd(readableBytes);
        } else {
            outgoingBytes.getAndAdd(readableBytes);
        }
    }
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:18,代码来源:TrafficReader.java

示例3: deframe

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
/**
 * Adds the given data to this deframer and attempts delivery to the listener.
 *
 * @param data the raw data read from the remote endpoint. Must be non-null.
 * @param endOfStream if {@code true}, indicates that {@code data} is the end of the stream from
 *        the remote endpoint.  End of stream should not be used in the event of a transport
 *        error, such as a stream reset.
 * @throws IllegalStateException if {@link #close()} has been called previously or if
 *         this method has previously been called with {@code endOfStream=true}.
 */
public void deframe(HttpData data, boolean endOfStream) {
    requireNonNull(data, "data");
    checkNotClosed();
    checkState(!this.endOfStream, "Past end of stream");

    startedDeframing = true;

    if (!data.isEmpty()) {
        final ByteBuf buf;
        if (data instanceof ByteBufHolder) {
            buf = ((ByteBufHolder) data).content();
        } else {
            buf = alloc.buffer(data.length());
            buf.writeBytes(data.array(), data.offset(), data.length());
        }
        unprocessed.addComponent(true, buf);
    }

    // Indicate that all of the data for this stream has been received.
    this.endOfStream = endOfStream;
    deliver();
}
 
开发者ID:line,项目名称:armeria,代码行数:33,代码来源:ArmeriaMessageDeframer.java

示例4: channelRead

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
/**
 * Create a {@link NettyServerRequestAdapter} when a {@link HttpRequest} is received, and use
 * @ {@link UnicastContentSubject} to send the content as a request stream.
 */
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
	Class<?> messageClass = msg.getClass();
	if (HttpRequest.class.isAssignableFrom(messageClass)) {
		this.request = new NettyServerRequestAdapter((HttpRequest) msg, this.requestContent);
		super.channelRead(ctx, this.request);
	} else if (HttpContent.class.isAssignableFrom(messageClass)) {
		Assert.notNull(this.request);
		ByteBuf content = ((ByteBufHolder) msg).content();
		ByteBuffer nioBuffer = content.nioBuffer();
		this.requestContent.onNext(nioBuffer);
		if (LastHttpContent.class.isAssignableFrom(messageClass)) {
			this.requestContent.onCompleted();
		}
		// FIXME I need to make it works without that ...
		super.channelRead(ctx, this.request);
	} else {
		super.channelRead(ctx, msg);
	}
}
 
开发者ID:sdeleuze,项目名称:rxweb,代码行数:25,代码来源:NettyServerCodecHandlerAdapter.java

示例5: shouldLogByteBufHolderDataRead

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Test
public void shouldLogByteBufHolderDataRead() throws Exception {
    ByteBufHolder msg = new DefaultByteBufHolder(Unpooled.copiedBuffer("hello", CharsetUtil.UTF_8)) {
        @Override
        public String toString() {
            return "foobar";
        }
    };

    appender.doAppend(matchesLog(".+RECEIVED: foobar, 5B$"));
    replay(appender);
    EmbeddedChannel channel = new EmbeddedChannel(new LoggingHandler());
    channel.writeInbound(msg);
    verify(appender);

    ByteBufHolder handledMsg = channel.readInbound();
    assertThat(msg, is(sameInstance(handledMsg)));
    handledMsg.release();
    assertThat(channel.readInbound(), is(nullValue()));
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:21,代码来源:LoggingHandlerTest.java

示例6: startAsync

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Override
public void startAsync(final Executor executor, final Runnable runnable) {
  Channel channel = ctx.channel();
  channel.attr(NEED_FLUSH).set(false);
  channel.attr(ASYNC).set(true);

  ReferenceCounted body = ((ByteBufHolder) req).content();
  body.retain();
  executor.execute(() -> {
    try {
      runnable.run();
    } finally {
      body.release();
    }
  });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:17,代码来源:NettyRequest.java

示例7: channelRead

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    Class<?> recievedMsgClass = msg.getClass();

    if (io.netty.handler.codec.http.HttpResponse.class.isAssignableFrom(recievedMsgClass)) {
        @SuppressWarnings({"rawtypes", "unchecked"})
        HttpClientResponse rxResponse = new HttpClientResponse((io.netty.handler.codec.http.HttpResponse)msg, contentSubject);
        super.channelRead(ctx, rxResponse); // For FullHttpResponse, this assumes that after this call returns,
                                            // someone has subscribed to the content observable, if not the content will be lost.
    }

    if (HttpContent.class.isAssignableFrom(recievedMsgClass)) {// This will be executed if the incoming message is a FullHttpResponse or only HttpContent.
        ByteBuf content = ((ByteBufHolder) msg).content();
        if (content.isReadable()) {
            invokeContentOnNext(content);
        }
        if (LastHttpContent.class.isAssignableFrom(recievedMsgClass)) {
            if (null != requestProcessingObserver) {
                requestProcessingObserver.onCompleted();
            }
            contentSubject.onCompleted();
        }
    } else if(!io.netty.handler.codec.http.HttpResponse.class.isAssignableFrom(recievedMsgClass)){
        invokeContentOnNext(msg);
    }
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:27,代码来源:ClientRequestResponseConverter.java

示例8: channelRead

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    Class<?> recievedMsgClass = msg.getClass();

    if (io.netty.handler.codec.http.HttpRequest.class.isAssignableFrom(recievedMsgClass)) {
        @SuppressWarnings({"rawtypes", "unchecked"})
        HttpServerRequest rxRequest = new HttpServerRequest((io.netty.handler.codec.http.HttpRequest) msg, contentSubject);
        keepAlive = rxRequest.getHeaders().isKeepAlive();
        super.channelRead(ctx, rxRequest); // For FullHttpRequest, this assumes that after this call returns,
                                           // someone has subscribed to the content observable, if not the content will be lost.
    }

    if (HttpContent.class.isAssignableFrom(recievedMsgClass)) {// This will be executed if the incoming message is a FullHttpRequest or only HttpContent.
        ByteBuf content = ((ByteBufHolder) msg).content();
        invokeContentOnNext(content);
        if (LastHttpContent.class.isAssignableFrom(recievedMsgClass)) {
            contentSubject.onCompleted();
        }
    } else {
        invokeContentOnNext(msg);
    }
}
 
开发者ID:allenxwang,项目名称:RxNetty,代码行数:23,代码来源:ServerRequestResponseConverter.java

示例9: emmit

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
private void emmit(FluxSink<Message> emitter, String roomId) {
    HttpClient
            .create()
            .get("https://stream.gitter.im/v1/rooms/" + roomId + "/chatMessages",
                    (r) -> r.addHeader("Authorization", "Bearer 3cd4820adf59b6a7116f99d92f68a1b786895ce7"))
            .flatMapMany(HttpClientResponse::receiveContent)
            .map(ByteBufHolder::content)
            .filter(bb -> bb.capacity() > 2)
            .map(MessageEncoder::mapToMessage)
            .doOnNext(m -> System.out.println("Log Emit: " + m))
            .subscribe(emitter::next, emitter::error, emitter::complete);
}
 
开发者ID:OlegDokuka,项目名称:reactive-playing,代码行数:13,代码来源:ReactorGitterClient.java

示例10: channelRead

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Override
final public void channelRead(ChannelHandlerContext ctx, Object msg)
		throws Exception {
	if (msg == null || msg == Unpooled.EMPTY_BUFFER || msg instanceof EmptyByteBuf) {
		return;
	}
	try {
		ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
		if (ops != null) {
			ops.onInboundNext(ctx, msg);
		}
		else {
			if (log.isDebugEnabled()) {
				String loggingMsg = msg.toString();
				if (msg instanceof HttpResponse) {
					DecoderResult decoderResult = ((HttpResponse) msg).decoderResult();
					if (decoderResult.isFailure()) {
						log.debug("Decoding failed: " + msg + " : ", decoderResult.cause());
					}
				}
				if (msg instanceof ByteBufHolder) {
					loggingMsg = ((ByteBufHolder) msg).content()
					                                  .toString(Charset.defaultCharset());
				}
				log.debug("{} No ChannelOperation attached. Dropping: {}", ctx
						.channel().toString(), loggingMsg);
			}
			ReferenceCountUtil.release(msg);
		}
	}
	catch (Throwable err) {
		Exceptions.throwIfFatal(err);
		exceptionCaught(ctx, err);
		ReferenceCountUtil.safeRelease(msg);
	}
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:37,代码来源:ChannelOperationsHandler.java

示例11: readByte

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Override
public int readByte(ByteBufHolder chunk) {
    ByteBuf buf = chunk.content();
    if (buf.readableBytes() == 0) {
        return ChunkedInputStream.EOF;
    }
    return buf.readByte();
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:9,代码来源:ByteBufHolderAdapter.java

示例12: readBytes

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
@Override
public int readBytes(ByteBufHolder chunk, byte[] arr, int off, int len) {
    ByteBuf buf = chunk.content();
    int avail = buf.readableBytes();
    if (avail == 0) {
        return ChunkedInputStream.EOF;
    }
    int readed = Math.min(len, avail);
    buf.readBytes(arr, off, readed);
    return readed;
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:12,代码来源:ByteBufHolderAdapter.java

示例13: calculateSize

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
/**
 * Calculate the size of the given {@link Object}.
 *
 * This implementation supports {@link ByteBuf} and {@link ByteBufHolder}. Sub-classes may override this.
 *
 * @param msg
 *            the msg for which the size should be calculated.
 * @return size the size of the msg or {@code -1} if unknown.
 */
protected long calculateSize(Object msg) {
    if (msg instanceof ByteBuf) {
        return ((ByteBuf) msg).readableBytes();
    }
    if (msg instanceof ByteBufHolder) {
        return ((ByteBufHolder) msg).content().readableBytes();
    }
    return -1;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:19,代码来源:AbstractTrafficShapingHandler.java

示例14: amount

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
private static int amount(Object msg) {
    if (msg instanceof ByteBuf) {
        return ((ByteBuf) msg).readableBytes();
    }
    if (msg instanceof ByteBufHolder) {
        return ((ByteBufHolder) msg).content().readableBytes();
    }
    return 1;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:10,代码来源:ChunkedWriteHandler.java

示例15: formatMessage

import io.netty.buffer.ByteBufHolder; //导入依赖的package包/类
protected String formatMessage(String eventName, Object msg) {
    if (msg instanceof ByteBuf) {
        return formatByteBuf(eventName, (ByteBuf) msg);
    } else if (msg instanceof ByteBufHolder) {
        return formatByteBufHolder(eventName, (ByteBufHolder) msg);
    } else {
        return formatNonByteBuf(eventName, msg);
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:10,代码来源:LoggingHandler.java


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