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.francetelecom.clara.cloud.mvn.consumer.MvnConsumerConfigurerTest.java

@Test
public void should_cleanup_local_repo_on_startup() throws IOException {
    File dummyDir = new File(this.mvnConsumerConfigurer.getLocalM2RepoPath() + File.separator + "xxx");
    FileUtils.forceMkdir(dummyDir);

    assertTrue("Directory :" + dummyDir + "should exist", dummyDir.isDirectory());
    this.mvnConsumerConfigurer.init();

    assertFalse("Directory :" + dummyDir + "should NOT exist", dummyDir.exists());

}

From source file:com.redhat.victims.VictimsResultCache.java

/**
 * Create the parent caching directory.//from   w w w  .j  ava 2s  .  c  o m
 * 
 * @param cache
 * @throws VictimsException
 */
protected void create(File cache) throws VictimsException {
    try {
        FileUtils.forceMkdir(cache);
    } catch (IOException e) {
        throw new VictimsException("Could not create an on disk cache", e);
    }
}

From source file:com.norconex.collector.core.data.store.impl.mvstore.MVStoreCrawlDataStore.java

public MVStoreCrawlDataStore(String path, boolean resume) {

    try {//from   www .  java  2  s  .c o  m
        FileUtils.forceMkdir(new File(path));
    } catch (IOException e) {
        throw new CrawlDataStoreException("Cannot create crawl data store directory: " + path, e);
    }
    store = MVStore.open(path + "/mvstore");

    mapQueued = store.openMap("queued");
    mapActive = store.openMap("active");
    mapProcessedValid = store.openMap("processedValid");
    mapProcessedInvalid = store.openMap("processedInvalid");
    mapCached = store.openMap("cached");

    if (resume) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Active count: " + mapActive.size());
            LOG.debug("Cache count: " + mapCached.size());
            LOG.debug("Processed valid count: " + mapProcessedValid.size());
            LOG.debug("Processed invalid count: " + mapProcessedInvalid.size());
            LOG.debug(path + " Putting active URLs back in the queue...");
        }
        // Active -> Queued
        for (String key : mapActive.keySet()) {
            mapQueued.put(key, mapActive.remove(key));
        }

    } else {
        mapCached.clear();
        mapActive.clear();
        mapQueued.clear();
        mapProcessedInvalid.clear();

        // Valid Processed -> Cached
        for (String key : mapProcessedValid.keySet()) {
            ICrawlData processed = mapProcessedValid.remove(key);
            if (processed.getState().isGoodState()) {
                mapCached.put(key, processed);
            }
        }
    }
    store.commit();
}

From source file:com.canoo.webtest.util.WebtestEmbeddingUtil.java

/**
 * Copies WebTest resources (ie webtest.xml, tools/*, the XSLs, CSSs and pictures, ...) package in WebTest jar file
 * into the provide folder. Indeed different Ant tasks can't work with resources in a jar file.
 * @param targetFolder the folder in which resources should be copied to
 * @throws java.io.IOException if the resources can be accessed or copied
 *///w ww .  jav a2 s. c om
static void copyWebTestResources(final File targetFolder) throws IOException {
    final String resourcesPrefix = "com/canoo/webtest/resources/";
    final URL webtestXmlUrl = WebtestEmbeddingUtil.class.getClassLoader()
            .getResource(resourcesPrefix + "webtest.xml");

    if (webtestXmlUrl == null) {
        throw new IllegalStateException("Can't find resource " + resourcesPrefix + "webtest.xml");
    } else if (webtestXmlUrl.toString().startsWith("jar:file")) {
        final String urlJarFileName = webtestXmlUrl.toString().replaceFirst("^jar:file:([^\\!]*).*$", "$1");
        final String jarFileName = URLDecoder.decode(urlJarFileName, Charset.defaultCharset().name());
        final JarFile jarFile = new JarFile(jarFileName);
        final String urlPrefix = StringUtils.removeEnd(webtestXmlUrl.toString(), "webtest.xml");

        for (final Enumeration<JarEntry> entries = jarFile.entries(); entries.hasMoreElements();) {
            final JarEntry jarEntry = entries.nextElement();
            if (jarEntry.getName().startsWith(resourcesPrefix)) {
                final String relativeName = StringUtils.removeStart(jarEntry.getName(), resourcesPrefix);
                final URL url = new URL(urlPrefix + relativeName);
                final File targetFile = new File(targetFolder, relativeName);
                FileUtils.forceMkdir(targetFile.getParentFile());
                FileUtils.copyURLToFile(url, targetFile);
            }
        }
    } else if (webtestXmlUrl.toString().startsWith("file:")) {
        // we're probably developing and/or have a custom version of the resources in classpath
        final File webtestXmlFile = FileUtils.toFile(webtestXmlUrl);
        final File resourceFolder = webtestXmlFile.getParentFile();

        FileUtils.copyDirectory(resourceFolder, targetFolder);
    } else {
        throw new IllegalStateException(
                "Resource " + resourcesPrefix + "webtest.xml is not in a jar file: " + webtestXmlUrl);
    }
}

From source file:com.linkedin.pinot.core.segment.store.SegmentDirectoryPathsTest.java

@Test
public void testFindMetadataFile() throws IOException {
    File tempDirectory = null;/*from   ww w .j  a v  a 2 s .com*/
    try {
        // setup temp dir, v3 subdir and create metadata.properties in both
        tempDirectory = new File(SegmentDirectoryPaths.class.toString());
        tempDirectory.deleteOnExit();
        FileUtils.forceMkdir(tempDirectory);
        File v3Dir = new File(tempDirectory, "v3");
        FileUtils.forceMkdir(v3Dir);
        File metaFile = new File(tempDirectory, V1Constants.MetadataKeys.METADATA_FILE_NAME);
        try (FileOutputStream outputStream = new FileOutputStream(metaFile)) {
            outputStream.write(10);
        }
        File v3MetaFile = new File(v3Dir, V1Constants.MetadataKeys.METADATA_FILE_NAME);
        FileUtils.copyFile(metaFile, v3MetaFile);

        {
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), metaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), metaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());
        }
        {
            // drop v1 metadata file
            FileUtils.forceDelete(metaFile);
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNotNull(testMetaFile);
            Assert.assertEquals(testMetaFile.toString(), v3MetaFile.toString());
        }
        {
            // drop v3 metadata file
            FileUtils.forceDelete(v3MetaFile);
            File testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v1);
            Assert.assertNull(testMetaFile);

            testMetaFile = SegmentDirectoryPaths.findMetadataFile(tempDirectory, SegmentVersion.v3);
            Assert.assertNull(testMetaFile);
        }
    } finally {
        if (tempDirectory != null) {
            FileUtils.deleteQuietly(tempDirectory);
        }
    }
}

From source file:com.dchq.docker.volume.driver.adaptor.LocalVolumeAdaptorImpl.java

@Override
public BaseResponse create(CreateRequest request) {
    BaseResponse response = new BaseResponse();
    try {//from   w w  w . j av a  2 s . com
        File file = new File(new File(TMP_LOC), request.getName());
        FileUtils.forceMkdir(file);
        logger.info("Created Volume [{}] on path [{}]", file.getName(), file.getAbsoluteFile());

    } catch (Exception e) {
        logger.warn(e.getLocalizedMessage(), e);
        response.setErr(e.getLocalizedMessage());
    }
    return response;
}

From source file:com.github.brandtg.pantopod.crawler.FileBasedCrawlingEventHandler.java

@Override
protected boolean handleData(URI url, byte[] data) throws IOException {
    File outputRoot = new File(outputDir, url.getHost() + File.separator + url.getPath());
    FileUtils.forceMkdir(outputRoot);
    File outputData = new File(outputRoot, DAT_FILE);
    if (!outputData.exists()) {
        try (OutputStream os = new FileOutputStream(outputData)) {
            IOUtils.write(data, os);/*from   ww  w .j  ava2  s  . c  om*/
            LOG.info("Wrote {}", outputRoot);
        }
        return true;
    }
    return false;
}

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

public static void local_mkdirs(String path) throws IOException {
    LOG.debug("Making dirs at" + path);
    FileUtils.forceMkdir(new File(path));
}

From source file:com.thoughtworks.go.util.FileUtil.java

public static void validateAndCreateDirectory(File directory) {
    if (directory.exists()) {
        return;//  w  ww .j  a v a 2 s.  com
    }
    try {
        FileUtils.forceMkdir(directory);
    } catch (IOException e) {
        throw new RuntimeException("Failed to create folder: " + directory.getAbsolutePath());
    }
}

From source file:com.norconex.collector.core.pipeline.importer.SaveDocumentStage.java

@Override
public boolean execute(ImporterPipelineContext ctx) {
    //TODO have an interface for how to store downloaded files
    //(i.e., location, directory structure, file naming)
    File workdir = ctx.getConfig().getWorkDir();
    File downloadDir = new File(workdir, "/downloads");
    if (!downloadDir.exists()) {
        try {/*from   w  w w  . j  ava  2  s.  c om*/
            FileUtils.forceMkdir(downloadDir);
        } catch (IOException e) {
            throw new CollectorException("Cannot create download directory: " + downloadDir, e);
        }
    }
    String path = urlToPath(ctx.getCrawlData().getReference());

    File downloadFile = new File(downloadDir, path);

    if (LOG.isDebugEnabled()) {
        LOG.debug("Saved file: " + downloadFile);
    }
    try {
        OutputStream out = FileUtils.openOutputStream(downloadFile);
        IOUtils.copy(ctx.getDocument().getContent(), out);
        IOUtils.closeQuietly(out);

        ctx.fireCrawlerEvent(CrawlerEvent.DOCUMENT_SAVED, ctx.getCrawlData(), downloadFile);
    } catch (IOException e) {
        throw new CollectorException("Cannot save document: " + ctx.getCrawlData().getReference(), e);
    }
    return true;
}