<commit_before>package edu.ucdenver.ccp.common.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;

import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.io.output.WriterOutputStream;

import edu.ucdenver.ccp.common.file.CharacterEncoding;

/**
 * A utility class with the goal of providing methods that properly use/enforce character encoding
 * with regard to Input/Output Streams.
 * 
 * @author bill
 * 
 */
public class StreamUtil {

	/**
	 * Returns an <code>InputStream</code> that properly enforces character encoding
	 * 
	 * @param is
	 * @param encoding
	 * @return
	 */
	public static InputStream getEncodingSafeInputStream(InputStream is, CharacterEncoding encoding) {
		return new ReaderInputStream(new InputStreamReader(is, encoding.getDecoder()));
	}

	public static InputStream getEncodingSafeInputStream(File file, CharacterEncoding encoding)
			throws FileNotFoundException {
		return getEncodingSafeInputStream(new FileInputStream(file), encoding);
	}

	/**
	 * Returns an <code>OutputStream</code> that properly enforces character encoding
	 * 
	 * @param os
	 * @param encoding
	 * @return
	 */
	public static OutputStream getEncodingSafeOutputStream(OutputStream os, CharacterEncoding encoding) {
		return new WriterOutputStream(new OutputStreamWriter(os, encoding.getEncoder()));
	}

	public static OutputStream getEncodingSafeOutputStream(File file, CharacterEncoding encoding)
			throws FileNotFoundException {
		return getEncodingSafeOutputStream(new FileOutputStream(file), encoding);
	}

	/**
	 * Returns the input <code>InputStreamReader</code> to a <code>String</code>
	 * @param isr
	 * @return
	 * @throws IOException
	 */
	public static String toString(InputStreamReader isr) throws IOException {
		StringBuilder sb = new StringBuilder();
		try {
			Reader reader = new BufferedReader(isr);
			int ch;
			while ((ch = reader.read()) > -1)
				sb.append((char)ch);
			return sb.toString();
		} finally {
			if (isr != null)
				isr.close();
		}
	}

}
<commit_msg>Resolving Eclipse warnings. Added JavaDoc.<commit_after>package edu.ucdenver.ccp.common.io;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;

import org.apache.commons.io.input.ReaderInputStream;
import org.apache.commons.io.output.WriterOutputStream;

import edu.ucdenver.ccp.common.file.CharacterEncoding;

/**
 * A utility class with the goal of providing methods that properly use/enforce character encoding
 * with regard to Input/Output Streams.
 * 
 * @author bill
 * 
 */
public class StreamUtil {

	/**
	 * Returns an <code>InputStream</code> that properly enforces character encoding
	 * 
	 * @param is
	 * @param encoding
	 * @return
	 */
	public static InputStream getEncodingSafeInputStream(InputStream is, CharacterEncoding encoding) {
		return new ReaderInputStream(new InputStreamReader(is, encoding.getDecoder()));
	}

	/**
	 * Returns an <code>InputStream</code> from a file that properly enforces character encoding
	 * 
	 * @param file
	 * @param encoding
	 * @return
	 * @throws FileNotFoundException
	 */
	public static InputStream getEncodingSafeInputStream(File file, CharacterEncoding encoding)
			throws FileNotFoundException {
		return getEncodingSafeInputStream(new FileInputStream(file), encoding);
	}

	/**
	 * Returns an <code>OutputStream</code> that properly enforces character encoding
	 * 
	 * @param os
	 * @param encoding
	 * @return
	 */
	public static OutputStream getEncodingSafeOutputStream(OutputStream os, CharacterEncoding encoding) {
		return new WriterOutputStream(new OutputStreamWriter(os, encoding.getEncoder()));
	}

	/**
	 * Returns an <code>OutputStream</code> from a file that properly enforces character encoding
	 * 
	 * @param file
	 * @param encoding
	 * @return
	 * @throws FileNotFoundException
	 */
	public static OutputStream getEncodingSafeOutputStream(File file, CharacterEncoding encoding)
			throws FileNotFoundException {
		return getEncodingSafeOutputStream(new FileOutputStream(file), encoding);
	}

	/**
	 * Returns the input <code>InputStreamReader</code> to a <code>String</code>
	 * 
	 * @param isr
	 * @return
	 * @throws IOException
	 */
	public static String toString(InputStreamReader isr) throws IOException {
		StringBuilder sb = new StringBuilder();
		try {
			Reader reader = new BufferedReader(isr);
			int ch;
			while ((ch = reader.read()) > -1)
				sb.append((char) ch);
			return sb.toString();
		} finally {
			if (isr != null)
				isr.close();
		}
	}

}

{'fraction_non_alphanumeric': 0.09916534181240064, 'fraction_numerical': 0.000397456279809221, 'mean_word_length': 4.6423766816143495, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '413505', 'n_tokens_mistral': 1476, 'n_tokens_neox': 1341, 'n_words': 385}