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:hoot.services.controllers.info.ReportsResourceTest.java

@Test
@Category(UnitTest.class)
public void testGetMetaData() throws Exception {
    String storePath = _rps._homeFolder + "/" + _rps._rptStorePath;
    File f = new File(storePath);
    File fWks = new File(storePath + "/123_test");
    if (fWks.exists()) {
        FileUtils.forceDelete(fWks);//from w  w w .  j a  va  2  s  .  co m
    }
    FileUtils.forceMkdir(f);
    JSONObject res = _rps._getMetaData("123_test");
    assertNull(res.get("name"));

    FileUtils.forceMkdir(fWks);
    String currTime = "" + System.currentTimeMillis();
    JSONObject metaData = new JSONObject();
    metaData.put("name", "Test Report1");
    metaData.put("description", "This is test report 1");
    metaData.put("created", currTime);
    metaData.put("reportpath", storePath + "/123_test/report.pdf");
    File meta = new File(storePath + "/123_test/meta.data");
    FileUtils.write(meta, metaData.toJSONString());

    res = _rps._getMetaData("123_test");

    org.junit.Assert.assertEquals("Test Report1", res.get("name").toString());
    org.junit.Assert.assertEquals("This is test report 1", res.get("description").toString());
    org.junit.Assert.assertEquals(currTime, res.get("created").toString());
    org.junit.Assert.assertEquals("reportpath", storePath + "/123_test/report.pdf",
            res.get("reportpath").toString());

    FileUtils.forceDelete(fWks);

}

From source file:com.meltmedia.cadmium.deployer.DeployerModule.java

/**
 * Called to do all bindings for this module.
 * //w w w. j  a  v a2  s. com
 * @see <a href="http://code.google.com/p/google-guice/">Google Guice</a>
 */
@Override
protected void configure() {
    try {
        InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
        File appRoot = new File(System.getProperty(CadmiumListener.BASE_PATH_ENV), "maven");
        FileUtils.forceMkdir(appRoot);
        String remoteMavenRepo = System.getProperty(MAVEN_REPOSITORY);
        ArtifactResolver resolver = new ArtifactResolver(remoteMavenRepo, appRoot.getAbsolutePath());
        bind(ArtifactResolver.class).toInstance(resolver);
        bind(JBossAdminApi.class);
        Multibinder<ConfigurationListener> listenerBinder = Multibinder.newSetBinder(binder(),
                ConfigurationListener.class);
        listenerBinder.addBinding().to(JBossAdminApi.class);
        bind(IJBossUtil.class).to(JBossDelegator.class);
    } catch (Exception e) {
        logger.error("Failed to initialize maven artifact resolver.", e);
    }
}

From source file:com.github.jrh3k5.mojo.flume.io.ArchiveUtils.java

/**
 * Extract the contents of a TAR file.//from  w  w w .jav a  2  s.c o  m
 * 
 * @param tarFile
 *            A {@link File} representing the TAR file whose contents are to be extracted.
 * @param toDirectory
 *            A {@link File} representing the directory to which the contents of the TAR file to be extracted.
 * @throws IllegalArgumentException
 *             If the given TAR file is not a file or does not exist or the given output directory is not a directory or does not exist.
 * @throws IOException
 *             If any errors occur during the extraction.
 * @see #tarDirectory(File, File)
 */
public static void untarFile(File tarFile, File toDirectory) throws IOException {
    if (!tarFile.isFile()) {
        throw new IllegalArgumentException("TAR file " + tarFile + " must be an existent file.");
    }

    if (!toDirectory.exists()) {
        FileUtils.forceMkdir(toDirectory);
    }

    if (!toDirectory.isDirectory()) {
        throw new IllegalArgumentException(
                "Output directory " + toDirectory + " must be an existent directory.");
    }

    final TarUnArchiver unarchiver = new TarUnArchiver(tarFile);
    unarchiver.enableLogging(new Slf4jPlexusLogger(FlumeCopier.class));
    unarchiver.setDestDirectory(toDirectory);
    unarchiver.extract();
}

From source file:de.fhg.iais.asc.oai.localwriter.RepositoryWriter.java

public RepositoryWriter(File rootDir, int maxFilesEach, String oaipmhserveruri, String eventId) {
    this.rootDir = rootDir;
    this.maxFilesEach = maxFilesEach > 0 ? maxFilesEach : 0;
    this.eventId = eventId;
    try {/*from w  w w.  j a  v a  2s .  c  o  m*/
        FileUtils.forceMkdir(this.rootDir);
    } catch (IOException e) {
        LOG.error("", e);
    }
    LOG.info("Working folder: " + this.rootDir.getAbsolutePath());
    this.currentServer = oaipmhserveruri;
}

From source file:com.btoddb.chronicle.ChronicleIT.java

@Before
public void setup() throws Exception {
    theDir = new File("tmp/junitTmp_" + UUID.randomUUID().toString());
    FileUtils.forceMkdir(theDir);

    config = Config.create("src/test/resources/chronicle-test.yaml");
    for (PlunkerRunner runner : config.getPlunkers().values()) {
        runner.getFpq().setJournalDirectory(new File(theDir, runner.getPlunker().getId() + "/journals"));
        runner.getFpq().setPagingDirectory(new File(theDir, runner.getPlunker().getId() + "/pages"));
    }//from w  w  w.j a  va 2s.co m

    chronicle = new Chronicle();
    chronicle.init(config);
}

From source file:at.uni_salzburg.cs.ros.viewer.services.BigraphArchiveImpl.java

/**
 * @param imageRenderer the BigraphImageRenderer instance.
 * @throws IOException/*from  w w  w  . j  av  a  2 s . co m*/
 */
public BigraphArchiveImpl(BigraphImageRenderer imageRenderer) throws IOException {
    this.imageRenderer = imageRenderer;
    String bgmArchiveDirName = System.getProperty(BGM_ARCHIVE_PROP, BGM_ARCHIVE_DEFAULT_DIR);
    bgmArchive = new File(bgmArchiveDirName);
    FileUtils.forceMkdir(bgmArchive);
    LOG.info("Using archive directory {}", bgmArchive.getAbsolutePath());

    String cleanUp = System.getProperty(BGM_ARCHIVE_CLEANUP_PROP, "true");
    if ("true".equalsIgnoreCase(cleanUp)) {
        LOG.info("Cleaning up bigraph image archive folder '{}'", bgmArchive.getAbsolutePath());
        FileUtils.cleanDirectory(bgmArchive);
    } else {
        LOG.info("Cleaning up bigraph image archive folder '{}' declined.", bgmArchive.getAbsolutePath());
    }
}

From source file:ch.algotrader.util.io.CsvTickWriter.java

public CsvTickWriter(File file) throws IOException {

    File parent = file.getParentFile();
    if (!parent.exists()) {
        FileUtils.forceMkdir(parent);
    }//from  w  w w.  ja  va  2 s  .c o m

    boolean exists = file.exists();

    this.writer = new CsvBeanWriter(new FileWriter(file, true), CsvPreference.EXCEL_PREFERENCE);

    if (!exists) {
        this.writer.writeHeader(header);
    }
}

From source file:gov.va.vinci.leo.tools.GenerateDescriptors.java

/**
 * A utility for generating Descriptors and Type Descriptors for an annotator.
 *
 * @param annotatorClassName The annotator class name. The annotator class must extend LeoBaseAnnotator and
 *                           be in the classpath.
 * @param outputRootPath     The root directory to output the descriptors to. Descriptors are written to outputRootPath/annotator package/Annotator(Descriptor/Type).xml
 * @throws Exception if any exception occurs during generation.
 *//*from ww w .j  a  v  a  2 s. c o m*/
public static void generate(String annotatorClassName, String outputRootPath) throws Exception {
    LeoBaseAnnotator annotator = (LeoBaseAnnotator) Class.forName(annotatorClassName).newInstance();
    String shortName = annotatorClassName;
    if (annotatorClassName.contains(".")) {
        shortName = annotatorClassName.substring(annotatorClassName.lastIndexOf(".") + 1);
    }

    String newOutputPath = outputRootPath;
    if (!outputRootPath.endsWith(File.separator)) {
        newOutputPath += File.separator;
    }

    if (annotatorClassName.contains(".")) {
        newOutputPath += annotatorClassName.substring(0, annotatorClassName.lastIndexOf(".")).replaceAll("\\.",
                File.separator) + File.separator;
    }

    FileUtils.forceMkdir(new File(newOutputPath));
    annotator.getLeoTypeSystemDescription().toXML(newOutputPath + shortName + "Type.xml");

    LeoAEDescriptor desc = (LeoAEDescriptor) annotator.getDescriptor();
    desc.toXML(shortName);
    String descriptorPath = desc.getDescriptorLocator();
    if (descriptorPath.startsWith("file:")) {
        descriptorPath = descriptorPath.substring(5);
    }

    FileUtils.copyFile(new File(descriptorPath), new File(newOutputPath + shortName + "Descriptor.xml"));
}

From source file:com.legstar.coxb.gen.AbstractCoxbGenTest.java

/** @{inheritDoc */
public void setUp() throws Exception {
    super.setUp();
    CodeGenUtil.initVelocity();/*from w  w  w.  j  av  a  2s .c o  m*/
    mParameters = new HashMap<String, Object>();
    CodeGenHelper helper = new CodeGenHelper();
    mParameters.put("helper", helper);
    mParameters.put("coxbHelper", new CoxbHelper());
    FileUtils.forceMkdir(GEN_SRC_DIR);
    FileUtils.cleanDirectory(GEN_SRC_DIR);
    FileUtils.forceMkdir(GEN_ANT_DIR);
    FileUtils.cleanDirectory(GEN_ANT_DIR);
    FileUtils.forceMkdir(GEN_BIN_DIR);
    FileUtils.cleanDirectory(GEN_BIN_DIR);
}

From source file:com.michaelfitzmaurice.devtools.HeaderToolTest.java

@Before
public void setUpDirectories() throws IOException {

    // ensure test data exists as expected
    File runtimeDirectory = new File(System.getProperty("user.dir"));
    File testDataRoot = new File(runtimeDirectory, "src/test/data/");
    assertTestDataDirValid(testDataRoot);

    // copy test data to a temp directory
    TMP_ROOT_DIRECTORY = new File(FileUtils.getTempDirectory(),
            "header_tool_tests_" + System.currentTimeMillis());
    FileUtils.forceMkdir(TMP_ROOT_DIRECTORY);
    TMP_ROOT_DIRECTORY.deleteOnExit();//from   w  ww.j a v  a 2 s. c  o  m
    FileUtils.copyDirectory(testDataRoot, TMP_ROOT_DIRECTORY);
    Collection<File> tmpDirContents = FileUtils.listFilesAndDirs(TMP_ROOT_DIRECTORY, TrueFileFilter.INSTANCE,
            TrueFileFilter.INSTANCE);
    assertFileListsEqual(expectedTestDirContents(TMP_ROOT_DIRECTORY), tmpDirContents,
            "Temp dir does not contain expected contents");

    HEADER_FILE = new File(testDataRoot, HEADER_FILENAME);
    HEADER_CONTENT = fileContents(HEADER_FILE);
    assertTrue("Header file was empty", HEADER_CONTENT.length() > 0);
}