<commit_before>// Copyright (C) 2011 jOVAL.org.  All rights reserved.
// This software is licensed under the AGPL 3.0 license available at http://www.joval.org/agpl_v3.txt

package org.joval.util;

import java.io.File;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Simple utility for computing checksums.
 *
 * @author <NAME>
 * @version %I% %G%
 */
public class Checksum {
    public enum Algorithm {
	MD5("MD5"),
	SHA1("SHA-1");

	String value;

	Algorithm(String value) {
	    this.value = value;
	}

	String value() {
	    return value;
	}
    }

    public static String getChecksum(File f, Algorithm algorithm) throws IOException {
	InputStream in = null;
	try {
	    in = new FileInputStream(f);
	    return getChecksum(in, algorithm);
	} finally {
	    try {
		if (in != null) {
		    in.close();
		}
	    } catch (IOException e) {
	    }
	}
    }

    public static String getChecksum(String data, Algorithm algorithm) throws IOException {
	return getChecksum(new ByteArrayInputStream(data.getBytes()), algorithm);
    }<commit_msg>Getting the checksum of a String should never generate an IOException.<commit_after>// Copyright (C) 2011 jOVAL.org.  All rights reserved.
// This software is licensed under the AGPL 3.0 license available at http://www.joval.org/agpl_v3.txt

package org.joval.util;

import java.io.File;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Simple utility for computing checksums.
 *
 * @author <NAME>
 * @version %I% %G%
 */
public class Checksum {
    public enum Algorithm {
	MD5("MD5"),
	SHA1("SHA-1");

	String value;

	Algorithm(String value) {
	    this.value = value;
	}

	String value() {
	    return value;
	}
    }

    public static String getChecksum(File f, Algorithm algorithm) throws IOException {
	InputStream in = null;
	try {
	    in = new FileInputStream(f);
	    return getChecksum(in, algorithm);
	} finally {
	    try {
		if (in != null) {
		    in.close();
		}
	    } catch (IOException e) {
	    }
	}
    }

    public static String getChecksum(String data, Algorithm algorithm) {
	try {
	    return getChecksum(new ByteArrayInputStream(data.getBytes()), algorithm);
	} catch (IOException e) {
	    throw new RuntimeException(e);
	}
    }
{'fraction_non_alphanumeric': 0.1127315727236894, 'fraction_numerical': 0.008671659440283799, 'mean_word_length': 3.460456942003515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2115005', 'n_tokens_mistral': 828, 'n_tokens_neox': 783, 'n_words': 225}