class CSVReader {

    public void read(BufferedReader reader, TableReader lineConsumer) {
        try {
            String line = reader.readLine();
            if (line == null) {
                return;
            }
            ImmutableList<String> header = Arrays.stream(line.split(COLUMN_DELIMITER, -1))
                    .collect(ImmutableList.toImmutableList());
            int headerLength = header.size();
            lineConsumer.consumeHeader(header);
            line = reader.readLine();
            while (line != null) {
                if (!line.isEmpty()) {
                    String[] splitLine = line.split(COLUMN_DELIMITER, -1);
                    Preconditions.checkState(splitLine.length == headerLength,
                            String.format("Line incompatible with header.%n Line: %s%n Header: %s", Arrays.toString(splitLine), header));
                    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
                    for (int i = 0; i < headerLength; i++) {
                        builder.put(header.get(i), splitLine[i]);
                    }
                    lineConsumer.consumeLine(builder.build());
                }
                line = reader.readLine();
            }
            lineConsumer.fileFinished();
            reader.close();
        } catch (IOException e) {
            logger.error("Failed to read file", e);
        }
    }

}