List of usage examples for java.nio.file Files delete
public static void delete(Path path) throws IOException
From source file:cc.arduino.contributions.packages.ContributionInstaller.java
private void downloadIndexAndSignature(MultiStepProgress progress, List<String> downloadedPackagedIndexFilesAccumulator, String packageIndexUrl, ProgressListener progressListener) throws Exception { File packageIndex = download(progress, packageIndexUrl, progressListener); downloadedPackagedIndexFilesAccumulator.add(packageIndex.getName()); try {/*from w w w . j a va 2s . c o m*/ File packageIndexSignature = download(progress, packageIndexUrl + ".sig", progressListener); boolean signatureVerified = signatureVerifier.isSigned(packageIndex); if (signatureVerified) { downloadedPackagedIndexFilesAccumulator.add(packageIndexSignature.getName()); } else { downloadedPackagedIndexFilesAccumulator.remove(packageIndex.getName()); Files.delete(packageIndex.toPath()); Files.delete(packageIndexSignature.toPath()); System.err.println( I18n.format(tr("{0} file signature verification failed. File ignored."), packageIndexUrl)); } } catch (Exception e) { //ignore errors } }
From source file:org.sonarsource.scanner.cli.ConfTest.java
@Test public void shouldNotResolveSymlinks() throws IOException, URISyntaxException { assumeTrue(SystemUtils.IS_OS_UNIX);/*from w w w.j a va 2 s.c o m*/ Path root = temp.getRoot().toPath(); Path realProjectHome = Paths .get(getClass().getResource("ConfTest/shouldLoadModuleConfiguration/project").toURI()); Path linkProjectHome = root.resolve("link"); try { Files.createSymbolicLink(linkProjectHome, realProjectHome); args.setProperty("project.home", linkProjectHome.toAbsolutePath().toString()); Properties properties = conf.properties(); assertThat(properties.getProperty("module1.sonar.projectName")).isEqualTo("Module 1"); assertThat(properties.getProperty("module2.sonar.projectName")).isEqualTo("Module 2"); assertThat(properties.getProperty("sonar.projectBaseDir")).isEqualTo(linkProjectHome.toString()); assertThat(properties.getProperty("module1.sonar.projectBaseDir")) .isEqualTo(linkProjectHome.resolve("module1").toString()); assertThat(properties.getProperty("module2.sonar.projectBaseDir")) .isEqualTo(linkProjectHome.resolve("module2").toString()); } finally { if (linkProjectHome != null) { Files.delete(linkProjectHome); } } }
From source file:com.github.tteofili.looseen.Test20NewsgroupsClassification.java
private void delete(Path... paths) throws IOException { for (Path path : paths) { if (Files.isDirectory(path)) { Stream<Path> pathStream = Files.list(path); Iterator<Path> iterator = pathStream.iterator(); while (iterator.hasNext()) { Files.delete(iterator.next()); }/*w w w .j ava 2 s .co m*/ } } }
From source file:org.sejda.core.service.TaskTestContext.java
@Override public void close() throws IOException { IOUtils.closeQuietly(streamOutput);/* w w w.jav a 2s . c om*/ this.streamOutput = null; IOUtils.closeQuietly(outputDocument); this.outputDocument = null; if (nonNull(fileOutput)) { if (fileOutput.isDirectory()) { Files.walkFileTree(fileOutput.toPath(), new SimpleFileVisitor<Path>() { @Override 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; } }); } Files.deleteIfExists(fileOutput.toPath()); } this.fileOutput = null; }
From source file:org.apache.solr.schema.TestManagedSchema.java
public void testAddSameFieldTwice() throws Exception { deleteCore();/*ww w . java 2 s.c om*/ File managedSchemaFile = new File(tmpConfDir, "managed-schema"); Files.delete(managedSchemaFile.toPath()); // Delete managed-schema so it won't block parsing a new schema System.setProperty("managed.schema.mutable", "true"); initCore("solrconfig-managed-schema.xml", "schema-one-field-no-dynamic-field.xml", tmpSolrHome.getPath()); Map<String, Object> options = new HashMap<>(); options.put("stored", "false"); IndexSchema oldSchema = h.getCore().getLatestSchema(); String fieldName = "new_field"; String fieldType = "text"; SchemaField newField = oldSchema.newField(fieldName, fieldType, options); IndexSchema newSchema = oldSchema.addField(newField); h.getCore().setLatestSchema(newSchema); String errString = "Field 'new_field' already exists."; ignoreException(Pattern.quote(errString)); try { newSchema = newSchema.addField(newField); h.getCore().setLatestSchema(newSchema); fail("Should fail when adding the same field twice"); } catch (Exception e) { for (Throwable t = e; t != null; t = t.getCause()) { // short circuit out if we found what we expected if (t.getMessage() != null && -1 != t.getMessage().indexOf(errString)) return; } // otherwise, rethrow it, possibly completely unrelated throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unexpected error, expected error matching: " + errString, e); } finally { resetExceptionIgnores(); } }
From source file:org.codice.ddf.platform.migratable.impl.PlatformMigratableTest.java
/** Verifies that when an optional file is missing the export succeeds and so does the import. */ @Test/* w w w . ja v a 2s. c o m*/ public void testDoExportAndDoImportOptionalFileNotExported() throws IOException { // Setup export Path exportDir = tempDir.getRoot().toPath().toRealPath(); // Delete etc/users.properties. This file is optional, so it will not generate // an error during export. Files.delete(ddfHome.resolve("etc").resolve("users.properties").toRealPath()); List<Path> optionalFilesExported = OPTIONAL_SYSTEM_FILES.stream() .filter(p -> !p.equals(Paths.get("etc", "users.properties"))).collect(Collectors.toList()); MigrationReport exportReport = doExport(exportDir); // Verify export assertThat("The export report has errors.", exportReport.hasErrors(), is(false)); assertThat("The export report has warnings.", exportReport.hasWarnings(), is(false)); assertThat("Export was not successful.", exportReport.wasSuccessful(), is(true)); String exportedZipBaseName = String.format("%s-%s.dar", SUPPORTED_BRANDING, SUPPORTED_VERSION); Path exportedZip = exportDir.resolve(exportedZipBaseName).toRealPath(); assertThat("Export zip does not exist.", exportedZip.toFile().exists(), is(true)); assertThat("Exported zip is empty.", exportedZip.toFile().length(), greaterThan(0L)); // Setup import setup(DDF_IMPORTED_HOME, DDF_IMPORTED_TAG, SUPPORTED_VERSION); PlatformMigratable iPlatformMigratable = new PlatformMigratable(); List<Migratable> iMigratables = Arrays.asList(iPlatformMigratable); ConfigurationMigrationManager iConfigurationMigrationManager = new ConfigurationMigrationManager( iMigratables, systemService); MigrationReport importReport = iConfigurationMigrationManager.doImport(exportDir, this::print); // Verify import assertThat("The import report has errors.", importReport.hasErrors(), is(false)); assertThat("The import report has warnings.", importReport.hasWarnings(), is(false)); assertThat("Import was not successful.", importReport.wasSuccessful(), is(true)); verifyRequiredSystemFilesImported(); verifyImported(optionalFilesExported); verifyWsSecurityFilesImported(); verifyKeystoresImported(); verifyServiceWrapperImported(); }
From source file:org.structr.rest.resource.LogResource.java
private void collectFilesAndStore(final Context context, final Path dir, final int level) throws FrameworkException { if (level == 1) { logger.log(Level.INFO, "Path {0}", dir); }/*from ww w . j a v a 2 s . com*/ try (final DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) { for (final Path p : stream) { if (Files.isDirectory(p)) { collectFilesAndStore(context, p, level + 1); } else { context.update(storeLogEntry(p)); // update object count and commit context.commit(true); } Files.delete(p); } } catch (IOException ioex) { ioex.printStackTrace(); } }
From source file:org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndexFileManager.java
@Override public void deleteTransactionFiles() throws HyracksDataException { String[] files = listDirFiles(baseDir, transactionFileNameFilter); if (files.length == 0) { // Do nothing } else if (files.length > 1) { throw new HyracksDataException("Found more than one transaction"); } else {//from w w w .j a v a 2 s . c o m File dir = new File(baseDir); //create transaction filter FilenameFilter transactionFilter = createTransactionFilter(files[0], true); String[] componentsFiles = listDirFiles(baseDir, transactionFilter); for (String fileName : componentsFiles) { try { String absFileName = dir.getPath() + File.separator + fileName; Files.delete(Paths.get(absFileName)); } catch (IOException e) { throw new HyracksDataException("Failed to delete transaction files", e); } } // delete the txn lock file String absFileName = dir.getPath() + File.separator + files[0]; try { Files.delete(Paths.get(absFileName)); } catch (IOException e) { throw new HyracksDataException("Failed to delete transaction files", e); } } }
From source file:it.polimi.diceH2020.launcher.Experiment.java
void wipeResultDir() throws IOException { Path result = Paths.get(settings.getResultDir()); if (Files.exists(result)) { Files.walkFileTree(result, new SimpleFileVisitor<Path>() { @Override/* w w w . ja v a2s. c om*/ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { Files.delete(dir); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; } }); Files.deleteIfExists(result); Files.createDirectory(result); } }
From source file:com.upplication.s3fs.util.AmazonS3ClientMock.java
/** * store in the memory map/* www . j a v a2 s. c om*/ * @param bucketName bucket where persist * @param elem */ private void persist(String bucketName, S3Element elem) { Path bucket = find(bucketName); String key = elem.getS3Object().getKey().replaceAll("/", "%2F"); Path resolve = bucket.resolve(key); if (Files.exists(resolve)) try { Files.delete(resolve); } catch (IOException e1) { // ignore } try { Files.createFile(resolve); S3ObjectInputStream objectContent = elem.getS3Object().getObjectContent(); if (objectContent != null) { byte[] byteArray = IOUtils.toByteArray(objectContent); Files.write(resolve, byteArray); } } catch (IOException e) { throw new AmazonServiceException("Problem creating mock element: ", e); } }