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


Java ByteBuf.internalNioBuffer方法代码示例

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


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

示例1: encode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public ByteBuf encode(Object in) throws IOException {
    ByteBuf bytes = null;
    try {
        LZ4Compressor compressor = factory.fastCompressor();
        bytes = innerCodec.getValueEncoder().encode(in);
        ByteBuffer srcBuf = bytes.internalNioBuffer(bytes.readerIndex(), bytes.readableBytes());
        
        int outMaxLength = compressor.maxCompressedLength(bytes.readableBytes());
        ByteBuf out = ByteBufAllocator.DEFAULT.buffer(outMaxLength + DECOMPRESSION_HEADER_SIZE);
        out.writeInt(bytes.readableBytes());
        ByteBuffer outBuf = out.internalNioBuffer(out.writerIndex(), out.writableBytes());
        int pos = outBuf.position();
        
        compressor.compress(srcBuf, outBuf);
        
        int compressedLength = outBuf.position() - pos;
        out.writerIndex(out.writerIndex() + compressedLength);
        return out;
    } finally {
        if (bytes != null) {
            bytes.release();
        }
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:26,代码来源:LZ4Codec.java

示例2: hashToBase64

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static String hashToBase64(ByteBuf objectState) {
    ByteBuffer bf = objectState.internalNioBuffer(objectState.readerIndex(), objectState.readableBytes());
    long h1 = LongHashFunction.farmUo().hashBytes(bf);
    long h2 = LongHashFunction.xx().hashBytes(bf);

    ByteBuf buf = ByteBufAllocator.DEFAULT.buffer((2 * Long.SIZE) / Byte.SIZE);
    try {
        buf.writeLong(h1).writeLong(h2);
        ByteBuf b = Base64.encode(buf);
        try {
            String s = b.toString(CharsetUtil.UTF_8);
            return s.substring(0, s.length() - 2);
        } finally {
            b.release();
        }
    } finally {
        buf.release();
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:20,代码来源:Hash.java

示例3: decode

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
public Object decode(ByteBuf buf, State state) throws IOException {
    int decompressSize = buf.readInt();
    ByteBuf out = ByteBufAllocator.DEFAULT.buffer(decompressSize);
    try {
        LZ4SafeDecompressor decompressor = factory.safeDecompressor();
        ByteBuffer outBuffer = out.internalNioBuffer(out.writerIndex(), out.writableBytes());
        int pos = outBuffer.position();
        decompressor.decompress(buf.internalNioBuffer(buf.readerIndex(), buf.readableBytes()), outBuffer);
        int compressedLength = outBuffer.position() - pos;
        out.writerIndex(compressedLength);
        return innerCodec.getValueDecoder().decode(out, state);
    } finally {
        out.release();
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:LZ4Codec.java

示例4: doReadMessages

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    DatagramChannel ch = javaChannel();
    ChannelConfig config = config();
    RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();

    ByteBuf data = allocHandle.allocate(config.getAllocator());
    allocHandle.attemptedBytesRead(data.writableBytes());
    boolean free = true;
    try {
        ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
        int pos = nioData.position();
        int read = ch.read(nioData);
        if (read <= 0) {
            return read;
        }

        allocHandle.lastBytesRead(nioData.position() - pos);
        buf.add(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    } finally {
        if (free) {
            data.release();
        }
    }
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:31,代码来源:UkcpClientUdpChannel.java

示例5: doReadMessages

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected int doReadMessages(List<Object> buf) throws Exception {
    DatagramChannel ch = javaChannel();
    UkcpServerChannelConfig config = config();
    RecvByteBufAllocator.Handle allocHandle = unsafe().recvBufAllocHandle();

    ByteBuf data = allocHandle.allocate(config.getAllocator());
    allocHandle.attemptedBytesRead(data.writableBytes());
    boolean free = true;
    try {
        ByteBuffer nioData = data.internalNioBuffer(data.writerIndex(), data.writableBytes());
        int pos = nioData.position();
        InetSocketAddress remoteAddress = (InetSocketAddress) ch.receive(nioData);
        if (remoteAddress == null) {
            return 0;
        }

        allocHandle.lastBytesRead(nioData.position() - pos);
        buf.add(UkcpPacket.newInstance(data.writerIndex(data.writerIndex() + allocHandle.lastBytesRead()),
                remoteAddress));
        free = false;
        return 1;
    } catch (Throwable cause) {
        PlatformDependent.throwException(cause);
        return -1;
    } finally {
        if (free) {
            data.release();
        }
    }
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:32,代码来源:UkcpServerChannel.java

示例6: doWriteMessage

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
    UkcpPacket packet = (UkcpPacket) msg;
    InetSocketAddress remoteAddress = packet.remoteAddress();
    ByteBuf data = packet.content();

    final int dataLen = data.readableBytes();
    if (dataLen == 0) {
        return true;
    }

    final ByteBuffer nioData = data.internalNioBuffer(data.readerIndex(), dataLen);
    final int writtenBytes;
    writtenBytes = javaChannel().send(nioData, remoteAddress);
    return writtenBytes > 0;
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:17,代码来源:UkcpServerChannel.java

示例7: hash

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
public static byte[] hash(ByteBuf objectState) {
    ByteBuffer b = objectState.internalNioBuffer(objectState.readerIndex(), objectState.readableBytes());
    long h1 = LongHashFunction.farmUo().hashBytes(b);
    long h2 = LongHashFunction.xx().hashBytes(b);

    ByteBuf buf = ByteBufAllocator.DEFAULT.buffer((2 * Long.SIZE) / Byte.SIZE);
    try {
        buf.writeLong(h1).writeLong(h2);
        byte[] dst = new byte[buf.readableBytes()];
        buf.readBytes(dst);
        return dst;
    } finally {
        buf.release();
    }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:Hash.java

示例8: doWriteMessage

import io.netty.buffer.ByteBuf; //导入方法依赖的package包/类
@Override
protected boolean doWriteMessage(Object msg, ChannelOutboundBuffer in) throws Exception {
    ByteBuf data = (ByteBuf) msg;

    final int dataLen = data.readableBytes();
    if (dataLen == 0) {
        return true;
    }

    final ByteBuffer nioData = data.internalNioBuffer(data.readerIndex(), dataLen);
    final int writtenBytes;
    writtenBytes = javaChannel().write(nioData);
    return writtenBytes > 0;
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:15,代码来源:UkcpClientUdpChannel.java


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