<commit_before>package com.alexrnl.subtitlecorrector.io;

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.alexrnl.commons.error.ExceptionUtils;
import com.alexrnl.commons.io.IOUtils;
import com.alexrnl.subtitlecorrector.common.Subtitle;
import com.alexrnl.subtitlecorrector.common.SubtitleFile;

/**
 * Abstract class for a subtitle reader.<br />
 * @author Alex
 */
public abstract class SubtitleReader {
	/** Logger */
	private static Logger	lg	= Logger.getLogger(SubtitleReader.class.getName());
	
	/** The charset of the subtitle files read */
	private final Charset			charSet;
	
	/**
	 * Constructor #1.<br />
	 * Default constructor, uses {@link StandardCharsets#UTF_8 UTF-8} as charset.
	 */
	public SubtitleReader () {
		this(StandardCharsets.UTF_8);
	}
	
	/**
	 * Constructor #.<br />
	 * @param charSet
	 *        the character set to use for reading the subtitles.
	 */
	public SubtitleReader (final Charset charSet) {
		super();
		this.charSet = charSet;
	}

	/**
	 * Read the specified file and return the loaded {@link SubtitleFile}.<br />
	 * This method is synchronized, to avoid read files from different threads simultaneously.
	 * @param file
	 *        the file to read.<commit_msg>Add a method so implementation of SubtitleReader can get the character set<commit_after>package com.alexrnl.subtitlecorrector.io;

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;

import com.alexrnl.commons.error.ExceptionUtils;
import com.alexrnl.commons.io.IOUtils;
import com.alexrnl.subtitlecorrector.common.Subtitle;
import com.alexrnl.subtitlecorrector.common.SubtitleFile;

/**
 * Abstract class for a subtitle reader.<br />
 * @author Alex
 */
public abstract class SubtitleReader {
	/** Logger */
	private static Logger	lg	= Logger.getLogger(SubtitleReader.class.getName());
	
	/** The charset of the subtitle files read */
	private final Charset			charSet;
	
	/**
	 * Constructor #1.<br />
	 * Default constructor, uses {@link StandardCharsets#UTF_8 UTF-8} as charset.
	 */
	public SubtitleReader () {
		this(StandardCharsets.UTF_8);
	}
	
	/**
	 * Constructor #.<br />
	 * @param charSet
	 *        the character set to use for reading the subtitles.
	 */
	public SubtitleReader (final Charset charSet) {
		super();
		this.charSet = charSet;
	}
	
	/**
	 * Return the current character set used by this reader.
	 * @return the charset used.
	 */
	protected Charset getCharSet () {
		return charSet;
	}
	
	/**
	 * Read the specified file and return the loaded {@link SubtitleFile}.<br />
	 * This method is synchronized, to avoid read files from different threads simultaneously.
	 * @param file
	 *        the file to read.
{'fraction_non_alphanumeric': 0.10943517329910141, 'fraction_numerical': 0.0025673940949935813, 'mean_word_length': 3.8779342723004695, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3315995', 'n_tokens_mistral': 1007, 'n_tokens_neox': 943, 'n_words': 266}