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.silverpeas.directory.servlets.ImageProfilTest.java

@BeforeClass
public static void prepareDir() throws IOException {
    FileUtils.forceMkdir(new File(TEMP_DIRECTORY));
    FileUtils.copyFileToDirectory(new File(SOURCE_FILE), new File(TEMP_DIRECTORY));
}

From source file:com.github.ipaas.ideploy.agent.util.ZipUtil.java

/**
 * /*from  w  w w.ja v  a2  s  .c o  m*/
 * @param srcFile  ?
 * @param targetDir 
 * @throws Exception
 */
public static void unZip(String zipFile, String targetDir) throws Exception {
    ZipFile zipfile = new ZipFile(zipFile);
    try {
        Enumeration<ZipEntry> entries = zipfile.getEntries();
        if (entries == null || !entries.hasMoreElements()) {
            return;
        }
        //  
        FileUtils.forceMkdir(new File(targetDir));

        // ??

        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            String fname = zipEntry.getName();

            // 

            if (zipEntry.isDirectory()) {
                String fpath = FilenameUtils.normalize(targetDir + "/" + fname);
                FileUtils.forceMkdir(new File(fpath));
                continue;

            }
            // ?

            if (StringUtils.contains(fname, "/")) {
                String tpath = StringUtils.substringBeforeLast(fname, "/");
                String fpath = FilenameUtils.normalize(targetDir + "/" + tpath);
                FileUtils.forceMkdir(new File(fpath));
            }
            // ? 
            InputStream input = null;
            OutputStream output = null;

            try {
                input = zipfile.getInputStream(zipEntry);
                String file = FilenameUtils.normalize(targetDir + "/" + fname);
                output = new FileOutputStream(file);
                IOUtils.copy(input, output);
            } finally {
                IOUtils.closeQuietly(input);
                IOUtils.closeQuietly(output);
            }
        }
    } finally {
        ZipFile.closeQuietly(zipfile);
    }

}

From source file:com.meltmedia.cadmium.maven.ArtifactResolverTest.java

@Test
public void testResolveArtifact() throws Exception {
    File localRepo = new File("./target/.m2");
    if (localRepo.exists()) {
        FileUtils.cleanDirectory(localRepo);
    }// ww  w  . j  a  v  a2s  .  c  om
    FileUtils.forceMkdir(localRepo);
    ArtifactResolver resolver = new ArtifactResolver(null, localRepo.getAbsolutePath());
    File artifact = resolver.resolveMavenArtifact("org.apache.maven:maven-artifact:3.0.4");
    System.err.println("Artifact is downloaded to: " + artifact.getAbsolutePath());
    assertTrue("Artifact not downloaded.", artifact.exists());
    assertTrue("Artifact cannot be read.", artifact.canRead());
    assertTrue("Artifact points to empty file.", artifact.lastModified() > 0l);
}

From source file:ml.shifu.shifu.util.HDFSUtilsTest.java

@Test
public void test() throws IOException, IntrospectionException {
    File tmp = new File("tmp");
    if (!tmp.exists()) {
        FileUtils.forceMkdir(tmp);
    }// w  w  w .  ja  v a  2  s.  c  om

    // HDFSUtils utils = null;
    //utils = new HDFSUtils();

    //utils.deleteFolder("tmp");

    HDFSUtils.getLocalFS().delete(new Path("tmp"), true);

    Assert.assertTrue(!tmp.exists());
}

From source file:com.alexholmes.hadooputils.TestBase.java

@Before
public void before() throws IOException {
    if (TEST_ROOT_DIR.exists()) {
        FileUtils.forceDelete(TEST_ROOT_DIR);
    }/*w w w  . j  ava  2s  .  com*/
    FileUtils.forceMkdir(TEST_ROOT_DIR);
}

From source file:edu.ur.util.FileUtil.java

/**
 * Create a directory in the specified location.
 *
 * @param directory to create//from  www. j a va 2  s . co  m
 */
public void createDirectory(File directory) {
    try {
        FileUtils.forceMkdir(directory);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:ch.vorburger.mariadb4j.Util.java

/**
 * Retrieve the directory located at the given path. Checks that path indeed is a reabable
 * directory. If this does not exist, create it (and log having done so).
 * /* www .  j a  v  a  2 s  .  c o  m*/
 * @param path directory(ies, can include parent directories) names, as forward slash ('/')
 *            separated String
 * @return safe File object representing that path name
 * @throws IllegalArgumentException If it is not a directory, or it is not readable
 */
public static File getDirectory(String path) {
    boolean log = false;
    File dir = new File(path);
    if (!dir.exists()) {
        log = true;
        try {
            FileUtils.forceMkdir(dir);
        } catch (IOException e) {
            throw new IllegalArgumentException("Unable to create new directory at path: " + path, e);
        }
    }
    String absPath = dir.getAbsolutePath();
    if (absPath.trim().length() == 0) {
        throw new IllegalArgumentException(path + " is empty");
    }
    if (!dir.isDirectory()) {
        throw new IllegalArgumentException(path + " is not a directory");
    }
    if (!dir.canRead()) {
        throw new IllegalArgumentException(path + " is not a readable directory");
    }
    if (log) {
        logger.info("Created directory: " + absPath);
    }
    return dir;
}

From source file:com.jwm123.loggly.reporter.AppDirectory.java

public File getFileDir(String relativePath) throws IOException {
    File relFile = new File(appDir, relativePath);
    if (!relFile.getParentFile().exists()) {
        FileUtils.forceMkdir(relFile.getParentFile());
    }//ww w.  ja v  a  2s  . c o  m
    return relFile;
}

From source file:com.liferay.arquillian.maven.importer.LiferayPluginTestCase.java

protected static void setupPortalMinimal() {
    System.setProperty("liferay.version", LIFERAY_VERSION);

    System.setProperty("liferay.auto.deploy.dir", PORTAL_AUTO_DEPLOY_DIR);

    System.setProperty("liferay.app.server.deploy.dir", PORTAL_SERVER_DEPLOY_DIR);

    System.setProperty("liferay.app.server.lib.global.dir", PORTAL_SERVER_LIB_GLOBAL_DIR);

    System.setProperty("liferay.app.server.portal.dir", SERVER_PORTAL_DIR);

    try {/*from ww  w  .  jav  a  2 s.co m*/
        ArchiverManager archiverManager = plexusContainer.lookup(ArchiverManager.class);

        assertNotNull(archiverManager);

        FileUtils.forceMkdir(new File(PORTAL_AUTO_DEPLOY_DIR));
        FileUtils.forceMkdir(new File(PORTAL_SERVER_DEPLOY_DIR));
        FileUtils.forceMkdir(new File(PORTAL_SERVER_LIB_GLOBAL_DIR));
        FileUtils.forceMkdir(new File(SERVER_PORTAL_DIR));

        final MavenResolverSystem mavenResolverSystem = Maven.configureResolver()
                .fromClassloaderResource("settings.xml");

        File[] dependencies = mavenResolverSystem.loadPomFromClassLoaderResource("liferay-setup.xml")
                .importRuntimeAndTestDependencies().resolve().withoutTransitivity().asFile();

        File warFile = null;

        for (File file : dependencies) {
            String fileName = file.getName();
            String fileExtension = FilenameUtils.getExtension(fileName);

            if (fileExtension.equalsIgnoreCase("jar")) {
                FileUtils.copyFile(file, new File(PORTAL_SERVER_LIB_GLOBAL_DIR, file.getName()));
            } else if (fileExtension.equalsIgnoreCase("war") && fileName.contains("portal-web")) {

                warFile = file;
            }
        }

        assertNotNull(warFile);

        // extract portal war

        UnArchiver unArchiver = archiverManager.getUnArchiver(warFile);
        unArchiver.setDestDirectory(new File(SERVER_PORTAL_DIR));
        unArchiver.setSourceFile(warFile);
        unArchiver.setOverwrite(false);
        unArchiver.extract();
        setup = true;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.leverno.ysbos.item.domain.ItemTest.java

public void setUp() throws Exception {
    super.setUp();

    rootFolder = new String("/tmp/archiverTest/");
    FileUtils.forceMkdir(new File(rootFolder));

    fileOne = new File(String.format("%s/one", rootFolder));
    FileUtils.touch(fileOne);//from  w  ww.j  a  va 2s . c  om
}