com.webbfontaine.fcvrutilization.utils.FileUtils.java Source code

Java tutorial

Introduction

Here is the source code for com.webbfontaine.fcvrutilization.utils.FileUtils.java

Source

package com.webbfontaine.fcvrutilization.utils;

import com.webbfontaine.fcvrutilization.AppPropertiesUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

/**
 * Copyrights 2002-2011 Webb Fontaine
 * This software is the proprietary information of Webb Fontaine.
 * Its use is subject to License terms.
 * Developer: nigiyan
 * Date: 04/11/2011
 */

public class FileUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);

    public static String resolveTableName(File file) {

        if (!file.isFile()) {
            throw new RuntimeException("Not a file: " + file.getName());
        }

        if (file.getName().toLowerCase().contains("header")) {
            return "BE_GCNET_HEADER";
        }

        if (file.getName().toLowerCase().contains("item")) {
            return "BE_GCNET_ITEMS";
        }

        throw new RuntimeException("Can not resolve table name by filename");
    }

    public static void moveFilesFromInToOut() {
        LOGGER.info("Moving files to out folder...");
        Collection<File> files = getFilesFromIn();

        File outDir = new File(AppPropertiesUtils.getOutFolderPath());

        for (File file : files) {
            try {
                org.apache.commons.io.FileUtils.moveToDirectory(file, outDir, true);
            } catch (IOException e) {
                LOGGER.error("Unable to move file to out folder", e);
                throw new RuntimeException(e);
            }
        }
        LOGGER.info("{} files moved.", files.size());
    }

    public static Collection<File> getFilesFromIn() {
        return org.apache.commons.io.FileUtils.listFiles(new File(AppPropertiesUtils.getTmpFolderPath()),
                new String[] { "xml", "XML" }, false);
    }
}