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

xerial.larray.buffer.WritableChannelWrap Maven / Gradle / Ivy

There is a newer version: 0.4.1
Show newest version
package xerial.larray.buffer;

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

import static xerial.larray.buffer.UnsafeUtil.unsafe;

/**
 * @author Taro L. Saito
 */
class WritableChannelWrap implements WritableByteChannel {

    private final LBuffer b;
    int cursor = 0;

    WritableChannelWrap(LBuffer b) {
        this.b = b;
    }

    @Override
    public int write(ByteBuffer src) throws IOException {
        int len = (int) Math.max(src.limit() - src.position(), 0);
        int writeLen = 0;
        if(src.isDirect()) {
            src.put(b.toDirectByteBuffer(cursor, len));
            writeLen = len;
        }
        else if(src.hasArray()) {
            writeLen = b.readFrom(src.array(), src.position(), cursor, len);
        }
        else {
            for(long i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy