Example usage for org.apache.hadoop.fs ByteBufferUtil fallbackRead

List of usage examples for org.apache.hadoop.fs ByteBufferUtil fallbackRead

Introduction

In this page you can find the example usage for org.apache.hadoop.fs ByteBufferUtil fallbackRead.

Prototype

public static ByteBuffer fallbackRead(InputStream stream, ByteBufferPool bufferPool, int maxLength)
        throws IOException 

Source Link

Document

Perform a fallback read.

Usage

From source file:com.mellanox.r4h.DFSInputStream.java

License:Apache License

@Override
public synchronized ByteBuffer read(ByteBufferPool bufferPool, int maxLength, EnumSet<ReadOption> opts)
        throws IOException, UnsupportedOperationException {
    if (maxLength == 0) {
        return EMPTY_BUFFER;
    } else if (maxLength < 0) {
        throw new IllegalArgumentException("can't read a negative " + "number of bytes.");
    }//from ww w .  ja  v  a  2  s .  c om
    if ((blockReader == null) || (blockEnd == -1)) {
        if (pos >= getFileLength()) {
            return null;
        }
        /*
         * If we don't have a blockReader, or the one we have has no more bytes
         * left to read, we call seekToBlockSource to get a new blockReader and
         * recalculate blockEnd. Note that we assume we're not at EOF here
         * (we check this above).
         */
        if ((!seekToBlockSource(pos)) || (blockReader == null)) {
            throw new IOException("failed to allocate new BlockReader " + "at position " + pos);
        }
    }
    ByteBuffer buffer = null;
    if (dfsClient.getConf().getShortCircuitMmapEnabled()) {
        buffer = tryReadZeroCopy(maxLength, opts);
    }
    if (buffer != null) {
        return buffer;
    }
    buffer = ByteBufferUtil.fallbackRead(this, bufferPool, maxLength);
    if (buffer != null) {
        getExtendedReadBuffers().put(buffer, bufferPool);
    }
    return buffer;
}