<commit_before>package ch.softappeal.yass.util;

import org.junit.Assert;

import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class TestUtils {

  public interface Printer {
    void print(PrintWriter printer) throws Exception;
  }

  public static void compareFile(final String fileResourcePath, final Printer printer) {
    try {
      final PrintWriter writer = new PrintWriter(System.out);
      printer.print(writer);
      writer.flush();
      final CharArrayWriter buffer = new CharArrayWriter();
      try (PrintWriter out = new PrintWriter(buffer)) {
        printer.print(out);
      }
      final BufferedReader testReader = new BufferedReader(new CharArrayReader(buffer.toCharArray()));
      try (
        BufferedReader refReader = new BufferedReader(new InputStreamReader(
          new ClassLoaderResource(TestUtils.class.getClassLoader(), fileResourcePath).create(),
          StandardCharsets.UTF_8
        ))
      ) {
        while (true) {
          final String testLine = testReader.readLine();
          final String refLine = refReader.readLine();
          if ((testLine == null) && (refLine == null)) {
            return;
          }
          if ((testLine == null) || (refLine == null)) {
            throw new RuntimeException("files don't have same length");<commit_msg>Java 8 migration<commit_after>package ch.softappeal.yass.util;

import org.junit.Assert;

import java.io.BufferedReader;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class TestUtils {

  @FunctionalInterface
  public interface Printer {
    void print(PrintWriter printer) throws Exception;
  }

  public static void compareFile(final String fileResourcePath, final Printer printer) {
    try {
      final PrintWriter writer = new PrintWriter(System.out);
      printer.print(writer);
      writer.flush();
      final CharArrayWriter buffer = new CharArrayWriter();
      try (PrintWriter out = new PrintWriter(buffer)) {
        printer.print(out);
      }
      final BufferedReader testReader = new BufferedReader(new CharArrayReader(buffer.toCharArray()));
      try (
        BufferedReader refReader = new BufferedReader(new InputStreamReader(
          new ClassLoaderResource(TestUtils.class.getClassLoader(), fileResourcePath).create(),
          StandardCharsets.UTF_8
        ))
      ) {
        while (true) {
          final String testLine = testReader.readLine();
          final String refLine = refReader.readLine();
          if ((testLine == null) && (refLine == null)) {
            return;
          }
          if ((testLine == null) || (refLine == null)) {
            throw new RuntimeException("files don't have same length");
{'fraction_non_alphanumeric': 0.09816576086956522, 'fraction_numerical': 0.0010190217391304348, 'mean_word_length': 3.1246498599439776, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5446330', 'n_tokens_mistral': 784, 'n_tokens_neox': 778, 'n_words': 200}