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.ariht.maven.plugins.config.ConfigProcessorMojo.java

/**
 * Prepare output directory: base-path/filter-sub-dir/template-dir/template.name
 *///  w  w  w  .j  a v  a  2s  . c o  m
private String createOutputDirectory(final FileInfo template, final FileInfo filter,
        final String outputBasePath) throws IOException {
    final String outputDirectory = getOutputPath(template, filter, outputBasePath);
    final File outputDir = new File(outputDirectory);
    if (!outputDir.exists()) {
        getLog().debug("Creating : " + outputDir);
        FileUtils.forceMkdir(outputDir);
    }
    return FilenameUtils.normalize(outputDirectory);
}

From source file:com.wavemaker.commons.util.IOUtils.java

/**
 * Copy from: file to file, directory to directory, file to directory.
 *
 * @param source File object representing a file or directory to copy from.
 * @param destination File object representing the target; can only represent a file if the source is a file.
 * @param excludes A list of exclusion filenames.
 * @throws IOException//  w  w  w .  ja va  2s  .co m
 */
public static void copy(File source, File destination, List<String> excludes) throws IOException {

    if (!source.exists()) {
        throw new IOException("Can't copy from non-existent file: " + source.getAbsolutePath());
    } else if (excludes.contains(source.getName())) {
        return;
    }

    if (source.isDirectory()) {
        if (!destination.exists()) {
            FileUtils.forceMkdir(destination);
        }
        if (!destination.isDirectory()) {
            throw new IOException("Can't copy directory (" + source.getAbsolutePath() + ") to non-directory: "
                    + destination.getAbsolutePath());
        }

        File files[] = source.listFiles(new WMFileNameFilter());
        for (int i = 0; i < files.length; i++) {
            copy(files[i], new File(destination, files[i].getName()), excludes);
        }
    } else if (source.isFile()) {
        if (destination.isDirectory()) {
            destination = new File(destination, source.getName());
        }

        InputStream in = new FileInputStream(source);
        OutputStream out = new FileOutputStream(destination);

        copy(in, out, true, true);

    } else {
        throw new IOException(
                "Don't know how to copy " + source.getAbsolutePath() + "; it's neither a directory nor a file");
    }
}

From source file:com.adr.mimame.PlatformList.java

public Image getCachedImage(String url) {

    if (url == null) {
        return null;
    } else if (!"http".equalsIgnoreCase(url.substring(0, 4)) && !"ftp".equalsIgnoreCase(url.substring(0, 3))) {
        // a local image
        return new Image(url, true);
    } else {//from  w  ww .j a  v  a 2s  .  c  om
        // a remote image
        try {
            File cachedir = new File(mimamememuhome, "IMGCACHE");
            FileUtils.forceMkdir(cachedir);

            MessageDigest md = MessageDigest.getInstance("SHA-256");
            md.update(url.getBytes("UTF-8"));
            String cachefilename = Base64.getUrlEncoder().encodeToString(md.digest());
            File cachefile = new File(cachedir, cachefilename + ".png");
            File cachefilenull = new File(cachedir, cachefilename + ".null");

            if (cachefilenull.exists()) {
                return null;
            } else if (cachefile.exists()) {
                return new Image(cachefile.toURI().toURL().toString(), true);
            } else {
                Image img = new Image(url, true);
                img.progressProperty().addListener(
                        (ObservableValue<? extends Number> observable, Number oldValue, Number newValue) -> {
                            if (newValue.doubleValue() == 1.0) {
                                exec.execute(() -> {
                                    try {
                                        if (img.isError()) {
                                            cachefilenull.createNewFile();
                                        } else {
                                            ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png",
                                                    cachefile);
                                        }
                                    } catch (IOException ex) {
                                        logger.log(Level.SEVERE, "Cannot save image cache.", ex);
                                    }
                                });
                            }
                        });
                return img;
            }
        } catch (IOException | NoSuchAlgorithmException ex) {
            logger.log(Level.SEVERE, "Cannot create image cache.", ex);
            return new Image(url);
        }
    }
}

From source file:com.zaba37.easyreader.actions.menuBar.ImageBackgroundLoader.java

private String createUnixOrMacDirectory(String mainPath) {
    mainPath = mainPath.substring(0, mainPath.lastIndexOf(File.separator));
    mainPath = mainPath + File.separator + ".TmpEasyReaderImageDirectory";
    File file = new File(mainPath);

    try {/*  w w w  .  j a v a 2 s  .c o m*/
        if (file.exists()) {
            FileUtils.forceDelete(file);
        }

        FileUtils.forceMkdir(file);
    } catch (IOException ex) {
        Logger.getLogger(ImageBackgroundLoader.class.getName()).log(Level.SEVERE, null, ex);
    }

    return file.getPath();
}

From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java

/**
 * Export all collections in the repository.
 * //from w  w w. j  av a  2 s. c om
 * @param repository - repository to export
 * @throws IOException 
 */
public void export(Repository repository, File zipFileDestination) throws IOException {
    // create the path if it doesn't exist
    String path = FilenameUtils.getPath(zipFileDestination.getCanonicalPath());
    if (!path.equals("")) {
        File pathOnly = new File(FilenameUtils.getFullPath(zipFileDestination.getCanonicalPath()));
        FileUtils.forceMkdir(pathOnly);
    }

    File collectionXmlFile = temporaryFileCreator.createTemporaryFile(extension);
    Set<FileInfo> allPictures = createXmlFile(collectionXmlFile, repository.getInstitutionalCollections(),
            true);

    FileOutputStream out = new FileOutputStream(zipFileDestination);
    ArchiveOutputStream os = null;
    try {
        os = new ArchiveStreamFactory().createArchiveOutputStream("zip", out);
        os.putArchiveEntry(new ZipArchiveEntry("collection.xml"));

        FileInputStream fis = null;
        try {
            log.debug("adding xml file");
            fis = new FileInputStream(collectionXmlFile);
            IOUtils.copy(fis, os);
        } finally {
            if (fis != null) {
                fis.close();
                fis = null;
            }
        }

        log.debug("adding pictures size " + allPictures.size());
        for (FileInfo fileInfo : allPictures) {
            File f = new File(fileInfo.getFullPath());
            String name = FilenameUtils.getName(fileInfo.getFullPath());
            name = name + '.' + fileInfo.getExtension();
            log.debug(" adding name " + name);
            os.putArchiveEntry(new ZipArchiveEntry(name));
            try {
                log.debug("adding input stream");
                fis = new FileInputStream(f);
                IOUtils.copy(fis, os);
            } finally {
                if (fis != null) {
                    fis.close();
                    fis = null;
                }
            }
        }

        os.closeArchiveEntry();
        out.flush();
    } catch (ArchiveException e) {
        throw new IOException(e);
    } finally {
        if (os != null) {
            os.close();
            os = null;
        }
    }

    FileUtils.deleteQuietly(collectionXmlFile);

}

From source file:gov.nih.nci.caintegrator.application.analysis.grid.preprocess.PreprocessDatasetGridRunner.java

private File replaceGctFileWithPreprocessed(File gctFile, File zipFile) throws IOException {
    File zipFileDirectory = new File(zipFile.getParent().concat("/tempPreprocessedZipDir"));
    FileUtils.deleteDirectory(zipFileDirectory);
    FileUtils.forceMkdir(zipFileDirectory);
    FileUtils.waitFor(zipFileDirectory, TIMEOUT_SECONDS);
    Cai2Util.isValidZipFile(zipFile);
    ZipUtilities.unzip(zipFile, zipFileDirectory);
    FileUtils.waitFor(zipFileDirectory, TIMEOUT_SECONDS);
    Cai2Util.printDirContents(zipFileDirectory);
    if (zipFileDirectory.list() != null) {
        if (zipFileDirectory.list().length != 1) {
            int dirListlength = zipFileDirectory.list().length;
            FileUtils.deleteDirectory(zipFileDirectory);
            throw new IllegalStateException("The zip file returned from PreprocessDataset"
                    + " should have exactly 1 file instead of " + dirListlength);
        }//from  www .  j  av a2s.c  om
    } else {
        String zipFileDirectoryPath = zipFileDirectory.getAbsolutePath();
        FileUtils.deleteDirectory(zipFileDirectory);
        throw new IllegalStateException(
                "The zip file directory list at path: " + zipFileDirectoryPath + "is null.");
    }
    String[] files = zipFileDirectory.list();
    File preprocessedFile = new File(zipFileDirectory, files[0]);
    FileUtils.deleteQuietly(gctFile); // Remove the non-preprocessed file
    FileUtils.moveFile(preprocessedFile, gctFile); // move to gctFile
    FileUtils.deleteQuietly(zipFile);
    FileUtils.deleteDirectory(zipFileDirectory);
    return gctFile;
}

From source file:com.talis.entity.db.babudb.bulk.BabuDbEntityDatabaseBuilder.java

private void initWorkingDirs(File rootDir) throws IOException {
    LOG.info("Initialising Database root directory: {}", rootDir.getAbsolutePath());
    if (!rootDir.isDirectory() && rootDir.exists()) {
        String msg = String.format("Invalid Database root: {}", rootDir.getAbsolutePath());
        LOG.error(msg);/*from   w  w w  .  ja  v  a 2 s.  com*/
        throw new RuntimeException(msg);
    }
    FileUtils.forceMkdir(rootDir);
    FileUtils.cleanDirectory(rootDir);
}

From source file:berlin.iconn.persistence.InOutOperations.java

public static final void mkdir(String path) throws IOException {
    File file = new File(path);
    if (!file.isDirectory()) {
        FileUtils.forceMkdir(file);
    }//from w  ww . j  a v  a  2 s . c  o  m
}

From source file:net.sourceforge.atunes.kernel.modules.audioscrobbler.AudioScrobblerCache.java

/**
 * Private getter for albumInfoCacheDir. If dir does not exist, it's created
 * /*from   w ww. j  ava  2s.  co  m*/
 * @return
 * @throws IOException
 */
private static synchronized File getAlbumInfoCacheDir() throws IOException {
    if (!albumInfoCacheDir.exists())
        FileUtils.forceMkdir(albumInfoCacheDir);
    return albumInfoCacheDir;
}