private int readInternal()

in src/main/java/com/microsoft/azure/datalake/store/ADLFileInputStream.java [196:226]


    private int readInternal(long position, byte[] b, int offset, int length, boolean bypassReadAhead) throws IOException {
        boolean readAheadEnabled = true;
        if (readAheadEnabled && !bypassReadAhead && !client.disableReadAheads) {
            // try reading from read-ahead
            if (offset != 0) throw new IllegalArgumentException("readahead buffers cannot have non-zero buffer offsets");
            int receivedBytes;

            // queue read-aheads
            int numReadAheads = this.readAheadQueueDepth;
            long nextSize;
            long nextOffset = position;
            while (numReadAheads > 0 && nextOffset < directoryEntry.length) {
                nextSize = Math.min( (long)blocksize, directoryEntry.length-nextOffset);
                if (log.isTraceEnabled())
                    log.trace("Queueing readAhead for file " + filename + " offset " + nextOffset + " thread " + Thread.currentThread().getName());
                ReadBufferManager.getBufferManager().queueReadAhead(this, nextOffset, (int) nextSize);
                nextOffset = nextOffset + nextSize;
                numReadAheads--;
            }

            // try reading from buffers first
            receivedBytes = ReadBufferManager.getBufferManager().getBlock(this, position, length, b);
            if (receivedBytes > 0) return receivedBytes;

            // got nothing from read-ahead, do our own read now
            receivedBytes = readRemote(position, b, offset, length, false);
            return receivedBytes;
        } else {
            return readRemote(position, b, offset, length, false);
        }
    }