Java Code Examples for java.nio.channels.GatheringByteChannel#write()

The following examples show how to use java.nio.channels.GatheringByteChannel#write() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: UnpooledUnsafeDirectByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 3
Source File: ReadOnlyPooledHeapByteBuf.java    From spring-boot-protocol with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 4
Source File: QpidByteBufferFactory.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
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()]));
}
 
Example 5
Source File: UnpooledHeapByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 6
Source File: ReadOnlyByteBufferBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: UnpooledUnsafeDirectByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 8
Source File: CompositeByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 9
Source File: DataTransfer.java    From qmq with Apache License 2.0 5 votes vote down vote up
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    GatheringByteChannel channel = (GatheringByteChannel) target;
    long write = channel.write(this.buffers);
    transferred += write;
    return write;
}
 
Example 10
Source File: UnpooledHeapByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 11
Source File: UnpooledDirectByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: FixedCompositeByteBuf.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 13
Source File: CompositeByteBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@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;
        }
    }
}
 
Example 14
Source File: NetworkBuffer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source File: PullMessageProcessor.java    From qmq with Apache License 2.0 5 votes vote down vote up
@Override
public long transferTo(WritableByteChannel target, long position) throws IOException {
    GatheringByteChannel channel = (GatheringByteChannel) target;
    long write = channel.write(this.buffers);
    transferred += write;
    return write;
}
 
Example 16
Source File: ReadOnlyByteBufferBuf.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 17
Source File: HeapChannelBuffer.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public int getBytes(int index, GatheringByteChannel out, int length)
    throws IOException {
    return out.write(ByteBuffer.wrap(array, index, length));
}
 
Example 18
Source File: HeapChannelBuffer.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public int getBytes(int index, GatheringByteChannel out, int length)
    throws IOException {
    return out.write(ByteBuffer.wrap(array, index, length));
}
 
Example 19
Source File: IncrementalChunkBuffer.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
  return channel.write(buffers.toArray(new ByteBuffer[0]));
}
 
Example 20
Source File: ChunkBufferImplWithByteBufferList.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public long writeTo(GatheringByteChannel channel) throws IOException {
  long bytes = channel.write(buffers.toArray(new ByteBuffer[0]));
  findCurrent();
  return bytes;
}