Example usage for java.nio.file Files delete

List of usage examples for java.nio.file Files delete

Introduction

In this page you can find the example usage for java.nio.file Files delete.

Prototype

public static void delete(Path path) throws IOException 

Source Link

Document

Deletes a file.

Usage

From source file:com.clust4j.algo.HierarchicalTests.java

@Test
@Override/*from  w  w  w .  jav a 2 s.c  o m*/
public void testSerialization() throws IOException, ClassNotFoundException {
    HierarchicalAgglomerative agglom = new HierarchicalAgglomerative(matrix,
            new HierarchicalAgglomerativeParameters().setVerbose(true)).fit();

    final int[] l = agglom.getLabels();
    agglom.saveObject(new FileOutputStream(TestSuite.tmpSerPath));
    assertTrue(TestSuite.file.exists());

    HierarchicalAgglomerative agglom2 = (HierarchicalAgglomerative) HierarchicalAgglomerative
            .loadObject(new FileInputStream(TestSuite.tmpSerPath));

    // test re-fit:
    agglom2 = agglom2.fit();

    assertTrue(VecUtils.equalsExactly(l, agglom2.getLabels()));
    assertTrue(agglom2.equals(agglom));
    Files.delete(TestSuite.path);
}

From source file:org.apache.tika.batch.fs.FSBatchTestBase.java

public static void deleteDirectory(Path dir) throws IOException {
    Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
        @Override//from  w ww. jav  a2  s .  c  om
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }

    });
}

From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java

License:asdf

@AfterClass
public static void testdownClass() throws IOException {
    Files.walkFileTree(tempFolder, new SimpleFileVisitor<Path>() {
        @Override/*from ww w  . j  a va 2s .  c o m*/
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:com.clust4j.algo.RadiusNeighborsTests.java

@Test
@Override//from w ww .  ja va  2  s .c  o m
public void testSerialization() throws IOException, ClassNotFoundException {
    RadiusNeighbors nn = new RadiusNeighbors(iris, new RadiusNeighborsParameters(5.0).setVerbose(true)).fit();

    final int[][] c = nn.getNeighbors().getIndices();
    nn.saveObject(new FileOutputStream(TestSuite.tmpSerPath));
    assertTrue(TestSuite.file.exists());

    RadiusNeighbors nn2 = (RadiusNeighbors) RadiusNeighbors
            .loadObject(new FileInputStream(TestSuite.tmpSerPath));
    assertTrue(MatUtils.equalsExactly(nn2.getNeighbors().getIndices(), c));
    assertTrue(nn2.equals(nn));
    assertTrue(nn.equals(nn)); // test the ref return
    assertFalse(nn.equals(new Object()));

    Files.delete(TestSuite.path);
}

From source file:com.sastix.cms.server.services.content.HashedDirectoryServiceTest.java

private void deleteRecursive(Path path) throws IOException {
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
        @Override/* w w  w . j a  v  a2 s. com*/
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:org.spongepowered.common.world.WorldMigrator.java

/**
 * The last step of migration involves cleaning up folders within the world folders that match Vanilla dimension names (DIM-1/DIM1).
 *
 * @param worldPath The path to inspect//from  www . j  ava 2s  . co  m
 */
private static void removeInnerNameFolder(Path worldPath) {
    // We successfully copied the region folder elsewhere so now delete the DIM-1/DIM1 inside
    try {
        Files.delete(worldPath.resolve("DIM-1"));
    } catch (IOException ignore) {
    }

    try {
        Files.delete(worldPath.resolve("DIM1"));
    } catch (IOException ignore) {
    }
}

From source file:org.niord.core.batch.BatchSetService.java

/**
 * Called every minute to monitor the "batch-sets" folder. If a batch-set zip file has been
 * placed in this folder, the batch-set gets executed.
 */// w w w.j  av a 2 s.  c  o  m
@Schedule(persistent = false, second = "24", minute = "*/1", hour = "*/1")
protected void monitorBatchJobInFolderInitiation() {

    Path batchSetsFolder = batchService.getBatchJobRoot().resolve(BATCH_SETS_FOLDER);

    if (Files.isDirectory(batchSetsFolder)) {
        try (DirectoryStream<Path> stream = Files.newDirectoryStream(batchSetsFolder)) {
            for (Path p : stream) {
                if (Files.isReadable(p) && Files.isRegularFile(p)) {
                    try {
                        executeBatchSetFromArchiveOrFolder(p);
                    } catch (Exception e) {
                        log.error("Error executing batch set " + p, e);
                    } finally {
                        // Delete the file
                        try {
                            Files.delete(p);
                        } catch (IOException ignored) {
                        }
                    }
                }
            }
        } catch (IOException ignored) {
        }
    }
}

From source file:de.ingrid.interfaces.csw.jobs.UpdateJob.java

/**
 * Write the last execution date of this job.
 *
 * @param Date/*from   w  w w  . j av  a  2  s.c o  m*/
 */
public void writeLastExecutionDate(Date date) {
    File dateFile = new File(DATE_FILENAME);

    try {
        Writer output = new BufferedWriter(new FileWriter(dateFile));
        output.write(DATEFORMAT.format(date));
        output.close();
    } catch (Exception e) {
        // delete the date file to make sure we do not use a corrupted
        // version
        if (Files.exists(dateFile.toPath()))
            try {
                Files.delete(dateFile.toPath());
            } catch (IOException e1) {
                log.error("Could not remove " + dateFile + ".", e1);
            }
        log.warn(
                "Could not write to " + DATE_FILENAME + ". " + "The update job fetches all records next time.");
    }
}

From source file:org.apache.archiva.indexer.maven.search.AbstractMavenRepositorySearch.java

protected void createIndex(String repository, List<Path> filesToBeIndexed, boolean scan, Path indexDir)
        throws Exception {
    Repository rRepo = repositoryRegistry.getRepository(repository);
    IndexCreationFeature icf = rRepo.getFeature(IndexCreationFeature.class).get();

    IndexingContext context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);

    if (context != null) {
        context.close(true);/*  w ww  .  jav a 2 s.  c om*/
    }

    Path repoDir = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir()).resolve("target")
            .resolve("repos").resolve(repository);

    Path indexerDirectory = repoDir.resolve(".indexer");

    if (Files.exists(indexerDirectory)) {
        FileUtils.deleteDirectory(indexerDirectory);
    }

    assertFalse(Files.exists(indexerDirectory));

    Path lockFile = repoDir.resolve(".indexer/write.lock");
    if (Files.exists(lockFile)) {
        Files.delete(lockFile);
    }

    assertFalse(Files.exists(lockFile));

    Path repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "src/test/" + repository);
    assertTrue(Files.exists(repo));
    org.apache.commons.io.FileUtils.copyDirectory(repo.toFile(), repoDir.toFile());

    if (indexDir == null) {
        Path indexDirectory = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(),
                "target/index/test-" + Long.toString(System.currentTimeMillis()));
        indexDirectory.toFile().deleteOnExit();
        FileUtils.deleteDirectory(indexDirectory);
        icf.setIndexPath(indexDirectory.toUri());
    } else {

        icf.setIndexPath(indexDir.toUri());
    }
    context = rRepo.getIndexingContext().getBaseContext(IndexingContext.class);

    // minimize datas in memory
    //        context.getIndexWriter().setMaxBufferedDocs( -1 );
    //        context.getIndexWriter().setRAMBufferSizeMB( 1 );
    for (Path artifactFile : filesToBeIndexed) {
        assertTrue("file not exists " + artifactFile, Files.exists(artifactFile));
        ArtifactContext ac = artifactContextProducer.getArtifactContext(context, artifactFile.toFile());

        if (artifactFile.toString().endsWith(".pom")) {
            ac.getArtifactInfo().setFileExtension("pom");
            ac.getArtifactInfo().setPackaging("pom");
            ac.getArtifactInfo().setClassifier("pom");
        }
        indexer.addArtifactToIndex(ac, context);
        context.updateTimestamp(true);
    }

    if (scan) {
        DefaultScannerListener listener = new DefaultScannerListener(context, indexerEngine, true,
                new ArtifactScanListener());
        ScanningRequest req = new ScanningRequest(context, listener);
        scanner.scan(req);
        context.commit();
    }
    // force flushing
    context.commit();
    //  context.getIndexWriter().commit();
    context.setSearchable(true);

}

From source file:org.transitime.applications.GtfsFileProcessor.java

/**
 * Cleans up GTFS files. Specifically, if unzipped a GTFS zip file then
 * removes the .txt files from gtfsDirectoryName since they can be quite
 * large and don't need them around anymore.
 *//*from  www . ja  v a2 s  .  c  o  m*/
private void cleanupGtfsFiles() {
    // Only need to cleanup if unzipped a zip file
    if (gtfsZipFileName == null)
        return;

    try {
        File f = new File(gtfsDirectoryName);
        String fileNames[] = f.list();
        for (String fileName : fileNames) {
            if (fileName.endsWith(".txt")) {
                Files.delete(Paths.get(gtfsDirectoryName, fileName));
            }
        }
    } catch (Exception e) {
        logger.error("Exception when cleaning up GTFS files", e);
    }
}