类java.nio.channels.GatheringByteChannel源码实例Demo

下面列出了怎么用java.nio.channels.GatheringByteChannel的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: netty-4.1.22   文件: PooledUnsafeDirectByteBuf.java
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    checkIndex(index, length);
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = memory.duplicate();
    }
    index = idx(index);
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
源代码2 项目: netty-4.1.22   文件: PooledDirectByteBuf.java
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    checkIndex(index, length);
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = memory.duplicate();
    }
    index = idx(index);
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
源代码3 项目: Elasticsearch   文件: PagedBytesReference.java
@Override
public void writeTo(GatheringByteChannel channel) throws IOException {
    // nothing to do
    if (length == 0) {
        return;
    }

    int currentLength = length;
    int currentOffset = offset;
    BytesRef ref = new BytesRef();

    while (currentLength > 0) {
        // try to align to the underlying pages while writing, so no new arrays will be created.
        int fragmentSize = Math.min(currentLength, PAGE_SIZE - (currentOffset % PAGE_SIZE));
        boolean newArray = bytearray.get(currentOffset, fragmentSize, ref);
        assert !newArray : "PagedBytesReference failed to align with underlying bytearray. offset [" + currentOffset + "], size [" + fragmentSize + "]";
        Channels.writeToChannel(ref.bytes, ref.offset, ref.length, channel);
        currentLength -= ref.length;
        currentOffset += ref.length;
    }

    assert currentLength == 0;
}
 
源代码4 项目: IoTgo_Android_App   文件: ChannelEndPoint.java
public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
{
    int length=0;

    Buffer buf0 = header==null?null:header.buffer();
    Buffer buf1 = buffer==null?null:buffer.buffer();

    if (_channel instanceof GatheringByteChannel &&
        header!=null && header.length()!=0 && buf0 instanceof NIOBuffer &&
        buffer!=null && buffer.length()!=0 && buf1 instanceof NIOBuffer)
    {
        length = gatheringFlush(header,((NIOBuffer)buf0).getByteBuffer(),buffer,((NIOBuffer)buf1).getByteBuffer());
    }
    else
    {
        // flush header
        if (header!=null && header.length()>0)
            length=flush(header);

        // flush buffer
        if ((header==null || header.length()==0) &&
             buffer!=null && buffer.length()>0)
            length+=flush(buffer);

        // flush trailer
        if ((header==null || header.length()==0) &&
            (buffer==null || buffer.length()==0) &&
             trailer!=null && trailer.length()>0)
            length+=flush(trailer);
    }

    return length;
}
 
源代码5 项目: IoTgo_Android_App   文件: ChannelEndPoint.java
protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
{
    int length;

    synchronized(this)
    {
        // Adjust position indexs of buf0 and buf1
        bbuf0=bbuf0.asReadOnlyBuffer();
        bbuf0.position(header.getIndex());
        bbuf0.limit(header.putIndex());
        bbuf1=bbuf1.asReadOnlyBuffer();
        bbuf1.position(buffer.getIndex());
        bbuf1.limit(buffer.putIndex());

        _gather2[0]=bbuf0;
        _gather2[1]=bbuf1;

        // do the gathering write.
        length=(int)((GatheringByteChannel)_channel).write(_gather2);

        int hl=header.length();
        if (length>hl)
        {
            header.clear();
            buffer.skip(length-hl);
        }
        else if (length>0)
        {
            header.skip(length);
        }
    }
    return length;
}
 
源代码6 项目: flink   文件: NetworkBuffer.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
	// adapted from UnpooledDirectByteBuf:
	checkIndex(index, length);
	if (length == 0) {
		return 0;
	}

	ByteBuffer tmpBuf = memorySegment.wrap(index, length);
	return out.write(tmpBuf);
}
 
源代码7 项目: IoTgo_Android_App   文件: ChannelEndPoint.java
protected int gatheringFlush(Buffer header, ByteBuffer bbuf0, Buffer buffer, ByteBuffer bbuf1) throws IOException
{
    int length;

    synchronized(this)
    {
        // Adjust position indexs of buf0 and buf1
        bbuf0=bbuf0.asReadOnlyBuffer();
        bbuf0.position(header.getIndex());
        bbuf0.limit(header.putIndex());
        bbuf1=bbuf1.asReadOnlyBuffer();
        bbuf1.position(buffer.getIndex());
        bbuf1.limit(buffer.putIndex());

        _gather2[0]=bbuf0;
        _gather2[1]=bbuf1;

        // do the gathering write.
        length=(int)((GatheringByteChannel)_channel).write(_gather2);

        int hl=header.length();
        if (length>hl)
        {
            header.clear();
            buffer.skip(length-hl);
        }
        else if (length>0)
        {
            header.skip(length);
        }
    }
    return length;
}
 
源代码8 项目: netty4.0.27Learn   文件: CompositeByteBuf.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length)
        throws IOException {
    int count = nioBufferCount();
    if (count == 1) {
        return out.write(internalNioBuffer(index, length));
    } else {
        long writtenBytes = out.write(nioBuffers(index, length));
        if (writtenBytes > Integer.MAX_VALUE) {
            return Integer.MAX_VALUE;
        } else {
            return (int) writtenBytes;
        }
    }
}
 
源代码9 项目: netty-4.1.22   文件: PooledHeapByteBuf.java
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    checkIndex(index, length);
    index = idx(index);
    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = ByteBuffer.wrap(memory);
    }
    return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length));
}
 
源代码10 项目: netty-4.1.22   文件: UnpooledHeapByteBuf.java
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    ensureAccessible();
    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = ByteBuffer.wrap(array);
    }
    return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length));
}
 
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    ensureAccessible();
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = buffer.duplicate();
    }
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
源代码12 项目: netty-4.1.22   文件: ReadOnlyByteBufferBuf.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
    ensureAccessible();
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf = internalNioBuffer();
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    checkIndex(index, length);
    index = idx(index);
    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = ByteBuffer.wrap(array);
    }
    return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length));
}
 
源代码14 项目: qmq   文件: DataTransfer.java
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    GatheringByteChannel channel = (GatheringByteChannel) target;
    long write = channel.write(this.buffers);
    transferred += write;
    return write;
}
 
源代码15 项目: qmq   文件: PullMessageProcessor.java
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    GatheringByteChannel channel = (GatheringByteChannel) target;
    long write = channel.write(this.buffers);
    transferred += write;
    return write;
}
 
源代码16 项目: azeroth   文件: StreamReplier.java
private static Sink newSink(Object out) {
    if (out instanceof OutputStream) {
        return new OioSink((OutputStream) out);
    }
    if (out instanceof GatheringByteChannel) {
        return new NioSink((GatheringByteChannel) out);
    }
    throw new FastdfsException("unknown sink output type " + out.getClass().getName());
}
 
源代码17 项目: PHONK   文件: TransferLearningModel.java
/**
 * Writes the current values of the model parameters to a writable channel.
 *
 * The written values can be restored later using {@link #loadParameters(ScatteringByteChannel)},
 * under condition that the same underlying model is used.
 *
 * @param outputChannel where to write the parameters.
 * @throws IOException if an I/O error occurs.
 */
public void saveParameters(GatheringByteChannel outputChannel) throws IOException {
  parameterLock.readLock().lock();
  try {
    outputChannel.write(modelParameters);
    for (ByteBuffer buffer : modelParameters) {
      buffer.rewind();
    }
  } finally {
    parameterLock.readLock().unlock();
  }
}
 
源代码18 项目: qpid-broker-j   文件: QpidByteBufferFactory.java
static long write(GatheringByteChannel channel, Collection<QpidByteBuffer> qpidByteBuffers)
        throws IOException
{
    List<ByteBuffer> byteBuffers = new ArrayList<>();
    for (QpidByteBuffer qpidByteBuffer : qpidByteBuffers)
    {
        Collections.addAll(byteBuffers, getUnderlyingBuffers(qpidByteBuffer));
    }
    return channel.write(byteBuffers.toArray(new ByteBuffer[byteBuffers.size()]));
}
 
源代码19 项目: fastdfs-client   文件: StreamReplier.java
private static Sink newSink(Object out) {
    if (out instanceof OutputStream) {
        return new OioSink((OutputStream) out);
    }
    if (out instanceof GatheringByteChannel) {
        return new NioSink((GatheringByteChannel) out);
    }
    throw new FastdfsException("unknown sink output type " + out.getClass().getName());
}
 
源代码20 项目: netty4.0.27Learn   文件: UnpooledDirectByteBuf.java
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    ensureAccessible();
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = buffer.duplicate();
    }
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
源代码21 项目: netty4.0.27Learn   文件: PooledHeapByteBuf.java
private int getBytes(int index, GatheringByteChannel out, int length, boolean internal) throws IOException {
    checkIndex(index, length);
    index = idx(index);
    ByteBuffer tmpBuf;
    if (internal) {
        tmpBuf = internalNioBuffer();
    } else {
        tmpBuf = ByteBuffer.wrap(memory);
    }
    return out.write((ByteBuffer) tmpBuf.clear().position(index).limit(index + length));
}
 
源代码22 项目: netty4.0.27Learn   文件: ReadOnlyByteBufferBuf.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
    ensureAccessible();
    if (length == 0) {
        return 0;
    }

    ByteBuffer tmpBuf = internalNioBuffer();
    tmpBuf.clear().position(index).limit(index + length);
    return out.write(tmpBuf);
}
 
public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException {
   byte[] bytesToGet = new byte[length];
   getBytes(index, bytesToGet);
   return out.write(ByteBuffer.wrap(bytesToGet));
}
 
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
  long bytes = channel.write(buffers.toArray(new ByteBuffer[0]));
  findCurrent();
  return bytes;
}
 
源代码25 项目: dubbox   文件: HeapChannelBuffer.java
public int getBytes(int index, GatheringByteChannel out, int length)
    throws IOException {
    return out.write(ByteBuffer.wrap(array, index, length));
}
 
源代码26 项目: hadoop-ozone   文件: IncrementalChunkBuffer.java
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
  return channel.write(buffers.toArray(new ByteBuffer[0]));
}
 
源代码27 项目: Bats   文件: DrillBuf.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
  return udle.getBytes(index + offset, out, length);
}
 
源代码28 项目: Bats   文件: MutableWrappedByteBuf.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length)
    throws IOException {
  return buffer.getBytes(index, out, length);
}
 
源代码29 项目: Bats   文件: DeadBuf.java
@Override
public int readBytes(GatheringByteChannel out, int length) throws IOException {
  throw new UnsupportedOperationException(ERROR_MESSAGE);

}
 
源代码30 项目: netty4.0.27Learn   文件: PooledDirectByteBuf.java
@Override
public int getBytes(int index, GatheringByteChannel out, int length) throws IOException {
    return getBytes(index, out, length, false);
}
 
 类所在包
 类方法
 同包方法