Example usage for org.apache.commons.io FileUtils cleanDirectory

List of usage examples for org.apache.commons.io FileUtils cleanDirectory

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils cleanDirectory.

Prototype

public static void cleanDirectory(File directory) throws IOException 

Source Link

Document

Cleans a directory without deleting it.

Usage

From source file:net.technicpack.launchercore.modpacks.ModpackModel.java

public void setInstalledDirectory(File targetDirectory) {
    if (installedDirectory != null && installedDirectory.exists()) {
        try {/*from w ww .j  a va2  s .c om*/
            FileUtils.copyDirectory(installedDirectory, targetDirectory);
            FileUtils.cleanDirectory(installedDirectory);
        } catch (IOException ex) {
            Utils.getLogger().log(Level.SEVERE, ex.getMessage(), ex);
            return;
        }
    }

    installedDirectory = targetDirectory;
    String path = installedDirectory.getAbsolutePath();

    if (path.equals(directories.getModpacksDirectory().getAbsolutePath())) {
        installedPack.setDirectory(InstalledPack.MODPACKS_DIR);
    } else if (path.equals(directories.getLauncherDirectory().getAbsolutePath())) {
        installedPack.setDirectory(InstalledPack.LAUNCHER_DIR);
    } else if (path.startsWith(directories.getModpacksDirectory().getAbsolutePath())) {
        installedPack.setDirectory(InstalledPack.MODPACKS_DIR
                + path.substring(directories.getModpacksDirectory().getAbsolutePath().length() + 1));
    } else if (path.startsWith(directories.getLauncherDirectory().getAbsolutePath())) {
        installedPack.setDirectory(InstalledPack.LAUNCHER_DIR
                + path.substring(directories.getLauncherDirectory().getAbsolutePath().length() + 1));
    } else
        installedPack.setDirectory(path);

    save();
}

From source file:nl.b3p.gis.viewer.services.GisSecurityRealm.java

public static synchronized void flushSPCache() {
    boolean cacheOnDisk = HibernateUtil.cacheOnDisk;

    if (cacheOnDisk) {
        try {/*from ww w  .j  a v  a 2s.c o  m*/
            String dir = HibernateUtil.cacheOnDiskPath;
            File directory = new File(dir);

            FileUtils.cleanDirectory(directory);
        } catch (IOException ex) {
            log.error("Fout tijdens verwijderen disk cache.", ex);
        }

        log.debug("Cache on DISK WMS leeggemaakt.");
    } else {
        perUserNameSPCache.clear();
        //perUserNameSPCache = null;
        //perUserNameSPCache = new HashMap();

        log.debug("Cache in MEMORY WMS leeggemaakt.");
    }
}

From source file:nl.mpi.lamus.filesystem.implementation.LamusWorkspaceDirectoryHandlerTest.java

@Before
public void setUp() throws IOException {
    FileUtils.cleanDirectory(this.workspaceBaseDirectory);
    this.workspaceBaseDirectory.setWritable(true);
}

From source file:nl.mpi.lamus.filesystem.implementation.LamusWorkspaceDirectoryHandlerTest.java

@After
public void tearDown() throws IOException {
    FileUtils.cleanDirectory(this.workspaceBaseDirectory);
}

From source file:nl.mpi.lamus.filesystem.implementation.LamusWorkspaceFileHandlerTest.java

@Before
public void setUp() throws IOException {
    FileUtils.cleanDirectory(workspaceBaseDirectory);

    ReflectionTestUtils.setField(workspaceFileHandler, "archiveFileLocationProvider",
            mockArchiveFileLocationProvider);
    ReflectionTestUtils.setField(workspaceFileHandler, "workspaceAccessChecker", mockWorkspaceAccessChecker);
    ReflectionTestUtils.setField(workspaceFileHandler, "archiveFileHelper", mockArchiveFileHelper);
}

From source file:nl.mpi.lamus.filesystem.implementation.LamusWorkspaceFileHandlerTest.java

@After
public void tearDown() throws IOException {
    FileUtils.cleanDirectory(workspaceBaseDirectory);
    if (tempDirectory != null) {
        tempDirectory.setWritable(true);
        FileUtils.cleanDirectory(tempDirectory);
    }/*from   ww  w  .  j  av  a  2s  .  c  o  m*/
    if (anotherTempDirectory != null) {
        anotherTempDirectory.setWritable(true);
        FileUtils.cleanDirectory(anotherTempDirectory);
    }
}

From source file:nl.umcg.westrah.binarymetaanalyzer.BinaryMetaAnalysis.java

public void run() throws IOException {
    initialize();//from   w ww.  java  2  s .com
    loadProbeAnnotation();

    String outdir = settings.getOutput();
    if (usetmp) {
        outdir = tempDir;
    }

    System.out.println("Placing output here: " + outdir);
    outdir = Gpio.formatAsDirectory(outdir);
    Gpio.createDir(outdir);

    System.out.println(
            "Permutations: " + settings.getStartPermutations() + " until " + settings.getNrPermutations());

    String zscoretableheader = null;
    if (settings.isMakezscoretable()) {
        StringBuilder builder = new StringBuilder();
        builder.append("SNP\tAlleles\tAlleleAssessed");
        for (int t = 0; t < traitList.length; t++) {
            builder.append("\t").append(traitList[t].getMetaTraitName()).append("_")
                    .append(traitList[t].getAnnotation());
        }
        zscoretableheader = builder.toString();
    }

    int availableProcessors = Runtime.getRuntime().availableProcessors();
    int cores = settings.getNrThreads();
    if (cores < 1) {
        cores = 1;
    } else if (cores > availableProcessors) {
        cores = availableProcessors;
    }

    System.out.println("Will try to make use of " + cores + " CPU cores");
    System.out.println();

    HashSet<QTLPair> prevSet = null;
    for (int permutation = settings.getStartPermutations(); permutation <= settings
            .getNrPermutations(); permutation++) {
        // load probe annotation and index
        // this particular probe annotation can take multiple probes for a single location into account.

        HashSet<QTLPair> set = new HashSet<>();

        Descriptives.initializeZScoreToPValue();

        // re-intialize for each permutation, just to be sure
        if (permutation > settings.getStartPermutations()) {
            initialize();
            System.out.println("Loading probe annotation from: " + settings.getProbetranslationfile());
            loadProbeAnnotation();
            if (traitList.length == 0) {
                System.err.println("Error: no annotation loaded.");
                System.exit(-1);
            }
        }
        //         clearResultsBuffer();

        // create dataset objects
        System.out.println("Running permutation " + permutation);
        datasets = new BinaryMetaAnalysisDataset[settings.getDatasetlocations().size()];

        System.out.println("Loading datasets");
        for (int d = 0; d < datasets.length; d++) {
            datasets[d] = new BinaryMetaAnalysisDataset(settings.getDatasetlocations().get(d),
                    settings.getDatasetnames().get(d), settings.getDatasetPrefix().get(d), permutation,
                    settings.getDatasetannotations().get(d), probeAnnotation,
                    settings.getFeatureOccuranceScaleMaps().get(d));
        }

        System.out.println("Loaded " + datasets.length + " datasets");

        // create meta-analysis SNP index. have to recreate this every permutation,
        // since the order of SNPs is generated at random.
        System.out.println("Creating SNP index");
        createSNPIndex(outdir);
        System.out.println("Total of " + snpIndex.length + " SNPs");

        System.out.println("Creating probe index");
        createProbeIndex(outdir);
        System.out.println("Total of " + probeIndex.length + " probes");

        // make index of snp/probe combinations, if any specified
        createSNPProbeCombos(outdir);

        // load SNP annotation for SNPs present in dataset
        //         if (snpChr == null) {
        System.out.println("Loading SNP annotation from " + settings.getSNPAnnotationFile());
        loadSNPAnnotation();
        //         }

        // run analysis
        System.out.println("Type of analysis: " + settings.getAnalysisType());
        System.out.println("Cis-window: " + settings.getCisdistance());
        System.out.println("Trans-window: " + settings.getTransdistance());

        TextFile zscoreTableTf = null;
        TextFile zscoreTableTfNrSamples = null;

        if (settings.isMakezscoretable()) {

            String tableoutfile = outdir + "ZScoreMatrix-Permutation" + permutation + ".txt.gz";
            String tableoutfileNrSamples = outdir + "ZScoreMatrixNrSamples-Permutation" + permutation
                    + ".txt.gz";
            if (permutation == 0) {
                tableoutfile = outdir + "ZScoreMatrix.txt.gz";
                tableoutfileNrSamples = outdir + "ZScoreMatrixNrSamples.txt.gz";
            }
            System.out.println("Writing z-score table: " + tableoutfile);
            zscoreTableTf = new TextFile(tableoutfile, TextFile.W, 10 * 1048576);
            zscoreTableTfNrSamples = new TextFile(tableoutfileNrSamples, TextFile.W, 10 * 1048576);

            // write header
            zscoreTableTf.writeln(zscoretableheader);
            zscoreTableTfNrSamples.writeln(zscoretableheader);
        }

        ExecutorService threadPool = Executors.newFixedThreadPool(cores);
        CompletionService<Triple<ArrayList<QTL>, String, String>> pool = new ExecutorCompletionService<Triple<ArrayList<QTL>, String, String>>(
                threadPool);

        maxSavedPvalue = -Double.MAX_VALUE;
        locationToStoreResult = 0;
        bufferHasOverFlown = false;
        System.out.println("Max P: " + maxSavedPvalue + "\tLocationToStoreResult: " + locationToStoreResult);

        System.out.println("Starting meta-analysis");
        ProgressBar pb = new ProgressBar(snpList.length);
        int returned = 0;
        ArrayList<Future> futures = new ArrayList<>();
        for (int snp = 0; snp < snpList.length; snp++) {
            // this can go in different threads..
            boolean outputallzscores = true;
            if (permutation > 0) {
                outputallzscores = fullpermutationoutput;
            }
            BinaryMetaAnalysisTask t = new BinaryMetaAnalysisTask(settings, probeAnnotation, datasets, snpIndex,
                    snpList, snpChr, snpPositions, probeIndex, snpprobeCombos, traitMap, traitList, snp, DEBUG,
                    outputallzscores);
            futures.add(pool.submit(t));
        }

        // give the threadpool the signal to shutdown
        threadPool.shutdown();

        int addcalled = 0;
        while (returned < snpList.length) {
            try {
                Future<Triple<ArrayList<QTL>, String, String>> threadfuture = pool.take();
                if (threadfuture != null) {
                    Triple<ArrayList<QTL>, String, String> result = threadfuture.get();

                    for (QTL q : result.getLeft()) {
                        if (!DEBUG) {
                            addEQTL(q);
                        } else {

                            //                        int snpid = q.getSNPId();
                            //                        MetaQTL4MetaTrait trait = q.getMetaTrait();

                            //                        QTLPair combo = new QTLPair();
                            //                        combo.snpid = snpid;
                            //                        combo.trait = trait;
                            //                        set.add(combo);

                        }

                        addcalled++;
                    }
                    if (settings.isMakezscoretable()) {
                        zscoreTableTf.writeln(result.getMiddle());

                        zscoreTableTfNrSamples.writeln(result.getRight());
                    }
                    result = null;
                    returned++;
                    pb.iterate();
                }
                threadfuture = null;
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
        pb.close();

        if (DEBUG) {
            if (prevSet != null) {
                // compare sets
                TextFile tf = new TextFile(outdir + "debug-p" + permutation + ".txt", TextFile.W);
                for (QTLPair p : prevSet) {
                    if (!set.contains(p)) {
                        tf.writeln(snpList[p.snpid] + "\t" + p.trait.getMetaTraitName());
                    }
                }
                tf.close();
            }
            prevSet = set;
        }

        System.out.println("Snps returned: " + returned + "\tNr of snps submitted: " + snpList.length
                + "\tNr of eQTLs evaluated: " + addcalled);
        System.out.println("Max P: " + maxSavedPvalue + "\tLocationToStoreResult: " + locationToStoreResult);

        if (settings.isMakezscoretable()) {
            zscoreTableTf.close();
            zscoreTableTfNrSamples.close();

            if (usetmp) {

                String filename = "ZScoreMatrix-Permutation" + permutation + ".txt.gz";
                if (permutation == 0) {
                    filename = "ZScoreMatrix.txt.gz";
                }
                File source = new File(tempDir + filename);
                File dest = new File(settings.getOutput() + filename);
                if (dest.exists()) {
                    System.out.println(
                            "Destination file: " + dest.getAbsolutePath() + " exists already.. Deleting!");
                    dest.delete();
                }
                System.out.println(
                        "Moving file: " + tempDir + filename + " --> " + settings.getOutput() + filename);
                FileUtils.moveFile(source, dest);

                filename = "ZScoreMatrixNrSamples-Permutation" + permutation + ".txt.gz";
                if (permutation == 0) {
                    filename = "ZScoreMatrixNrSamples.txt.gz";
                }
                source = new File(tempDir + filename);
                dest = new File(settings.getOutput() + filename);
                if (dest.exists()) {
                    System.out.println(
                            "Destination file: " + dest.getAbsolutePath() + " exists already.. Deleting!");
                    dest.delete();
                }
                System.out.println(
                        "Moving file: " + tempDir + filename + " --> " + settings.getOutput() + filename);
                FileUtils.moveFile(source, dest);
            }
        }

        for (BinaryMetaAnalysisDataset dataset : datasets) {
            dataset.close();
        }

        if (!DEBUG) {
            writeBuffer(outdir, permutation);

        }
    }
    if (usetmp) {
        // move remaining contents of tmp dir to final directory
        File source = new File(tempDir);
        File dest = new File(settings.getOutput());
        FileUtils.copyDirectory(source, dest);
        FileUtils.cleanDirectory(source);
    }
}

From source file:nz.co.testamation.core.mock.sftp.SFTPMockServer.java

@Reset
public void reset() {
    try {/*from  w ww.  j a  va2 s .c o  m*/
        FileUtils.cleanDirectory(rootDir);
        for (String directory : defaultDirectories) {
            createDirOrFile(directory, true);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:opennlp.tools.parse_thicket.kernel_interface.style_classif.TSNE_ImporterProcessor.java

public void importFileCreatClassifDirs() {
    Map<Integer, String> id_Text = new HashMap<Integer, String>();
    Map<Integer, String> id_Label = new HashMap<Integer, String>();

    try {/*  ww  w .j  a  v a  2 s  .  c  o m*/
        FileUtils.cleanDirectory(new File(resourceWorkDir + "/txt"));
    } catch (IOException e2) {
        e2.printStackTrace();
    }

    String text = null;
    try {
        text = FileUtils.readFileToString(new File(resourceWorkDir + importFilePath),
                Charset.defaultCharset().toString());
    } catch (IOException e) {

        e.printStackTrace();
    }

    String[] portions = StringUtils.substringsBetween(text, "<text ", "/text>");
    for (int i = 0; i < portions.length; i++) {
        String label = StringUtils.substringBetween(portions[i], "id=\"", "\">");
        String po = StringUtils.substringBetween(portions[i], "\">", "<");
        id_Text.put(i, po);
        id_Label.put(i, label);
        if (true) {
            String localDirName = label.substring(0, 4);
            if (!new File(resourceWorkDir + "txt/" + localDirName).exists())
                try {
                    FileUtils.forceMkdir(new File(resourceWorkDir + "txt/" + localDirName));
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            try {
                label = label.replace('/', '_');
                String fullPath = resourceWorkDir + "txt/" + localDirName + "/" + i + label + ".txt";
                FileUtils.writeStringToFile(new File(fullPath), po);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}

From source file:org.abs_models.backend.erlang.ErlApp.java

public ErlApp(File destDir, File http_index_file, File http_static_dir)
        throws IOException, InternalBackendException {
    // FIXME this should probably be a method; strange to have a
    // class which does all its work in the constructor
    super();//from  w  w  w  .java  2  s  . c  om
    this.destDir = destDir;
    this.destCodeDir = new File(destDir, "absmodel/src/");
    this.destIncludeDir = new File(destDir, "absmodel/include/");
    destDir.mkdirs();
    FileUtils.cleanDirectory(destDir);
    destDir.mkdirs();
    new File(destDir, "absmodel/ebin").mkdir();
    index_file = http_index_file;
    static_dir = http_static_dir;
    if (static_dir != null && !static_dir.isDirectory()) {
        throw new InternalBackendException("Please provide a directory with static files");
    }
    copyRuntime();
}