All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.appconn.channel.WriteDirectByteArrayBuffer Maven / Gradle / Ivy

package org.appconn.channel;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.WritableByteChannel;

/**
 * appconn WriteBuffer DirectByteArray implementation.
 */
final class WriteDirectByteArrayBuffer extends WriteHeapByteBuffer {

    WriteDirectByteArrayBuffer(WritableByteChannel channel, int length) {
        super(channel);
        buffer = new byte[length];
        byteBuffer = ByteBuffer.allocateDirect(length);
        byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    }

    public void flush() throws IOException {
        byteBuffer.put(buffer, 0, position);
        byteBuffer.flip();
        while (byteBuffer.hasRemaining()) channel.write(byteBuffer);
        position = 0;
        byteBuffer.clear();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy