private void copy(CacheData input, OutputStream output, long start, long length)
            throws IOException {
        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
        int read;

        if (input.length() == length) {
            // Write full range.
            while ((read = input.read(buffer)) > 0) {
                output.write(buffer, 0, read);
            }
        } else {
            // Write partial range.
            input.seek(start);
            long toRead = 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;
                }
            }
        }
    }
Copy the given byte range of the given input to the given output.

@param input  The input to copy the given range to the given output for.
@param output The output to copy the given range from the given input for.
@param start  Start of the byte range.
@param length Length of the byte range.
@throws IOException If something fails at I/O level.
src/main/java/com/kodedu/controller/CacheResource.java