class HeadHandler implements Executor.StreamHandler {
    private final int maxLines;

    private final List<String> lines = new ArrayList<>();
    private final Charset charset;

    private static final int BUFFERED_READER_SIZE = 200;

    /**
     * Charset of the underlying reader is set to UTF-8.
     * @param maxLines maximum number of lines to store
     */
    public HeadHandler(int maxLines) {
        this.maxLines = maxLines;
        this.charset = StandardCharsets.UTF_8;
    }

    /**
     * @param maxLines maximum number of lines to store
     * @param charset character set
     */
    public HeadHandler(int maxLines, Charset charset) {
        this.maxLines = maxLines;
        this.charset = charset;
    }

    /**
     * @return number of lines read
     */
    public int count() {
        return lines.size();
    }

    /**
     * @param index index
     * @return line at given index. Will be non {@code null} for valid index.
     */
    public String get(int index) {
        return lines.get(index);
    }

    // for testing
    static int getBufferedReaderSize() {
        return BUFFERED_READER_SIZE;
    }

    @Override
    public void processStream(InputStream input) throws IOException {<FILL_FUNCTION_BODY>}
}

        try (BufferedInputStream bufStream = new BufferedInputStream(input);
        BufferedReader reader = new BufferedReader(new InputStreamReader(bufStream, this.charset),
                BUFFERED_READER_SIZE)) {
            int lineNum = 0;
            while (lineNum < maxLines) {
                String line = reader.readLine();
                if (line == null) { // EOF
                    return;
                }
                lines.add(line);
                lineNum++;
            }

            // Read and forget the rest.
            byte[] buf = new byte[1024];
            while ((bufStream.read(buf)) != -1) {
                ;
            }
        }
    
<no_super_class>