<commit_before>package handler;


import controller.MainScreenController;
import misc.Job;
import misc.Logger;

import java.io.File;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;

public class ArchiveHandler {
    /**
     * Compresses the specified handler while outputting the command-line
     * results to the screen.
     *
     * The resulting archive will bear the name of the input handler.
     * If the input handler is test.jpg, then the output archive will be test.jpg.7z
     * as an example.
     * @param job The Job being run.
     * @param selectedFile The file to compress.
     * @param controller The controller for the view in which the output text area resides.
     * @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
     * @return The compressed archive.
     */
    public File packFile(final Job job, final File selectedFile, final MainScreenController controller, final ConfigHandler configHandler) {
        // Basic command settings ripped from http://superuser.com/a/742034
        final StringBuilder stringBuilder = new StringBuilder();
        final Formatter formatter = new Formatter(stringBuilder, Locale.US);

        formatter.format("\"%s\" %s \"%s.%s\" \"%s%s.%s\"",
                        configHandler.getCompressionProgramPath(),
                        configHandler.getCompressionCommands(),
                        selectedFile.getAbsolutePath(),
                        configHandler.getDecodeFormat(),
                        job.getOutputDirectory(),
                        job.getName(),
                        configHandler.getDecodeFormat());

        controller.getView().getTextArea_output().appendText(stringBuilder.toString() + System.lineSeparator() + System.lineSeparator() + System.lineSeparator());

        CommandHandler.runProgram(stringBuilder.toString(), controller);

        // Return a File poingint to the newly created archive:
        final File file = new File(selectedFile.getAbsoluteFile() + "." + configHandler.getDecodeFormat());


        if(!file.exists()) {
            Logger.writeLog("Could not create " + file.getAbsolutePath() + " shutting down.", Logger.LOG_TYPE_ERROR);
            System.exit(1);
        }
        return file;
    }

    /**
     * Compresses the specified handler(s), while outputting the command-line
     * results to the screen, into a single archive.
     *
     * The resulting archive will bear the specified name.
     * @param job The Job being run.
     * @param selectedFiles The file(s) to compress.
     * @param controller The controller for the view in which the output text area resides.
     * @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
     * @return The compressed archive.
     */
    public File packFiles(final Job job, final List<File> selectedFiles, final MainScreenController controller, final ConfigHandler configHandler) {
        // Basic command settings ripped from http://superuser.com/a/742034
        final StringBuilder stringBuilder = new StringBuilder();
        final Formatter formatter = new Formatter(stringBuilder, Locale.US);

        formatter.format("\"%s\" %s \"%s.%s\"",
                        configHandler.getCompressionProgramPath(),
                        configHandler.getCompressionCommands(),
                        job.getName(),
                        job.getOutputDirectory());

        for(final File f : selectedFiles) {
            // todo If it's possible to do the below to lines with the formatter, then do so.
            stringBuilder.append(" ");
            stringBuilder.append("\"" + f.getAbsolutePath() + "\"");
        }

        controller.getView().getTextArea_output().appendText(stringBuilder.toString() + System.lineSeparator() + System.lineSeparator() + System.lineSeparator());

        CommandHandler.runProgram(stringBuilder.toString(), controller);

        // Return a File int to the newly created archive:
        final File file = new File(job.getName() + "." + configHandler.getDecodeFormat());

        if(!file.exists()) {
            Logger.writeLog("Could not create " + job.getName() + " shutting down.", Logger.LOG_TYPE_ERROR);
            System.exit(1);
        }

        return file;<commit_msg>Modified the sections of code that alter the text area to properly edit it.<commit_after>package handler;


import controller.MainScreenController;
import javafx.application.Platform;
import misc.Job;
import misc.Logger;

import java.io.File;
import java.util.Formatter;
import java.util.List;
import java.util.Locale;

public class ArchiveHandler {
    /**
     * Compresses the specified handler while outputting the command-line
     * results to the screen.
     *
     * The resulting archive will bear the name of the input handler.
     * If the input handler is test.jpg, then the output archive will be test.jpg.7z
     * as an example.
     * @param job The Job being run.
     * @param selectedFile The file to compress.
     * @param controller The controller for the view in which the output text area resides.
     * @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
     * @return The compressed archive.
     */
    public File packFile(final Job job, final File selectedFile, final MainScreenController controller, final ConfigHandler configHandler) {
        // Basic command settings ripped from http://superuser.com/a/742034
        final StringBuilder stringBuilder = new StringBuilder();
        final Formatter formatter = new Formatter(stringBuilder, Locale.US);

        formatter.format("\"%s\" %s \"%s.%s\" \"%s%s.%s\"",
                        configHandler.getCompressionProgramPath(),
                        configHandler.getCompressionCommands(),
                        selectedFile.getAbsolutePath(),
                        configHandler.getDecodeFormat(),
                        job.getOutputDirectory(),
                        job.getName(),
                        configHandler.getDecodeFormat());

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                controller.getView().getTextArea_output().appendText(stringBuilder.toString() + System.lineSeparator() + System.lineSeparator() + System.lineSeparator());
            }
        });

        CommandHandler.runProgram(stringBuilder.toString(), controller);

        // Return a File poingint to the newly created archive:
        final File file = new File(selectedFile.getAbsoluteFile() + "." + configHandler.getDecodeFormat());


        if(!file.exists()) {
            Logger.writeLog("Could not create " + file.getAbsolutePath() + " shutting down.", Logger.LOG_TYPE_ERROR);
            System.exit(1);
        }
        return file;
    }

    /**
     * Compresses the specified handler(s), while outputting the command-line
     * results to the screen, into a single archive.
     *
     * The resulting archive will bear the specified name.
     * @param job The Job being run.
     * @param selectedFiles The file(s) to compress.
     * @param controller The controller for the view in which the output text area resides.
     * @param configHandler The object that handles settings for encoding, decoding, compression, and a number of other features.
     * @return The compressed archive.
     */
    public File packFiles(final Job job, final List<File> selectedFiles, final MainScreenController controller, final ConfigHandler configHandler) {
        // Basic command settings ripped from http://superuser.com/a/742034
        final StringBuilder stringBuilder = new StringBuilder();
        final Formatter formatter = new Formatter(stringBuilder, Locale.US);

        formatter.format("\"%s\" %s \"%s.%s\"",
                        configHandler.getCompressionProgramPath(),
                        configHandler.getCompressionCommands(),
                        job.getName(),
                        job.getOutputDirectory());

        for(final File f : selectedFiles) {
            // todo If it's possible to do the below to lines with the formatter, then do so.
            stringBuilder.append(" ");
            stringBuilder.append("\"" + f.getAbsolutePath() + "\"");
        }

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                controller.getView().getTextArea_output().appendText(stringBuilder.toString() + System.lineSeparator() + System.lineSeparator() + System.lineSeparator());
            }
        });

        CommandHandler.runProgram(stringBuilder.toString(), controller);

        // Return a File int to the newly created archive:
        final File file = new File(job.getName() + "." + configHandler.getDecodeFormat());

        if(!file.exists()) {
            Logger.writeLog("Could not create " + job.getName() + " shutting down.", Logger.LOG_TYPE_ERROR);
            System.exit(1);
        }

        return file;
{'fraction_non_alphanumeric': 0.09748083242059145, 'fraction_numerical': 0.0032858707557502738, 'mean_word_length': 2.4971275373420148, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2966929', 'n_tokens_mistral': 2241, 'n_tokens_neox': 2143, 'n_words': 712}