private void copy(File file, OutputStream output, Range r) throws IOException {

        if (isAsciidocFile(file)) {
            String content = IOHelper.readFile(file.toPath());
            String cachedCharset= IOHelper.getCachedCharset(file.toPath());
            output.write(content.getBytes(cachedCharset));
        } else {
            RandomAccessFile input = new RandomAccessFile(file, "r");
            byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
            int read;

            try {
                if (input.length() == r.length) {
                    // Write full range.
                    while ((read = input.read(buffer)) > 0) {
                        output.write(buffer, 0, read);
                    }
                } else {
                    // Write partial range.
                    input.seek(r.start);
                    long toRead = r.length;

                    while ((read = input.read(buffer)) > 0) {
                        if ((toRead -= read) > 0) {
                            output.write(buffer, 0, read);
                        } else {
                            output.write(buffer, 0, (int) toRead + read);
                            break;
                        }
                    }
                }
            } finally {
                close(input);
            }
        }

    }
Copy the given byte range of the given input to the given output.

@throws IOException If something fails at I/O level.
src/main/java/com/kodedu/controller/FileService.java