<commit_before>//@@author A0163559U
package seedu.task.logic.commands;

import java.io.File;
import java.io.IOException;

import seedu.task.commons.core.Config;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.commons.util.ConfigUtil;
import seedu.task.logic.commands.exceptions.CommandException;

/**
 * Saves task data in the specified directory.
 */
public class SaveCommand extends Command {

    public static final String COMMAND_WORD = "save";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Saves all tasks in specified directory with specified file name. "
            + "Parameters: SAVE_LOCATION\n"
            + "Example: " + COMMAND_WORD
            + " /Users/username/Documents/TaskManager/taskmanager.xml";

    public static final String MESSAGE_SUCCESS = "Tasks saved in location: %1$s";
    public static final String MESSAGE_INVALID_SAVE_LOCATION = "This save location is invalid: %1$s";
    public static final String MESSAGE_NULL_SAVE_LOCATION = "A save location must be specified.";
    public static final String MESSAGE_DIRECTORY_SAVE_LOCATION = "A save location must also include the file name.";
    public static final String MESSAGE_SAVE_IO_EXCEPTION = "Failed to save file in location: %1$s";

    private final File toSave;
    /**
     * Creates an SaveCommand using raw values.
     *
     * @throws IllegalValueException if the save location is invalid
     * @throws IOException
     */
    public SaveCommand(String fileAsString) throws IllegalValueException {
        if (fileAsString == null || fileAsString.equals("")) {
            throw new IllegalValueException(MESSAGE_NULL_SAVE_LOCATION);
        }
        this.toSave = new File(fileAsString.trim());
        if (toSave.isDirectory()) {
            throw new IllegalValueException(MESSAGE_DIRECTORY_SAVE_LOCATION);
        }
        try {
            createSaveFile();
        } catch (IOException ioe) {
            ioe.printStackTrace();
            throw new IllegalValueException(String.format(MESSAGE_INVALID_SAVE_LOCATION, fileAsString));
        }

    }

    private boolean createSaveFile() throws IOException {
        boolean created = toSave.createNewFile();

        return created;
    }

    @Override
    public CommandResult execute() throws CommandException {<commit_msg>Use FileUtil create file<commit_after>//@@author A0163559U
package seedu.task.logic.commands;

import java.io.File;
import java.io.IOException;

import seedu.task.commons.core.Config;
import seedu.task.commons.exceptions.IllegalValueException;
import seedu.task.commons.util.ConfigUtil;
import seedu.task.commons.util.FileUtil;
import seedu.task.logic.commands.exceptions.CommandException;

/**
 * Saves task data in the specified directory.
 */
public class SaveCommand extends Command {

    public static final String COMMAND_WORD = "save";

    public static final String MESSAGE_USAGE = COMMAND_WORD
            + ": Saves all tasks in specified directory with specified file name. "
            + "Parameters: SAVE_LOCATION\n"
            + "Example: " + COMMAND_WORD
            + " /Users/username/Documents/TaskManager/taskmanager.xml";

    public static final String MESSAGE_SUCCESS = "Tasks saved in location: %1$s";
    public static final String MESSAGE_INVALID_SAVE_LOCATION = "This save location is invalid: %1$s";
    public static final String MESSAGE_NULL_SAVE_LOCATION = "A save location must be specified.";
    public static final String MESSAGE_DIRECTORY_SAVE_LOCATION = "A save location must also include the file name.";
    public static final String MESSAGE_SAVE_IO_EXCEPTION = "Failed to save file in location: %1$s";

    private final File toSave;
    /**
     * Creates an SaveCommand using raw values.
     *
     * @throws IllegalValueException if the save location is invalid
     * @throws IOException
     */
    public SaveCommand(String fileAsString) throws IllegalValueException {
        if (fileAsString == null || fileAsString.equals("")) {
            throw new IllegalValueException(MESSAGE_NULL_SAVE_LOCATION);
        }
        this.toSave = new File(fileAsString.trim());
        if (toSave.isDirectory()) {
            throw new IllegalValueException(MESSAGE_DIRECTORY_SAVE_LOCATION);
        }
        try {
            createSaveFile();
        } catch (IOException ioe) {
            ioe.printStackTrace();
            throw new IllegalValueException(String.format(MESSAGE_INVALID_SAVE_LOCATION, fileAsString));
        }

    }

    private boolean createSaveFile() throws IOException {
        boolean created = FileUtil.createFile(toSave);

        return created;
    }

    @Override
    public CommandResult execute() throws CommandException {
{'fraction_non_alphanumeric': 0.08201560193970062, 'fraction_numerical': 0.00421674045962471, 'mean_word_length': 3.228163992869875, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3311875', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1254, 'n_words': 363}