Java Utililty Methods ByteBuffer Write

List of utility methods to do ByteBuffer Write

Description

The list of methods to do ByteBuffer Write are organized into topic(s).

Method

intwriteFully(@Nonnull final FileChannel dst, @Nonnull final ByteBuffer src, @Nonnegative final long position)
write Fully
int count = 0;
while (src.remaining() > 0) {
    count += dst.write(src, position + src.position());
return count;
voidwriteFully(ByteBuffer buf, WritableByteChannel out)
if we were to register for OP_WRITE and send the remaining data on readyOps for this channel we have to either block the caller thread or queue the message buffers that may arrive while waiting for OP_WRITE.
int written = 0;
int toWrite = buf.limit();
while (written < toWrite) {
    written += out.write(buf);
voidwriteFully(ByteBuffer buffer, WritableByteChannel channel)
Writes the entire remaining contents of the buffer to the channel.
while (buffer.hasRemaining()) {
    channel.write(buffer);
voidwriteFully(FileChannel channel, ByteBuffer fileInfosBuffer)
write Fully
while (fileInfosBuffer.hasRemaining()) {
    channel.write(fileInfosBuffer);
voidwriteFully(FileChannel channel, ByteBuffer src)
Fully write to the file.
do {
    channel.write(src);
} while (src.remaining() > 0);
voidwriteFully(FileChannel channel, long offset, ByteBuffer buf)
write Fully
int remaining = buf.limit() - buf.position();
while (remaining > 0) {
    int written = channel.write(buf, offset);
    if (written < 0)
        throw new EOFException();
    remaining -= written;
voidwriteFully(FileChannel fc, ByteBuffer buf, long offset)
Write a ByteBuffer to a FileChannel at a given offset, handling short writes.
do {
    offset += fc.write(buf, offset);
} while (buf.remaining() > 0);
voidwriteFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer)
write Fully
int startBufferPosition = buffer.position();
while (buffer.remaining() > 0) {
    fileChannel.write(buffer, filePosition + buffer.position() - startBufferPosition);
voidwriteFully(final FileChannel channel, final ByteBuffer dst, final long position)
write Fully
while (dst.remaining() > 0) {
    channel.write(dst, position + dst.position());
voidwriteFully(final WritableByteChannel channel, final ByteBuffer buf)
write Fully
do {
    int written = channel.write(buf);
    if (written < 0) {
        throw new EOFException();
} while (buf.hasRemaining());