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:de.sulaco.bittorrent.service.downloader.TtorrentDownloaderTest.java

@Before
public void createTempDirectory() throws IOException {
    FileUtils.forceMkdir(new File(TEMPORARY_DIRECTORY));
}

From source file:de.blizzy.backup.database.Database.java

private void open(File folder, Collection<IStorageInterceptor> storageInterceptors) throws SQLException {
    if (conn == null) {
        try {//w w  w  .  j  ava  2  s. co  m
            if (!folder.exists()) {
                FileUtils.forceMkdir(folder);
            }

            try {
                Class.forName("org.h2.Driver"); //$NON-NLS-1$
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }

            StringBuilder paramsBuf = new StringBuilder("CACHE_SIZE=65536"); //$NON-NLS-1$
            String password = StringUtils.EMPTY;
            for (IStorageInterceptor interceptor : storageInterceptors) {
                if (interceptor instanceof IDatabaseModifyingStorageInterceptor) {
                    IDatabaseModifyingStorageInterceptor i = (IDatabaseModifyingStorageInterceptor) interceptor;
                    paramsBuf.append(";").append(i.getDatabaseParameters()); //$NON-NLS-1$
                    password = i.getDatabasePassword() + " " + password; //$NON-NLS-1$
                }
            }

            conn = DriverManager.getConnection("jdbc:h2:" + folder.getAbsolutePath() + "/backup" + //$NON-NLS-1$ //$NON-NLS-2$
                    ";" + paramsBuf.toString(), //$NON-NLS-1$
                    "sa", password); //$NON-NLS-1$
            conn.setAutoCommit(true);
            factory = new Factory(conn, SQLDialect.MYSQL);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.linkedin.pinot.common.utils.TarGzCompressionUtilsTest.java

@Test
public void testSubDirectories() throws IOException, ArchiveException, InterruptedException {
    new File(segmentDir, "metadata.properties").createNewFile();
    File v3Dir = new File(segmentDir, "v3");
    FileUtils.forceMkdir(v3Dir);
    new File(v3Dir, "creation.meta").createNewFile();

    File tarGzPath = new File(tarDir, SEGMENT_NAME + ".tar.gz");
    TarGzCompressionUtils.createTarGzOfDirectory(segmentDir.getPath(), tarGzPath.getPath());
    TarGzCompressionUtils.unTar(tarGzPath, untarDir);
    File[] segments = untarDir.listFiles();
    Assert.assertNotNull(segments);/*from  w w  w.  ja  va 2 s . com*/
    Assert.assertEquals(segments.length, 1);
    File[] segmentFiles = segments[0].listFiles();
    Assert.assertNotNull(segmentFiles);
    Assert.assertEquals(segmentFiles.length, 2);
    for (File segmentFile : segmentFiles) {
        String name = segmentFile.getName();
        Assert.assertTrue(name.equals("v3") || name.equals("metadata.properties"));
        if (name.equals("v3")) {
            Assert.assertTrue(segmentFile.isDirectory());
            File[] v3Files = v3Dir.listFiles();
            Assert.assertNotNull(v3Files);
            Assert.assertEquals(v3Files.length, 1);
            Assert.assertEquals(v3Files[0].getName(), "creation.meta");
        }
    }
}

From source file:com.hs.mail.container.config.Config.java

public static File getDataFile(Date date, long physmessageid) throws IOException {
    File directory = new File(dataDirectory, getSubDirectory(date, physmessageid));
    FileUtils.forceMkdir(directory);
    File zipped = new File(directory,
            Long.toString(physmessageid) + FilenameUtils.EXTENSION_SEPARATOR_STR + ZIPFILE_EXTENSION);
    return (zipped.exists()) ? zipped : new File(directory, Long.toString(physmessageid));
}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.RuntimeProvider.java

public File getWorkspace() throws IOException {
    if (workspace == null) {
        workspace = File.createTempFile("dkpro", "runtime");
        FileUtils.forceDelete(workspace);
        FileUtils.forceMkdir(workspace);
        workspace.deleteOnExit();/*  ww w  . j ava 2  s.c o m*/
    }
    return workspace;
}

From source file:com.treesbearfruit.icloudnotes.NotesSaver.java

private void save(Store store, String wheretobackup, String f) throws MessagingException, IOException {

    System.out.println("opening folder " + f);
    Folder folder = store.getFolder(f);//from  w w w.  j a v a  2  s. c  o m
    folder.open(Folder.READ_ONLY);

    FileUtils.forceMkdir(new File(wheretobackup));

    // Get directory
    Message message[] = folder.getMessages();
    for (int i = 0, n = message.length; i < n; i++) {
        // String from = (message[i].getFrom()[0]).toString();
        String subj = (message[i].getSubject()).toString();
        String nota = (message[i].getContent()).toString();

        // System.out.println("from: " + from);
        System.out.println("saving: " + subj);

        // BACKUP NOTE
        generals.writeFile(wheretobackup + "/" + generals.makeFilename(subj).trim() + ".html", nota,
                message[i].getSentDate());

    }
    folder.close(false);
}

From source file:com.commsen.liferay.BuildService.java

public void execute() throws MojoExecutionException {

    String webRootFolder = baseDir.getAbsolutePath() + "/" + webappFolderName;
    String srcFolder = baseDir.getAbsolutePath() + "/" + srcFolderName;
    String srcServiceFolder = baseDir.getAbsolutePath() + "/" + serviceApiFolderName;
    String resourcesFolder = baseDir.getAbsolutePath() + "/" + resourcesFolderName;
    String sqlFolder = webRootFolder + "/WEB-INF/sql";

    File inputFile = new File(webRootFolder + "/WEB-INF/service.xml");
    if (!inputFile.exists()) {
        getLog().warn("No service input file (" + inputFile.getAbsolutePath()
                + ") found! Skipping service API generation!");
        return;//ww w . j a  v  a 2s.c o m
    }
    try {
        FileUtils.forceMkdir(new File(sqlFolder));
    } catch (IOException e) {
        getLog().warn(e);
    }
    System.setProperty("external-properties", "com/liferay/portal/tools/dependencies/portal-tools.properties");
    System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger");
    System.setProperty("service.input.file", inputFile.getAbsolutePath());
    System.setProperty("service.hbm.file", resourcesFolder + "/META-INF/portlet-hbm.xml");
    System.setProperty("service.model.hints.file", resourcesFolder + "/META-INF/portlet-model-hints.xml");
    System.setProperty("service.spring.file", resourcesFolder + "/META-INF/portlet-spring.xml");
    System.setProperty("service.spring.base.file", resourcesFolder + "/META-INF/base-spring.xml");
    System.setProperty("service.spring.dynamic.data.source.file",
            resourcesFolder + "/META-INF/dynamic-data-source-spring.xml");
    System.setProperty("service.spring.hibernate.file", resourcesFolder + "/META-INF/hibernate-spring.xml");
    System.setProperty("service.spring.infrastructure.file",
            resourcesFolder + "/META-INF/infrastructure-spring.xml");
    System.setProperty("service.api.dir", srcServiceFolder);
    System.setProperty("service.impl.dir", srcFolder);
    System.setProperty("service.sql.dir", sqlFolder);
    System.setProperty("service.sql.file", "tables.sql");
    System.setProperty("service.sql.indexes.file", "indexes.sql");
    System.setProperty("service.sql.indexes.properties.file", "indexes.properties");
    System.setProperty("service.sql.sequences.file", "sequences.sql");
    System.setProperty("service.auto.namespace.tables", "true");
    System.setProperty("service.bean.locator.util", "com.liferay.util.bean.PortletBeanLocatorUtil");
    System.setProperty("service.props.util", "com.liferay.util.service.ServiceProps");
    System.setProperty("service.plugin.name", mavenProject.getArtifactId());

    try {
        ClassLoader cl = getClass().getClassLoader();
        Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
        method.setAccessible(true);
        method.invoke(cl, new URL("file://" + resourcesFolder + "/"));
    } catch (Exception e) {
        throw new MojoExecutionException(
                "Failed to modify classloader in order to add resource folder to classpath!", e);
    }

    ServiceBuilder.main(new String[0]);

    if (serviceDependencies != null && !serviceDependencies.isEmpty()) {
        List<Dependency> projectDependecies = mavenProject.getDependencies();
        projectDependecies.addAll(serviceDependencies);
    }
    mavenProject.addCompileSourceRoot(srcServiceFolder);
    File srcServiceProperties = new File(srcFolder, "service.properties");
    File resServiceProperties = new File(resourcesFolder, "service.properties");
    BuildService.deleteQuietly(resServiceProperties);
    try {
        BuildService.moveFile(srcServiceProperties, resServiceProperties);
    } catch (IOException e) {
        getLog().warn(e);
    }
}

From source file:net.firejack.platform.generate.service.BaseGeneratorService.java

protected void generate(Base base, String template, File dir) throws IOException {
    if (base != null && base.getClassPath() != null) {
        dir = new File(dir, base.getFilePosition());
        FileUtils.forceMkdir(dir);
        generator.compose(template, base, new File(dir, base.getFileName()), false);
    }/* w  w  w .j  a  va 2s  .  c o m*/
}

From source file:com.stevpet.sonar.plugins.dotnet.mscover.vstest.clean.CleanTest.java

@Test
public void CorrectDirNoFiles_Ignore() throws IOException {
    VsTestRunner runner = givenANewRunner();
    File placeHolder = TestUtils.getResource(CLEAN_TEST_EMPTY_PLACE_HOLDER_TXT);
    File testDir = new File(placeHolder.getParentFile(), ".sonar");
    FileUtils.forceMkdir(testDir);
    runner.setSonarPath(testDir.getAbsolutePath());
    runner.clean();// w  ww  .j av  a2 s  . com
    assertTrue(testDir.exists());
}

From source file:com.cdancy.artifactory.rest.util.ArtifactoryUtils.java

public static File getGradleFilesDir() {
    File gradleFilesDir = new File(getGradleHome(), "/caches/modules-2/files-2.1");
    if (!gradleFilesDir.exists()) {
        try {//from   w  w w .j  av a  2 s.co m
            FileUtils.forceMkdir(gradleFilesDir);
        } catch (Exception e) {
            Throwables.propagate(e);
        }
    }
    return gradleFilesDir;
}