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:com.gargoylesoftware.htmlunit.util.DebuggingWebConnection.java

/**
 * Wraps a web connection to have a report generated of the received responses.
 * @param webConnection the webConnection that do the real work
 * @param dirName the name of the directory to create in the tmp folder to save received responses.
 * If this folder already exists, it will be deleted first.
 * @throws IOException in case of problems writing the files
 *//* ww w .j  av a  2s  .  com*/
public DebuggingWebConnection(final WebConnection webConnection, final String dirName) throws IOException {

    super(webConnection);

    wrappedWebConnection_ = webConnection;
    final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
    reportFolder_ = new File(tmpDir, dirName);
    if (reportFolder_.exists()) {
        FileUtils.forceDelete(reportFolder_);
    }
    FileUtils.forceMkdir(reportFolder_);
    javaScriptFile_ = new File(reportFolder_, "hu.js");
    createOverview();
}

From source file:com.kelveden.rastajax.cli.Runner.java

private static File ensureWorkingDirectory() throws CliExecutionException {

    final File tempFolder = new File(FileUtils.getTempDirectory(), "rastajax-explode");

    try {/*  w  w  w . j a  v a 2  s  .  c  om*/
        FileUtils.forceMkdir(tempFolder);
        FileUtils.cleanDirectory(tempFolder);

    } catch (final IOException e) {
        throw new CliExecutionException("Failed to ensure presence of working folder.", e);
    }

    return tempFolder;
}

From source file:com.jivesoftware.os.upena.deployable.endpoints.api.UpenaRepoEndpoints.java

@PUT
@Path("/{subResources:.*}")
public Response putFileInRepo(InputStream fileInputStream, @PathParam("subResources") String subResources) {

    File f = new File(localPathToRepo.get(), subResources);
    try {/*from  w  w  w.  ja  va 2 s .c o m*/
        FileUtils.forceMkdir(f.getParentFile());
        saveFile(fileInputStream, f);
    } catch (Exception x) {
        LOG.error("Failed to write " + f, x);
        FileUtils.deleteQuietly(f);
        return Response.serverError().build();
    }

    if (f.getName().endsWith(".pom")) {
        autoRelease.uploaded(f);
    }

    return HeaderDecoration.decorate(Response.ok("Success")).build();
}

From source file:com.dv.util.DataViewerZipUtil.java

public static void doUnzipFile(ZipFile zipFile, File dest) throws IOException {
    if (!dest.exists()) {
        FileUtils.forceMkdir(dest);
    }//from ww w .  ja v a 2s . c  o  m
    Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        File file = new File(dest, entry.getName());
        if (entry.getName().endsWith(File.separator)) {
            FileUtils.forceMkdir(file);
        } else {
            OutputStream out = FileUtils.openOutputStream(file);
            InputStream in = zipFile.getInputStream(entry);
            try {
                IOUtils.copy(in, out);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                IOUtils.closeQuietly(out);
            }
        }
    }
    zipFile.close();
}

From source file:hoot.services.controllers.ingest.BasemapResourceTest.java

@Test
@Category(UnitTest.class)
public void TestDeleteBasemap() throws Exception {
    String testMapName = "testmap";

    BasemapResource mapRes = new BasemapResource();
    File dir = new File(mapRes._tileServerPath + "/BASEMAP/" + testMapName);
    FileUtils.forceMkdir(dir);

    org.junit.Assert.assertTrue(dir.exists());

    File controlFile = new File(mapRes._ingestStagingPath + "/BASEMAP/" + testMapName + ".enabled");
    FileUtils.touch(controlFile);/*from w  w  w  .j a  v a  2 s.  c om*/
    org.junit.Assert.assertTrue(controlFile.exists());

    mapRes._deleteBaseMap(testMapName);

    org.junit.Assert.assertFalse(dir.exists());

    org.junit.Assert.assertFalse(controlFile.exists());
}

From source file:com.btoddb.fastpersitentqueue.JournalMgr.java

private void prepareJournaling() throws IOException {
    FileUtils.forceMkdir(directory);
    Collection<File> files = FileUtils.listFiles(directory, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
    if (null == files || 0 == files.size()) {
        logger.info("no previous journal files found");
        return;//  w  ww .jav a 2  s  .co m
    }

    logger.info("loading journal descriptors");
    numberOfEntries.set(0);
    for (File f : files) {
        JournalFile jf = new JournalFile(f);
        jf.initForReading();
        jf.close();

        JournalDescriptor jd = new JournalDescriptor(jf);
        jd.setWritingFinished(true);
        jd.adjustEntryCount(jf.getNumberOfEntries());
        journalIdMap.put(jd.getId(), jd);
        numberOfEntries.addAndGet(jf.getNumberOfEntries());
        logger.info("loaded descriptor, {}, with {} entries", jd.getId(), jd.getNumberOfUnconsumedEntries());
        journalsLoadedAtStartup++;
    }

    logger.info("completed journal descriptor loading.  found a total of {} entries", numberOfEntries.get());
}

From source file:com.funambol.server.cleanup.ClientLogCleanUpAgentTest.java

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

    agent = new ClientLogCleanUpAgent(clientsLogDir, targetArchivationDirectory, activationThreshold,
            maxNumberOfArchivedFiles, numberOfArchivedFilesToDelete, timeToRest, lockName);

    try {/*from www . j  a  v  a  2s .  com*/
        FileUtils.forceMkdir(new File(TARGET_DIR));
        FileUtils.cleanDirectory(new File(TARGET_DIR));
        FileUtils.copyDirectory(new File(BASE_DIR), new File(TARGET_DIR),
                new NotFileFilter(new SuffixFileFilter(".svn")));
    } catch (IOException e) {
        assertTrue("Unable to handle target dir", true);
    }
}

From source file:de.flapdoodle.embed.process.store.ExtractedArtifactStore.java

private File getTargetDirectoryForExtractedFiles(File artifact) throws IOException {
    if (_directory != null) {
        return _directory.asFile();
    }/*from w w w  .  ja  va 2  s.  c o  m*/

    File directory = new File(FilenameUtils.removeExtension(artifact.getAbsolutePath()));
    FileUtils.forceMkdir(directory);

    return directory;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.GeneExpressionLoadAnnotationListener.java

@Override
protected void setJobMetadata(Job job) throws Exception {
    job.getJobMeta().setParameterValue("DATA_LOCATION", pathToFile);
    File sort = new File(sortName);
    if (!sort.exists()) {
        FileUtils.forceMkdir(sort);
    }//ww  w  . ja  v a  2 s.com
    job.getJobMeta().setParameterValue("SORT_DIR", sort.getAbsolutePath());
    job.getJobMeta().setParameterValue("DATA_SOURCE", "A");
    job.getJobMeta().setParameterValue("GPL_ID", platformId);
    job.getJobMeta().setParameterValue("SKIP_ROWS", "1");
    job.getJobMeta().setParameterValue("GENE_ID_COL", "4");
    job.getJobMeta().setParameterValue("GENE_SYMBOL_COL", "3");
    job.getJobMeta().setParameterValue("ORGANISM_COL", "5");
    job.getJobMeta().setParameterValue("PROBE_COL", "2");
    if (annotationDate != null) {
        job.getJobMeta().setParameterValue("ANNOTATION_DATE", annotationDate);
    }
    if (annotationRelease != null) {
        job.getJobMeta().setParameterValue("ANNOTATION_RELEASE", annotationRelease);
    }
    job.getJobMeta().setParameterValue("ANNOTATION_TITLE", annotationTitle);
    job.getJobMeta().setParameterValue("LOAD_TYPE", "I");
    job.getJobMeta().setParameterValue("TM_CZ_DB_SERVER", PreferencesHandler.getDbServer());
    job.getJobMeta().setParameterValue("TM_CZ_DB_NAME", PreferencesHandler.getDbName());
    job.getJobMeta().setParameterValue("TM_CZ_DB_PORT", PreferencesHandler.getDbPort());
    job.getJobMeta().setParameterValue("TM_CZ_DB_USER", PreferencesHandler.getTm_czUser());
    job.getJobMeta().setParameterValue("TM_CZ_DB_PWD", PreferencesHandler.getTm_czPwd());
    job.getJobMeta().setParameterValue("TM_LZ_DB_SERVER", PreferencesHandler.getDbServer());
    job.getJobMeta().setParameterValue("TM_LZ_DB_NAME", PreferencesHandler.getDbName());
    job.getJobMeta().setParameterValue("TM_LZ_DB_PORT", PreferencesHandler.getDbPort());
    job.getJobMeta().setParameterValue("TM_LZ_DB_USER", PreferencesHandler.getTm_lzUser());
    job.getJobMeta().setParameterValue("TM_LZ_DB_PWD", PreferencesHandler.getTm_lzPwd());
    job.getJobMeta().setParameterValue("DEAPP_DB_SERVER", PreferencesHandler.getDbServer());
    job.getJobMeta().setParameterValue("DEAPP_DB_NAME", PreferencesHandler.getDbName());
    job.getJobMeta().setParameterValue("DEAPP_DB_PORT", PreferencesHandler.getDbPort());
    job.getJobMeta().setParameterValue("DEAPP_DB_USER", PreferencesHandler.getDeappUser());
    job.getJobMeta().setParameterValue("DEAPP_DB_PWD", PreferencesHandler.getDeappPwd());
}

From source file:com.norconex.importer.Importer.java

/**
 * Creates a new importer with the given configuration.
 * @param importerConfig Importer configuration
 */// ww  w . j  av  a2 s. c om
public Importer(ImporterConfig importerConfig) {
    super();
    if (importerConfig != null) {
        this.importerConfig = importerConfig;
    } else {
        this.importerConfig = new ImporterConfig();
    }
    File tempDir = this.importerConfig.getTempDir();

    if (!tempDir.exists()) {
        try {
            FileUtils.forceMkdir(tempDir);
        } catch (IOException e) {
            throw new ImporterRuntimeException("Cannot create importer temporary directory: " + tempDir, e);
        }
    }
    streamFactory = new CachedStreamFactory(this.importerConfig.getMaxFilePoolCacheSize(),
            this.importerConfig.getMaxFileCacheSize(), this.importerConfig.getTempDir());
}