Example usage for org.apache.commons.io FileUtils forceMkdir

List of usage examples for org.apache.commons.io FileUtils forceMkdir

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils forceMkdir.

Prototype

public static void forceMkdir(File directory) throws IOException 

Source Link

Document

Makes a directory, including any necessary but nonexistent parent directories.

Usage

From source file:jenkins.plugins.livingdoc.ReportCollectorTest.java

@BeforeClass
public static void initBaseDir() throws IOException, URISyntaxException {

    URL dirUrl = ReportCollectorTest.class.getResource("ReportCollector");
    baseDir = new File(dirUrl.toURI());

    File localBuildDir = File.createTempFile("junit", "builddir");
    FileUtils.deleteQuietly(localBuildDir);
    FileUtils.forceMkdir(localBuildDir);
    buildDir = new FilePath(localBuildDir);
}

From source file:com.alibaba.jstorm.utils.JStormServerUtils.java

public static void downloadCodeFromMaster(Map conf, String localRoot, String masterCodeDir, String topologyId,
        boolean isSupervisor) throws IOException, TException {
    FileUtils.forceMkdir(new File(localRoot));
    FileUtils.forceMkdir(new File(StormConfig.stormlib_path(localRoot)));

    String localStormjarPath = StormConfig.stormjar_path(localRoot);
    String masterStormjarPath = StormConfig.stormjar_path(masterCodeDir);
    Utils.downloadFromMaster(conf, masterStormjarPath, localStormjarPath);

    String localStormcodePath = StormConfig.stormcode_path(localRoot);
    String masterStormcodePath = StormConfig.stormcode_path(masterCodeDir);
    Utils.downloadFromMaster(conf, masterStormcodePath, localStormcodePath);

    String localStormConfPath = StormConfig.stormconf_path(localRoot);
    String masterStormConfPath = StormConfig.stormconf_path(masterCodeDir);
    Utils.downloadFromMaster(conf, masterStormConfPath, localStormConfPath);

    Map stormConf = (Map) StormConfig.readLocalObject(topologyId, localStormConfPath);

    if (stormConf == null)
        throw new IOException("Get topology conf error: " + topologyId);

    List<String> libs = (List<String>) stormConf.get(GenericOptionsParser.TOPOLOGY_LIB_NAME);
    if (libs == null)
        return;//from  w  ww .  j  ava2  s.c  o m
    for (String libName : libs) {
        String localStromLibPath = StormConfig.stormlib_path(localRoot, libName);
        String masterStormLibPath = StormConfig.stormlib_path(masterCodeDir, libName);
        Utils.downloadFromMaster(conf, masterStormLibPath, localStromLibPath);
    }
}

From source file:net.certiv.antlr.project.util.Utils.java

public static boolean createDirs(String dir) {
    try {/*ww w .  j  a  v a2  s.  c  om*/
        FileUtils.forceMkdir(new File(dir));
    } catch (IOException e) {
        Log.error(Utils.class, "Failed to make directory for " + dir, e);
        return false;
    }
    return true;
}

From source file:com.intuit.cto.selfservice.service.Util.java

/**
 * Retrieve the directory located at the given path.
 * If this does not exist, create it//from  ww w  . j  a va2 s.co  m
 * If it is not a directory, or it is not readable, throw an Exception
 */
public static File getDirectory(String path) {
    File dir = new File(path);
    if (!dir.exists()) {
        try {
            FileUtils.forceMkdir(dir);
        } catch (IOException e) {
            throw new IllegalArgumentException("Unable to create new directory at path: " + path, e);
        }
    }
    if (dir.getAbsolutePath().trim().length() == 0) {
        throw new IllegalArgumentException(path + " is empty");
    }
    if (!dir.isDirectory()) {
        throw new IllegalArgumentException(path + " is not a directory");
    }
    if (!dir.canRead()) {
        throw new IllegalArgumentException(path + " is not a readable directory");
    }
    return dir;
}

From source file:eu.mrbussy.pdfsplitter.Splitter.java

/**
 * Split the given PDF file into multiple files using pages.
 * //w w  w. j  a  v a2s. c  o m
 * @param filename
 *            - Name of the PDF to split
 * @param useSubFolder
 *            - Use a separate folder to place the files in.
 */
public static void Run(File file, boolean useSubFolder) {
    PdfReader reader = null;
    String format = null;

    if (useSubFolder) {
        format = "%1$s%2$s%4$s"; // Directory format
        try {
            FileUtils.forceMkdir(
                    new File(String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()),
                            FilenameUtils.getBaseName(file.getAbsolutePath()),
                            FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        format = "%1$s%2$s%4$s%2$s_%%03d.%3$s"; // Directory format + filename
    } else
        format = "%1$s%2$s_%%03d.%3$s";

    String splitFile = String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()),
            FilenameUtils.getBaseName(file.getAbsolutePath()),
            FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR);

    try {
        reader = new PdfReader(new FileInputStream(file));

        if (reader.getNumberOfPages() > 0) {
            for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) {
                System.out.println(String.format(splitFile, pageNum));
                String filename = String.format(splitFile, pageNum);
                Document document = new Document(reader.getPageSizeWithRotation(1));
                PdfCopy writer = new PdfCopy(document, new FileOutputStream(filename));
                document.open();
                // Copy the page from the original
                PdfImportedPage page = writer.getImportedPage(reader, pageNum);
                writer.addPage(page);
                document.close();
                writer.close();
            }
        }
    } catch (Exception ex) {
        // TODO Implement exception handling
        ex.printStackTrace(System.err);
    } finally {
        if (reader != null)
            // Always close the stream
            reader.close();
    }
}

From source file:eu.planets_project.services.utils.DigitalObjectUtilsTests.java

@BeforeClass
public static void setup() throws IOException {
    work_folder = new File(DigitalObjectUtils.SYSTEM_TEMP_DIR, "DigitalObjectUtilsTest_TMP".toUpperCase());
    FileUtils.forceMkdir(work_folder);
}

From source file:edu.cornell.med.icb.goby.alignments.perms.TestPermutationWriter.java

@BeforeClass
public static void initializeTestDirectory() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Creating base test directory: " + BASE_TEST_DIR);
    }//from  w  w  w.ja  va2s .c om

    FileUtils.forceMkdir(new File(BASE_TEST_DIR));
}

From source file:com.carolinarollergirls.scoreboard.xml.AutoSaveScoreBoard.java

public synchronized void start() {
    try {//from w w w .j a  v a2s . c o m
        FileUtils.forceMkdir(new File(ScoreBoardManager.getDefaultPath(), DIRECTORY_NAME));
    } catch (IOException ioE) {
        ScoreBoardManager.printMessage(
                "WARNING: Unable to create auto-save directory '" + DIRECTORY_NAME + "' : " + ioE.getMessage());
        return;
    }
    Runnable r = new Runnable() {
        public void run() {
            backupAutoSavedFiles();
            ScoreBoardManager.printMessage("Starting auto-save");
            running = executor.scheduleWithFixedDelay(AutoSaveScoreBoard.this, 0, SAVE_DELAY, TimeUnit.SECONDS);
        }
    };
    running = executor.schedule(r, SAVE_DELAY, TimeUnit.SECONDS);
}

From source file:com.assemblade.opendj.OpenDJUtils.java

public static void initializeDatastore(String rootDirectory) throws IOException {
    File serverRoot = new File(rootDirectory);

    FileUtils.forceMkdir(serverRoot);
    FileUtils.forceMkdir(new File(rootDirectory + "/config"));
    FileUtils.forceMkdir(new File(rootDirectory + "/config/schema"));
    FileUtils.forceMkdir(new File(rootDirectory + "/config/upgrade"));
    FileUtils.forceMkdir(new File(rootDirectory + "/locks"));
    FileUtils.forceMkdir(new File(rootDirectory + "/logs"));
    FileUtils.forceMkdir(new File(rootDirectory + "/db"));

    extractFileIfNeeded("cat-config.ldif", rootDirectory + "/config/config.ldif");
    extractFileIfNeeded("wordlist.txt", rootDirectory + "/config/wordlist.txt");
    extractFileIfNeeded("admin-backend.ldif", rootDirectory + "/config/admin-backend.ldif");
    extractFileIfNeeded("config.ldif.8087", rootDirectory + "/config/upgrade/config.ldif.8087");
    extractFileIfNeeded("schema.ldif.8087", rootDirectory + "/config/upgrade/schema.ldif.8087");
    extractFileIfNeeded("00-core.ldif", rootDirectory + "/config/schema/00-core.ldif");
    extractFileIfNeeded("01-pwpolicy.ldif", rootDirectory + "/config/schema/01-pwpolicy.ldif");
    extractFileIfNeeded("02-config.ldif", rootDirectory + "/config/schema/02-config.ldif");
    extractFileIfNeeded("03-changelog.ldif", rootDirectory + "/config/schema/03-changelog.ldif");
    extractFileIfNeeded("03-rfc2713.ldif", rootDirectory + "/config/schema/03-rfc2713.ldif");
    extractFileIfNeeded("04-rfc2307bis.ldif", rootDirectory + "/config/schema/04-rfc2307bis.ldif");
    extractFileIfNeeded("07-assemblade.ldif", rootDirectory + "/config/schema/07-assemblade.ldif");
}

From source file:com.meltmedia.cadmium.core.config.impl.PropertiesWriterImpl.java

private static void ensureDirExists(String dir) throws IOException {
    File file = new File(dir);
    FileUtils.forceMkdir(file);
}