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:au.org.ala.biocache.dao.JsonPersistentQueueDAOImpl.java

@PostConstruct
public void init() {
    offlineDownloadList = Collections.synchronizedList(new ArrayList<DownloadDetailsDTO>());
    File file = new File(cacheDirectory);
    jsonMapper.configure(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES,
            false);//w  w w.ja va2s  .  c o  m

    try {
        FileUtils.forceMkdir(file);
    } catch (IOException e) {
        logger.error("Unable to construct cache directory.", e);
    }
    refreshFromPersistent();

}

From source file:eu.europeana.corelib.europeanastatic.cache.RepositoryImpl.java

@Override
public int createCacheDirectories(String prefix) throws IOException {
    if (!getRoot().exists()) {
        return -1;
    } else {//from www. j av a 2s  .  c  o  m
        getRoot().mkdirs();
        int count = 0;
        for (String dirAB : makeHexLetterPairs()) {
            for (String dirCD : makeHexLetterPairs()) {
                String directoryString = String.format("%s%s%s", dirAB, SLASH, dirCD);
                FileUtils.forceMkdir(
                        new File(getRoot(), String.format("%s%s%s", prefix, SLASH, directoryString)));
                count++;
            }
            count++;
        }
        return count;
    }
}

From source file:ml.shifu.shifu.actor.TrainModelActorTest.java

@Test
public void testActor() throws IOException, InterruptedException {
    File tmpDir = new File("./tmp");
    FileUtils.forceMkdir(tmpDir);

    // create normalize data
    actorSystem = ActorSystem.create("shifuActorSystem");
    ActorRef normalizeRef = actorSystem.actorOf(new Props(new UntypedActorFactory() {
        private static final long serialVersionUID = 6777309320338075269L;

        public UntypedActor create() throws IOException {
            return new NormalizeDataActor(modelConfig, columnConfigList, new AkkaExecStatus(true));
        }/*  ww w  . ja  va2s .co  m*/
    }), "normalize-calculator");

    List<Scanner> scanners = ShifuFileUtils.getDataScanners(
            "src/test/resources/example/cancer-judgement/DataStore/DataSet1", SourceType.LOCAL);
    normalizeRef.tell(new AkkaActorInputMessage(scanners), normalizeRef);

    while (!normalizeRef.isTerminated()) {
        Thread.sleep(5000);
    }

    File outputFile = new File("./tmp/NormalizedData");
    Assert.assertTrue(outputFile.exists());

    // start to run trainer
    actorSystem = ActorSystem.create("shifuActorSystem");
    File models = new File("./models");
    FileUtils.forceMkdir(models);

    final List<AbstractTrainer> trainers = new ArrayList<AbstractTrainer>();
    for (int i = 0; i < 5; i++) {
        AbstractTrainer trainer;
        if (modelConfig.getAlgorithm().equalsIgnoreCase("NN")) {
            trainer = new NNTrainer(this.modelConfig, i, false);
        } else if (modelConfig.getAlgorithm().equalsIgnoreCase("SVM")) {
            trainer = new SVMTrainer(this.modelConfig, i, false);
        } else if (modelConfig.getAlgorithm().equalsIgnoreCase("LR")) {
            trainer = new LogisticRegressionTrainer(this.modelConfig, i, false);
        } else {
            throw new RuntimeException("unsupport algorithm");
        }
        trainers.add(trainer);
    }

    // train model
    ActorRef modelTrainRef = actorSystem.actorOf(new Props(new UntypedActorFactory() {
        private static final long serialVersionUID = 6777309320338075269L;

        public UntypedActor create() throws IOException {
            return new TrainModelActor(modelConfig, columnConfigList, new AkkaExecStatus(true), trainers);
        }
    }), "trainer");

    scanners = ShifuFileUtils.getDataScanners("./tmp/NormalizedData", SourceType.LOCAL);
    modelTrainRef.tell(new AkkaActorInputMessage(scanners), modelTrainRef);

    while (!modelTrainRef.isTerminated()) {
        Thread.sleep(5000);
    }

    for (Scanner scanner : scanners) {
        scanner.close();
    }

    File model0 = new File("./models/model0.nn");
    File model1 = new File("./models/model0.nn");
    File model2 = new File("./models/model0.nn");
    File model3 = new File("./models/model0.nn");
    File model4 = new File("./models/model0.nn");

    Assert.assertTrue(model0.exists());
    Assert.assertTrue(model1.exists());
    Assert.assertTrue(model2.exists());
    Assert.assertTrue(model3.exists());
    Assert.assertTrue(model4.exists());

    File modelsTemp = new File("./modelsTmp");

    FileUtils.deleteDirectory(modelsTemp);
    FileUtils.deleteDirectory(models);
    FileUtils.deleteDirectory(tmpDir);
}

From source file:com.apporiented.hermesftp.cmd.impl.FtpCmdMkd.java

/**
 * {@inheritDoc}//from w ww.ja  v  a  2 s .  c  o  m
 */
public void execute() throws FtpCmdException {
    if ((getPermission() & PRIV_WRITE) == 0) {
        msgOut(MSG550_PERM);
        return;
    }
    String response;
    File dir = new File(getPathArg());
    if (dir.exists()) {
        log.debug(dir + " already exists");
        response = msg(MSG550_EXISTS);
    } else {
        try {
            FileUtils.forceMkdir(dir);
            response = msg(MSG250);
        } catch (IOException e) {
            response = msg(MSG451);
        }
    }
    out(response);
}

From source file:com.dianping.maven.plugin.tools.wms.WorkspaceManagementServiceImpl.java

@Override
public void create(WorkspaceContext context, OutputStream out) throws WorkspaceManagementException {
    if (context.getProjects() != null && context.getBaseDir() != null && out != null) {

        printContent("Generating phoenix workspace...", out);

        if (context.getBaseDir().exists()) {
            try {
                FileUtils.cleanDirectory(context.getBaseDir());
            } catch (IOException e) {
                throw new WorkspaceManagementException(e);
            }// www . ja  v a 2  s. c om
        }
        printContent(String.format("Workspace folder(%s) cleared...", context.getBaseDir()), out);

        try {
            FileUtils.forceMkdir(context.getBaseDir());
        } catch (IOException e) {
            throw new WorkspaceManagementException(e);
        }
        printContent(String.format("Workspace folder(%s) created...", context.getBaseDir()), out);

        for (String project : context.getProjects()) {
            Repository repository = repositoryManager.find(project);
            if (repository == null) {
                printContent(String.format("Project(%s) not found...", project), out);
            }

            CodeRetrieveConfig codeRetrieveConfig = toCodeRetrieveConfig(repository,
                    new File(context.getBaseDir(), project).getAbsolutePath(), out);
            if (codeRetrieveConfig != null) {
                printContent(
                        String.format("Checking out project %s(repo:%s)...", project, repository.getRepoUrl()),
                        out);
                CodeRetrieveService.getInstance().retrieveCode(codeRetrieveConfig);
            } else {
                printContent(String.format("Project repository(%s) unknown...", project), out);
            }
        }

        printContent("Generating phoenix-container...", out);

        generateContainerProject(context);

        printContent("Phoenix workspace generated...", out);

    } else {
        throw new WorkspaceManagementException("projects/basedir can not be null");
    }
}

From source file:com.example.recognizer.DataFiles.java

public boolean createRawLogDir() {
    if (!mDirRawLog.exists()) {
        try {//from   ww w.  j a  va2 s .co  m
            FileUtils.forceMkdir(mDirRawLog);
        } catch (IOException e) {
            return false;
        }
    }
    return true;
}

From source file:jenkins.plugins.itemstorage.s3.Downloads.java

public void startDownload(TransferManager manager, File base, String pathPrefix, S3ObjectSummary summary)
        throws AmazonServiceException, IOException {
    // calculate target file name
    File targetFile = FileUtils.getFile(base, summary.getKey().substring(pathPrefix.length() + 1));

    // if target file exists, only download it if newer
    if (targetFile.lastModified() < summary.getLastModified().getTime()) {
        // ensure directory above file exists
        FileUtils.forceMkdir(targetFile.getParentFile());

        // Start the download
        Download download = manager.download(summary.getBucketName(), summary.getKey(), targetFile);

        // Keep for later
        startedDownloads.add(new Memo(download, targetFile, summary.getLastModified().getTime()));
    }/*from  www.j a v  a 2  s .c om*/
}

From source file:AIR.ResourceBundler.Console.ResourcesBuilder.java

private void processParentResource(FileSet fileSet) throws Exception {
    String outputFile = Path.combine(_parentFolder, fileSet.getOutput());
    outputFile = outputFile.replace('/', File.separatorChar);
    File outputFolder = new File(outputFile).getParentFile();

    // make sure output folder exists
    if (!outputFolder.exists()) {
        FileUtils.forceMkdir(outputFolder);
    }/*  w  w w.  j  a v a 2  s.  c  om*/

    File output = new File(outputFile);
    output.createNewFile();

    FileWriter sw = new FileWriter(output);

    sw.write("/*\n");
    sw.write(String.format("Copyright (c) %s, American Institutes for Research. All rights reserved.\n",
            DateTime.getNow().getYear()));
    sw.write(String.format("GENERATED: %s\n", DateTime.getNow().toString()));
    // TODO Shajib: In .net code Environment.MachineName used
    int machineHash = HttpContext.getCurrentContext().getServer().hashCode();
    String machineID = Integer.toString(machineHash);
    sw.write(String.format("MACHINE: %s\n", machineID));
    sw.write("*/\n");
    sw.write("\n");

    Iterator<FileSetInput> it = _resources.getFileInputs(fileSet.getName());
    FileSetInput file = null;

    for (; it.hasNext();) {
        file = it.next();
        writeFileInput(sw, file);
    }
}

From source file:com.intuit.karate.demo.controller.UploadController.java

public UploadController() throws Exception {
    File file = new File(FILES_BASE);
    FileUtils.forceMkdir(file);
    logger.info("created directory: {}", file);
}

From source file:io.druid.data.input.impl.prefetch.PrefetchableTextFilesFirehoseFactoryTest.java

@BeforeClass
public static void setup() throws IOException {
    TEST_DIR = File.createTempFile(PrefetchableTextFilesFirehoseFactoryTest.class.getSimpleName(), "testDir");
    FileUtils.forceDelete(TEST_DIR);//  w  w  w . j a  v  a 2s  .c o  m
    FileUtils.forceMkdir(TEST_DIR);

    for (int i = 0; i < 100; i++) {
        try (CountingOutputStream cos = new CountingOutputStream(
                Files.newOutputStream(new File(TEST_DIR, "test_" + i).toPath()));
                Writer writer = new BufferedWriter(new OutputStreamWriter(cos, StandardCharsets.UTF_8))) {
            for (int j = 0; j < 100; j++) {
                final String a = StringUtils.format("%d,%03d,%03d\n", (20171220 + i), i, j);
                writer.write(a);
            }
            writer.flush();
            // Every file size must be same
            if (FILE_SIZE == -1) {
                FILE_SIZE = cos.getCount();
            } else {
                Assert.assertEquals(FILE_SIZE, cos.getCount());
            }
        }
    }
}