<commit_before>﻿package org.crayonlang.interpreter;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.imageio.ImageIO;

public final class ResourceReader {
  private ResourceReader() {}
  
    private static final char[] BUFFER = new char[500]; 
    public static String readFileText(String path) {
        FileReader fileReader;
        try {
            fileReader = new FileReader(path);
        } catch (FileNotFoundException e) {
            throw new RuntimeException("File not found: " + path);
        }

        BufferedReader br = new BufferedReader(fileReader);
        StringBuilder sb = new StringBuilder();
        int bytesRead = 0;
        while (bytesRead != -1) {
            try {
                bytesRead = br.read(BUFFER);
            } catch (IOException e) {
                bytesRead = -1;
            }

            if (bytesRead != -1) {
                sb.append(BUFFER, 0, bytesRead);
            }
        }

        try {
            br.close();
        } catch (IOException e) {
        }

        String output = sb.toString();
		if (output.length() >= 3) {
          if (output.charAt(0) == 239 && output.charAt(1) == 187 && output.charAt(2) == 191) {
		    output = output.substring(3);
		  }
		}
		return output;
    }

    public static BufferedImage loadImageFromLocalFile(String path) {
		String resPath = "resources/" + path;
        try {
            return ImageIO.read(new File(resPath));
        } catch (IOException e) {
            return null;
        }
    }
}
<commit_msg>Fix unicode BOM trimming in Java apps.<commit_after>﻿package org.crayonlang.interpreter;

import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import javax.imageio.ImageIO;

public final class ResourceReader {
  private ResourceReader() {}
  
    private static final char[] BUFFER = new char[500]; 
    public static String readFileText(String path) {
        FileReader fileReader;
        try {
            fileReader = new FileReader(path);
        } catch (FileNotFoundException e) {
            throw new RuntimeException("File not found: " + path);
        }

        BufferedReader br = new BufferedReader(fileReader);
        StringBuilder sb = new StringBuilder();
        int bytesRead = 0;
        while (bytesRead != -1) {
            try {
                bytesRead = br.read(BUFFER);
            } catch (IOException e) {
                bytesRead = -1;
            }

            if (bytesRead != -1) {
                sb.append(BUFFER, 0, bytesRead);
            }
        }

        try {
            br.close();
        } catch (IOException e) {
        }

        String output = sb.toString();
		if (output.length() >= 3) {
        	if (output.charAt(0) == 239 && output.charAt(1) == 187 && output.charAt(2) == 191) {
				output = output.substring(3);
			}
		}

		if (output.length() > 0 && output.charAt(0) == 65279) {
			output = output.substring(1);
		}
		
		return output;
    }

    public static BufferedImage loadImageFromLocalFile(String path) {
		String resPath = "resources/" + path;
        try {
            return ImageIO.read(new File(resPath));
        } catch (IOException e) {
            return null;
        }
    }
}

{'fraction_non_alphanumeric': 0.11197916666666667, 'fraction_numerical': 0.015046296296296295, 'mean_word_length': 2.0139494333042722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '3512038', 'n_tokens_mistral': 1051, 'n_tokens_neox': 977, 'n_words': 247}