<commit_before>package learntocode.javaapi.io_and_nio.nio;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Provide methods to create directories with files on you machine.
 * Is used in every class io and nio packages examples
 * <br>
 * Change directories in this file to ones you like better
 */ /*
public class FilesCreatorNIO {

    private static String dirIOFiles;
    private static String dirNIOFiles;

    private static String fileNameTemplate = "file_";

    public static String getDirNIOFiles() { return dirNIOFiles; }
    public static String getFileNameTemplate() { return fileNameTemplate; }

    public static void createFilesNIO() {
        createFiles(dirNIOFiles);
    }

    private static File[] createFiles(String dir) {
        int numOfFiles = 10;
        Path[] files = new Path[numOfFiles];
        Path directoryFile = Paths.get(dirIOFiles);
        //directoryFile.

        for (int i =0; i < numOfFiles; i++) {
            try {
                File f = new File(dirIOFiles, fileNameTemplate + i);
                if (f.exists()) {
                    f.delete();
                }
                System.out.print("Creating file " + f.getAbsolutePath() + " ... ");
                boolean fileCreated = f.createNewFile();
                if (!fileCreated) {
                    System.out.println(" ERROR! Could not create file " + fileNameTemplate + i + " in directory " + dirIOFiles);
                    break;
                } else {
                    files[i] = f;
                    System.out.println("Success!");
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Initialization finished. Your output: \n");
        return files;
    }


    private static void setDirsByOs() {
        String os = System.getProperty("os.name");
        if (os.startsWith("Windows")) {
            System.out.println("Current OS is Windows");
            String homeDrive = System.getProperty("user.home");
            dirNIOFiles = homeDrive + "\\test_files_nio";
        } else {
            dirNIOFiles = "/tmp/test_files_nio";
        }

        System.out.println("Setting test files directories to: \n" +
                "  NIO: " + dirNIOFiles);
    }
}
*/<commit_msg>Add FileCreatorNIO which uses Paths/Files nio classes to create directories<commit_after>package learntocode.javaapi.io_and_nio.nio;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * Provide methods to create directories with files on you machine.
 * Is used in every class io and nio packages examples
 * <br>
 * Change directories in this file to ones you like better
 */
public class FilesCreatorNIO {

    private static String dirNIOFiles;

    private static String fileNameTemplate = "file_";

    public static String getDirNIOFiles() { return dirNIOFiles; }
    public static String getFileNameTemplate() { return fileNameTemplate; }

    public static Path[] createFiles() {
        setDirsByOs();
        int numOfFiles = 10;
        Path[] files = new Path[numOfFiles];
        Path directoryFile = Paths.get(dirNIOFiles);
        try {
            Files.createDirectories(directoryFile);
        } catch (IOException e) {
            System.out.println("Could not create directories to" + directoryFile.toString());
            e.printStackTrace();
        }

        for (int i =0; i < numOfFiles; i++) {
            try {
                Path f = Paths.get(dirNIOFiles, fileNameTemplate + i);
                if (Files.exists(f)) {
                    Files.delete(f);
                }
                System.out.println("Creating file " + f.toString() + " ... Success!");
                files[i] = Files.createFile(f);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("Initialization finished. Your output: \n");
        return files;
    }


    private static void setDirsByOs() {
        String os = System.getProperty("os.name");
        if (os.startsWith("Windows")) {
            System.out.println("Current OS is Windows");
            String homeDrive = System.getProperty("user.home");
            dirNIOFiles = homeDrive + "\\test_files_nio";
        } else {
            dirNIOFiles = "/tmp/test_files_nio";
        }

        System.out.println("Setting test files directories to: \n" +
                "  NIO: " + dirNIOFiles);
    }
}
{'fraction_non_alphanumeric': 0.10734586794927853, 'fraction_numerical': 0.0013117621337997377, 'mean_word_length': 2.0318091451292246, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2893665', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1220, 'n_words': 336}