protected long slurpFullFile()

in src/main/java/com/microsoft/azure/datalake/store/ADLFileInputStream.java [145:172]


    protected long slurpFullFile() throws IOException {
        if (log.isTraceEnabled()) {
            log.trace("ADLFileInputStream.slurpFullFile() - using client {} from file {}. At offset {}", client.getClientId(), filename, getPos());
        }

        if (buffer == null) {
            blocksize = (int) directoryEntry.length;
            buffer = new byte[blocksize];
        }

        //reset buffer to initial state - i.e., throw away existing data
        bCursor = (int) getPos();  // preserve current file offset (may not be 0 if app did a seek before first read)
        limit = 0;
        fCursor = 0;  // read from beginning
        int loopCount = 0;

        // if one OPEN request doesnt get full file, then read again at fCursor
        while (fCursor < directoryEntry.length) {
            int bytesRead = readInternal(fCursor, buffer, limit, blocksize - limit, true);
            limit += bytesRead;
            fCursor += bytesRead;

            // just to be defensive against infinite loops
            loopCount++;
            if (loopCount >= 10) { throw new IOException("Too many attempts in reading whole file " + filename); }
        }
        return fCursor;
    }