<commit_before>package com.dg.helpers;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * Created by <NAME> (<EMAIL>)
 *
 * Utilities for handling Files
 */
public class FileHelper
{
    @SuppressWarnings("ResultOfMethodCallIgnored")
    public static boolean moveTo(File from, File to)
    {
        if (from.exists())
        {
            if (from.renameTo(to))
            {
                return true;
            }

            try
            {
                to.delete();
                to.createNewFile();

                FileChannel source = null;
                FileChannel destination = null;
                try
                {
                    source = new FileInputStream(from).getChannel();
                    destination = new FileOutputStream(to).getChannel();
                    destination.transferFrom(source, 0, source.size());
                }
                finally
                {
                    if (source != null)
                    {
                        source.close();
                    }
                    if (destination != null)
                    {
                        destination.close();
                    }
                }
            }
            catch (IOException e)
            {
                // Could not copy the file over.
                to.delete();
                return false;
            }
        }

        return true;
    }
}<commit_msg>Added throwing and non-throwing variations of moveTo and copyTo<commit_after>package com.dg.helpers;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * Created by <NAME> (<EMAIL>)
 *
 * Utilities for handling Files
 */
public class FileHelper
{
    /**
     * Move a file, even across volumes.
     * Overwrites existing files.
     * Does not throw on failure.
     * @param from origin path
     * @param to destination path
     * @return true if successful
     */
    public static boolean move(File from, File to)
    {
        return move(from, to, true);
    }

    /**
     * Move a file, even across volumes.
     * Does not throw on failure.
     * @param from origin path
     * @param to destination path
     * @param overwrite should we overwrite existing files?
     * @return true if successful
     */
    public static boolean move(File from, File to, boolean overwrite)
    {
        try
        {
            moveWithExceptions(from, to, overwrite);
            return true;
        }
        catch (IOException ignore)
        {

        }
        return false;
    }

    /**
     * Move a file, even across volumes.
     * Overwrites existing files.
     * @param from origin path
     * @param to destination path
     * @throws IOException
     */
    public static void moveWithExceptions(File from, File to) throws IOException
    {
        moveWithExceptions(from, to, true);
    }

    /**
     * Move a file, even across volumes.
     * @param from origin path
     * @param to destination path
     * @param overwrite should we overwrite existing files?
     * @throws IOException
     */
    public static void moveWithExceptions(File from, File to, boolean overwrite) throws IOException
    {
        if (!from.exists())
        {
            throw new FileNotFoundException(String.format("'from' file was not found (%s).", from.toString()));
        }

        if (overwrite && to.exists())
        {
            if (!to.delete())
            {
                throw new IOException(String.format("'to' file was cannot be overwritten (%s).", to.toString()));
            }
        }
        if (from.renameTo(to))
        {
            return;
        }
        if (to.createNewFile())
        {
            FileChannel source = null;
            FileChannel destination = null;
            try
            {
                source = new FileInputStream(from).getChannel();
                destination = new FileOutputStream(to).getChannel();
                destination.transferFrom(source, 0, source.size());
            }
            catch (IOException ex)
            {
                //noinspection ResultOfMethodCallIgnored
                to.delete();
                throw ex;
            }
            finally
            {
                if (source != null)
                {
                    source.close();
                }
                if (destination != null)
                {
                    destination.close();
                }
                //noinspection ResultOfMethodCallIgnored
                from.delete();
            }
        }
        else
        {
            throw new IOException(String.format("'to' file was cannot be created (%s).", to.toString()));
        }
    }

    /**
     * Copy a file, even across volumes.
     * Overwrites existing files.
     * Does not throw on failure.
     * @param from origin path
     * @param to destination path
     * @return true if successful
     */
    public static boolean copy(File from, File to)
    {
        return copy(from, to, true);
    }

    /**
     * Copy a file, even across volumes.
     * Does not throw on failure.
     * @param from origin path
     * @param to destination path
     * @param overwrite should we overwrite existing files?
     * @return true if successful
     */
    public static boolean copy(File from, File to, boolean overwrite)
    {
        try
        {
            copyWithExceptions(from, to, overwrite);
            return true;
        }
        catch (IOException ignore)
        {

        }
        return false;
    }

    /**
     * Copy a file, even across volumes.
     * Overwrites existing files.
     * @param from origin path
     * @param to destination path
     * @throws IOException
     */
    public static void copyWithExceptions(File from, File to) throws IOException
    {
        copyWithExceptions(from, to, true);
    }

    /**
     * Copy a file, even across volumes.
     * @param from origin path
     * @param to destination path
     * @param overwrite should we overwrite existing files?
     * @throws IOException
     */
    public static void copyWithExceptions(File from, File to, boolean overwrite) throws IOException
    {
        if (!from.exists())
        {
            throw new FileNotFoundException(String.format("'from' file was not found (%s).", from.toString()));
        }

        if (overwrite && to.exists())
        {
            if (!to.delete())
            {
                throw new IOException(String.format("'to' file was cannot be overwritten (%s).", to.toString()));
            }
        }
        if (to.createNewFile())
        {
            FileChannel source = null;
            FileChannel destination = null;
            try
            {
                source = new FileInputStream(from).getChannel();
                destination = new FileOutputStream(to).getChannel();
                destination.transferFrom(source, 0, source.size());
            }
            catch (IOException ex)
            {
                //noinspection ResultOfMethodCallIgnored
                to.delete();
                throw ex;
            }
            finally
            {
                if (source != null)
                {
                    source.close();
                }
                if (destination != null)
                {
                    destination.close();
                }
            }
        }
        else
        {
            throw new IOException(String.format("'to' file was cannot be created (%s).", to.toString()));
        }
    }
}
{'fraction_non_alphanumeric': 0.0927755678172719, 'fraction_numerical': 0.00038496086231233157, 'mean_word_length': 1.4167441860465115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6266341', 'n_tokens_mistral': 1955, 'n_tokens_neox': 1870, 'n_words': 570}