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:me.springframework.di.maven.BeanFactoryGeneratorMojo.java

/**
 * Makes sure the target directory exists.
 * /*ww  w .ja  va2s  .c o  m*/
 * @throws MojoExecutionException If the target directory cannot be created.
 */
private void ensureTargetDirectoryExists() throws MojoExecutionException {
    try {
        FileUtils.forceMkdir(targetDirectory);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to create target directory", e);
    }
}

From source file:com.magnet.tools.tests.CukeCommandExecutor.java

/**
 * Ctor//from w w w  .  j a  v  a2 s.c o m
 *
 * @param workingDirectory working directory for execution
 * @param async            whether to wait for command to return
 * @param subsMap          variables substitution
 * @param vars             variables where to save optional expression evaluation
 * @param testEnv          test environment
 * @param command          command line to execute
 * @throws java.io.IOException if an exception occurred
 */
public CukeCommandExecutor(String command, String workingDirectory, boolean async, Map<String, String> subsMap,
        Map<String, Object> vars, Map<String, String> testEnv) throws IOException {

    this.substitutionMap = subsMap;
    this.testEnvironment = testEnv;
    this.variables = vars;
    // Must get the existing environment so it inherits but overrides
    Map<String, String> env = new HashMap<String, String>(System.getenv());
    if (null != testEnvironment) {
        env.putAll(testEnvironment);
    }
    env.put("user.home", System.getProperty("user.home"));

    ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
    setWatchdog(watchdog);
    String[] args = command.split("\\s+");
    commandLine = new CommandLine(args[0]);
    if (args.length > 0) {
        for (int i = 1; i < args.length; i++) {
            commandLine.addArgument(args[i]);
        }
    }
    commandLine.setSubstitutionMap(substitutionMap);

    this.environment = env;
    this.command = command;
    this.async = async;
    setWorkingDirectory(new File(workingDirectory));
    String logFileName = command.replaceAll("[:\\.\\-\\s\\/\\\\]", "_");
    if (logFileName.length() > 128) {
        logFileName = logFileName.substring(0, 100);
    }
    this.logFile = new File(getWorkingDirectory(),
            "cuke_logs" + File.separator + +System.currentTimeMillis() + "-" + logFileName + ".log");

    FileUtils.forceMkdir(logFile.getParentFile());

    OutputStream outputStream = new FileOutputStream(logFile);
    this.teeOutputStream = new TeeOutputStream(outputStream, System.out); // also redirected to stdout
    ExecuteStreamHandler streamHandler = new PumpStreamHandler(outputStream);
    this.setStreamHandler(streamHandler);
}

From source file:edu.uci.ics.pregelix.example.asterixdb.ConnectorTest.java

private static void setUpPregelix() throws Exception {
    ClusterConfig.setStorePath(PATH_TO_CLUSTER_STORE);
    ClusterConfig.setClusterPropertiesPath(PATH_TO_CLUSTER_PROPERTIES);
    cleanupStores();/*from  www . java 2 s  . c o m*/
    PregelixHyracksIntegrationUtil.init();

    System.setProperty(GlobalConfig.CONFIG_FILE_PROPERTY, TEST_CONFIG_FILE_NAME);

    LOGGER.info("Hyracks mini-cluster started");
    FileUtils.forceMkdir(new File(ACTUAL_RESULT_DIR));
    FileUtils.cleanDirectory(new File(ACTUAL_RESULT_DIR));
    startHDFS();
}

From source file:com.blockwithme.longdb.leveldb.LevelDBBackend.java

@Override
protected void openInternal(final Map<String, LevelDBDatabase> theDatabase) {
    theDatabase.clear();/* ww w.j a v  a2  s.co  m*/
    try {
        final File dataRoot = new File(rootFolder);
        if (!dataRoot.exists())
            FileUtils.forceMkdir(dataRoot);
        final String[] dataDirs = dataRoot.list(DirectoryFileFilter.INSTANCE);

        if (dataDirs != null && dataDirs.length > 0) {
            for (final String dir : dataDirs) {
                final String fullPath = dataRoot.getAbsolutePath() + File.separator + dir;
                final LevelDBDatabase bdb = new LevelDBDatabase(this, new File(fullPath), dir);
                theDatabase.put(dir.toLowerCase(), bdb);
            }
        }
    } catch (final Exception e) {
        throw new DBException("Error creating connection: " + theDatabase, e);
    }
}

From source file:ch.admin.suis.msghandler.common.CompleteFullTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();

    Security.addProvider(new BouncyCastleProvider());
    SenderSession.msgGen = new V2MessageXmlGenerator();

    TEMP_DIRS.forEach((dir) -> {/* w w  w.j a v  a 2s  . c o  m*/
        try {
            FileUtils.forceMkdir(dir);
        } catch (IOException ex) {
            // ignore
        }
    });

    addToClassPath(INSTALL_DIR + "/conf");
}

From source file:com.turn.griffin.GriffinLibCacheUtil.java

public Optional<FileInfo> addFileToLocalLibCache(String blobName, long version, String dest, String filepath) {

    FileInfo fileInfo = FileInfo.newBuilder().setFilename(blobName).setVersion(version)
            .setHash(computeMD5(filepath).get()).setDest(dest).setCompression(FILE_COMPRESSION.name())
            .setBlockSize(FILE_BLOCK_SIZE).build();

    try {/*from   ww w.  j a  v a  2  s  . c  o m*/
        FileUtils.forceMkdir(new File(getTempCacheDirectory(fileInfo)));
        String tempCacheFilePath = getTempCacheFilePath(fileInfo);
        FileUtils.copyFile(new File(filepath), new File(tempCacheFilePath));

        /* The compression type is decided only once at the time a file is pushed.
           This design will ensure that any change to default file compression
           would not affect any previously pushed file as long as the new code
           supports the old compression.
         */
        compressFile(tempCacheFilePath, FILE_COMPRESSION);
        writeTempCacheMetaDataFile(fileInfo);

        /* Now move everything to local libcache */
        moveFromTempCacheToLibCache(fileInfo);

    } catch (IOException ioe) {
        logger.error(String.format("Unable to create local repository for %s", blobName), ioe);
        return Optional.absent();
    }

    String libCacheCompressedFilePath = getLibCacheCompressedFilePath(fileInfo);
    /* NOTE: Number of blocks are for the compressed file and not the original file. */
    int blockCount = (int) Math
            .ceil(FileUtils.sizeOf(new File(libCacheCompressedFilePath)) / (double) FILE_BLOCK_SIZE);

    FileInfo finalFileInfo = FileInfo.newBuilder().mergeFrom(fileInfo).setBlockCount(blockCount).build();

    return Optional.of(finalFileInfo);
}

From source file:de.tudarmstadt.ukp.clarin.webanno.automation.MiraAutomationServiceImpl.java

@Override
public void createTemplate(Project aProject, File aContent, String aFileName, String aUsername)
        throws IOException {
    String templatePath = dir.getAbsolutePath() + PROJECT + aProject.getId() + MIRA + MIRA_TEMPLATE;
    FileUtils.forceMkdir(new File(templatePath));
    copyLarge(new FileInputStream(aContent), new FileOutputStream(new File(templatePath + aFileName)));

    createLog(aProject, aUsername).info(" Created Template file[ " + aFileName + "] for Project ["
            + aProject.getName() + "] with ID [" + aProject.getId() + "]");
    createLog(aProject, aUsername).removeAllAppenders();
}

From source file:com.textocat.textokit.commons.consumer.IobWriter.java

@Override
public void initialize(UimaContext ctx) throws ResourceInitializationException {
    super.initialize(ctx);
    try {/*from   www.j  a v a2 s  . c  o  m*/
        FileUtils.forceMkdir(outputDir);
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
    if (encodeTypeLabels != null && encodeTypeLabels.isEmpty()) {
        encodeTypeLabels = null;
    }
    if (encodeTypeLabels != null && encodeTypeNames.size() != encodeTypeLabels.size()) {
        throw new IllegalArgumentException("encodeTypeLabels must have the same length with encodeTypes");
    }
}

From source file:ml.shifu.shifu.core.alg.LogisticRegressionTrainer.java

private void saveLR() throws IOException {
    File folder = new File("./models");
    if (!folder.exists()) {
        FileUtils.forceMkdir(folder);
    }//from w w  w . jav a2  s.  com
    EncogDirectoryPersistence.saveObject(new File("./models/model" + this.trainerID + ".lr"), classifier);
}

From source file:com.norconex.commons.lang.file.FileUtil.java

/**
 * Moves a file to a directory.   Like {@link #moveFile(File, File)}:
 * <ul>// w ww  . j a v  a 2 s  .c o m
 *   <li>If the target directory does not exists, it creates it first.</li>
 *   <li>If the target file already exists, it deletes it first.</li>
 *   <li>If target file deletion does not work, it will try 10 times,
 *       waiting 1 second between each try to give a chance to whatever
 *       OS lock on the file to go.</li>
 *   <li>It throws a IOException if the move failed (as opposed to fail
 *       silently).</li>
 * </ul>
 * @param sourceFile source file to move
 * @param targetDir target destination
 * @throws IOException cannot move file.
 */
public static void moveFileToDir(File sourceFile, File targetDir) throws IOException {
    if (sourceFile == null || !sourceFile.isFile()) {
        throw new IOException("Source file is not valid: " + sourceFile);
    }
    if (targetDir == null || targetDir.exists() && !targetDir.isDirectory()) {
        throw new IOException("Target directory is not valid:" + targetDir);
    }
    if (!targetDir.exists()) {
        FileUtils.forceMkdir(targetDir);
    }

    String fileName = sourceFile.getName();
    File targetFile = new File(targetDir.getAbsolutePath() + SystemUtils.PATH_SEPARATOR + fileName);
    moveFile(sourceFile, targetFile);
}