@SuppressWarnings("unused")
    protected int readFileWithMeta(final ByteBufferCollector buf, final String fileName, final Message fileMeta,
                                   long offset, final long maxCount) throws IOException, RetryAgainException {
        buf.expandIfNecessary();
        final String filePath = this.path + File.separator + fileName;
        final File file = new File(filePath);
        try (final FileInputStream input = new FileInputStream(file); final FileChannel fc = input.getChannel()) {
            int totalRead = 0;
            while (true) {
                final int nread = fc.read(buf.getBuffer(), offset);
                if (nread <= 0) {
                    return EOF;
                }
                totalRead += nread;
                if (totalRead < maxCount) {
                    if (buf.hasRemaining()) {
                        return EOF;
                    } else {
                        buf.expandAtMost((int) (maxCount - totalRead));
                        offset += nread;
                    }
                } else {
                    final long fsize = file.length();
                    if (fsize < 0) {
                        LOG.warn("Invalid file length {}", filePath);
                        return EOF;
                    }
                    if (fsize == offset + nread) {
                        return EOF;
                    } else {
                        return totalRead;
                    }
                }
            }
        }
    }
Read a file data form local dir by fileName.

@author boyan (boyan@alibaba-inc.com)

2018-Apr-06 9:25:12 PM
jraft-core/src/main/java/com/alipay/sofa/jraft/storage/io/LocalDirReader.java