<commit_before>package ejf;

import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.text.edits.TextEdit;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Properties;

public class Main {

    public static void main(final String[] args) {
        if (args.length < 2) {
            System.err.println("usage: eclipse-formatter <style.xml> <file1.java> <file2.java> ...");
            System.exit(1);
        }
        boolean someFailed = false;
        for (final String f : Arrays.copyOfRange(args, 1, args.length)) try {
            write(f, format(props(args[0]), read(f)));
        } catch (Exception e) {
            System.err.println(e.toString() + ": " + f);
            someFailed = true;
        }
        if (someFailed) System.exit(2);
    }

    private static String read(final String path) throws IOException {
        return new String(Files.readAllBytes(Paths.get(path)));
    }

    private static void write(final String path, final String content) throws IOException {
        Files.write(Paths.get(path), content.getBytes());
    }

    private static String format(final Properties options, final String input) throws BadLocationException {
        final CodeFormatter formatter = new DefaultCodeFormatter(options);
        final IDocument doc = new Document();
        doc.set(input);
        final TextEdit edit = formatter.format(
                CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
                input, 0, input.length(), 0, "\n");
        if (edit == null) throw new RuntimeException("formatting failed");
        edit.apply(doc);
        return doc.get();
    }

    private static Properties props(final String xmlFile) {
        return new Properties();
    }

}<commit_msg>Do not create new CodeFormatters for each file<commit_after>package ejf;

import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.text.edits.TextEdit;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilderFactory;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.Normalizer;
import java.util.Arrays;
import java.util.Properties;

public class Main {

    public static void main(final String[] args) {
        if (args.length < 2) {
            System.err.println("usage: eclipse-formatter <style.xml> <file1.java> <file2.java> ...");
            System.exit(1);
        }
        boolean someFailed = false;
        final Formatter fm = new Formatter(args[0]);
        for (final String f : Arrays.copyOfRange(args, 1, args.length))
            try {
                write(f, fm.format(read(f)));
            } catch (Exception e) {
                System.err.println(e.toString() + ": " + f);
                someFailed = true;
            }
        if (someFailed) System.exit(2);
    }

    private static String read(final String path) throws IOException {
        return new String(Files.readAllBytes(Paths.get(path)));
    }

    private static void write(final String path, final String content) throws IOException {
        Files.write(Paths.get(path), content.getBytes());
    }

    private static class Formatter {
        private final CodeFormatter formatter;

        public Formatter(final String xmlFile) {
            formatter = new DefaultCodeFormatter(props(xmlFile));
        }

        public String format(final String input) throws BadLocationException {
            final IDocument doc = new Document();
            doc.set(input);
            final TextEdit edit = formatter.format(
                    CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
                    input, 0, input.length(), 0, "\n");
            if (edit == null) throw new RuntimeException("formatting failed");
            edit.apply(doc);
            return doc.get();
        }

        private static Properties props(final String xmlFile) {
            return new Properties();
        }
    }


}
{'fraction_non_alphanumeric': 0.10979955456570156, 'fraction_numerical': 0.004677060133630289, 'mean_word_length': 2.696296296296296, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '6880391', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1231, 'n_words': 311}