class SimpleImaBaselineGenerator {

    public final void updateBaselineFromCSVFile(final SimpleImaBaseline baseline,
            final InputStream inStream) throws IOException, ParseException,
            IMABaselineGeneratorException {

        if (baseline == null) {
            LOGGER.error("null argument: baseline");
            throw new NullPointerException("baseline");
        }
        if (inStream == null) {
            LOGGER.error("null argument: in");
            throw new NullPointerException("in");
        }

        String regex = "\"?(.*?)\"?,([a-fA-F0-9]{40})";
        Pattern p = Pattern.compile(regex);

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                inStream, "UTF8"));
        String dataRow;

        while ((dataRow = reader.readLine()) != null) {
            if (StringUtils.isBlank(dataRow)) {
                continue;
            }
            Matcher m = p.matcher(dataRow);
            if (!m.matches() || m.groupCount() != 2) {
                final String msg = "row does not match regex: " + dataRow;
                LOGGER.error(msg);
                throw new IMABaselineGeneratorException(msg);
            }

            String path = m.group(1);
            path = path.replace("\"\"", "\"");

            try {
                final byte[] hash = Hex.decodeHex(m.group(2).toCharArray());
                final Digest digest = new Digest(DigestAlgorithm.SHA1, hash);
                final IMABaselineRecord imaRecord = new IMABaselineRecord(path,
                        digest);
                baseline.addToBaseline(imaRecord);
                final String msg = String.format("added record %s", imaRecord);
                LOGGER.debug(msg);
            } catch (DecoderException e) {
                String msg = "File " + path + " has invalid hash sting.  "
                        + "Record not added to baseline";
                LOGGER.error(msg, e);
            }
        }
        reader.close();
    }

}