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


Java FileRegion.transfered方法代码示例

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


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

示例1: encode

import io.netty.channel.FileRegion; //导入方法依赖的package包/类
/**
 * Encode a message into a {@link io.netty.buffer.ByteBuf}. This method will be called for each written message that
 * can be handled by this encoder.
 *
 * @param ctx the {@link io.netty.channel.ChannelHandlerContext} which this {@link
 * io.netty.handler.codec.MessageToByteEncoder} belongs to
 * @param msg the message to encode
 * @param out the {@link io.netty.buffer.ByteBuf} into which the encoded message will be written
 * @throws Exception is thrown if an error occurs
 */
@Override
protected void encode(ChannelHandlerContext ctx, FileRegion msg, final ByteBuf out) throws Exception {
    WritableByteChannel writableByteChannel = new WritableByteChannel() {
        @Override
        public int write(ByteBuffer src) throws IOException {
            out.writeBytes(src);
            return out.capacity();
        }

        @Override
        public boolean isOpen() {
            return true;
        }

        @Override
        public void close() throws IOException {
        }
    };

    long toTransfer = msg.count();

    while (true) {
        long transferred = msg.transfered();
        if (toTransfer - transferred <= 0) {
            break;
        }
        msg.transferTo(writableByteChannel, transferred);
    }
}
 
开发者ID:apache,项目名称:rocketmq,代码行数:40,代码来源:FileRegionEncoder.java

示例2: doWrite

import io.netty.channel.FileRegion; //导入方法依赖的package包/类
@Override
protected void doWrite(ChannelOutboundBuffer in) throws Exception {
    for (;;) {
        Object msg = in.current();
        if (msg == null) {
            // nothing left to write
            break;
        }
        if (msg instanceof ByteBuf) {
            ByteBuf buf = (ByteBuf) msg;
            int readableBytes = buf.readableBytes();
            while (readableBytes > 0) {
                doWriteBytes(buf);
                int newReadableBytes = buf.readableBytes();
                in.progress(readableBytes - newReadableBytes);
                readableBytes = newReadableBytes;
            }
            in.remove();
        } else if (msg instanceof FileRegion) {
            FileRegion region = (FileRegion) msg;
            long transfered = region.transfered();
            doWriteFileRegion(region);
            in.progress(region.transfered() - transfered);
            in.remove();
        } else {
            in.remove(new UnsupportedOperationException(
                    "unsupported message type: " + StringUtil.simpleClassName(msg)));
        }
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:31,代码来源:AbstractOioByteChannel.java

示例3: doWriteFileRegion

import io.netty.channel.FileRegion; //导入方法依赖的package包/类
@Override
protected long doWriteFileRegion(FileRegion region) throws Exception {
    final long position = region.transfered();
    return region.transferTo(javaChannel(), position);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:6,代码来源:NioSocketChannel.java

示例4: checkEOF

import io.netty.channel.FileRegion; //导入方法依赖的package包/类
private static void checkEOF(FileRegion region) throws IOException {
    if (region.transfered() < region.count()) {
        throw new EOFException("Expected to be able to write " + region.count() + " bytes, " +
                               "but only wrote " + region.transfered());
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:7,代码来源:OioByteStreamChannel.java

示例5: doWriteFileRegion

import io.netty.channel.FileRegion; //导入方法依赖的package包/类
@Override
protected long doWriteFileRegion(FileRegion region) throws Exception {
    final long position = region.transfered();
    final long writtenBytes = region.transferTo(javaChannel(), position);
    return writtenBytes;
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:7,代码来源:NioSocketChannel.java


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