List of usage examples for java.nio.file Files deleteIfExists
public static boolean deleteIfExists(Path path) throws IOException
From source file:com.pentaho.ctools.cde.reference.ExportPopupComponent.java
/** * The function will delete the export file. *///from w w w.j av a 2 s . c o m public void DeleteFile() { try { Files.deleteIfExists(Paths.get(this.exportFilePath)); Files.deleteIfExists(Paths.get(this.exportFilePath2)); Files.deleteIfExists(Paths.get(this.exportFilePath3)); Files.deleteIfExists(Paths.get(this.exportFilePath4)); Files.deleteIfExists(Paths.get(this.exportFilePath5)); Files.deleteIfExists(Paths.get(this.exportFilePath6)); } catch (Exception e) { this.log.error(e.getMessage()); } }
From source file:com.arpnetworking.metrics.impl.TsdLogSinkTest.java
@Test public void testEmptySerialization() throws IOException, InterruptedException { final File actualFile = new File("./target/TsdLogSinkTest/testEmptySerialization-Query.log"); Files.deleteIfExists(actualFile.toPath()); final Sink sink = new TsdLogSink.Builder().setDirectory(createDirectory("./target/TsdLogSinkTest")) .setName("testEmptySerialization-Query").setImmediateFlush(Boolean.TRUE).build(); sink.record(new TsdEvent(ANNOTATIONS, TEST_EMPTY_SERIALIZATION_TIMERS, TEST_EMPTY_SERIALIZATION_COUNTERS, TEST_EMPTY_SERIALIZATION_GAUGES)); // TODO(vkoskela): Add protected option to disable async [MAI-181]. Thread.sleep(100);/*from www . j a v a 2 s.com*/ final String actualOriginalJson = fileToString(actualFile); assertMatchesJsonSchema(actualOriginalJson); final String actualComparableJson = actualOriginalJson .replaceAll("\"_host\":\"[^\"]*\"", "\"_host\":\"<HOST>\"") .replaceAll("\"_id\":\"[^\"]*\"", "\"_id\":\"<ID>\""); final JsonNode actual = OBJECT_MAPPER.readTree(actualComparableJson); final JsonNode expected = OBJECT_MAPPER.readTree(EXPECTED_EMPTY_METRICS_JSON); Assert.assertEquals("expectedJson=" + OBJECT_MAPPER.writeValueAsString(expected) + " vs actualJson=" + OBJECT_MAPPER.writeValueAsString(actual), expected, actual); }
From source file:eu.europa.ec.markt.dss.signature.StreamDocumentTest.java
@Test public void createDocumentFromStreamedDataFile() throws Exception { try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(new byte[] { 0x041 })) { DataFile dataFile = new DataFile(byteArrayInputStream, "A.txt", "text/plain"); StreamDocument streamDocument = new StreamDocument(dataFile.getStream(), dataFile.getName(), MimeType.fromMimeTypeString(dataFile.getMediaType())); streamDocument.save("createDocumentFromStreamedDataFile.txt"); }//w w w. j a v a 2 s .c o m try (FileInputStream fileInputStream = new FileInputStream("createDocumentFromStreamedDataFile.txt")) { assertArrayEquals(new byte[] { 0x041 }, IOUtils.toByteArray(fileInputStream)); } Files.deleteIfExists(Paths.get("createDocumentFromStreamedDataFile.txt")); }
From source file:org.pentaho.hadoop.shim.HadoopRunningOnClusterTest.java
private void disablePmrFile() throws URISyntaxException, IOException { Files.deleteIfExists(Paths.get(urlTestResources.toURI())); }
From source file:org.phoenicis.tools.files.FileUtilities.java
/** * deletes a file only if it is inside Phoenicis root * @param fileToDelete fileOrDirectoryToDelete *//*from ww w . j av a 2 s. c o m*/ public void remove(File fileToDelete) throws IOException { assertInDirectory(fileToDelete); if (fileToDelete.isDirectory()) { FileUtils.deleteDirectory(fileToDelete); } else { Files.deleteIfExists(fileToDelete.toPath()); } }
From source file:com.arpnetworking.metrics.impl.StenoLogSinkTest.java
@Test public void testEmptySerialization() throws IOException, InterruptedException { final File actualFile = new File("./target/StenoLogSinkTest/testEmptySerialization-Query.log"); Files.deleteIfExists(actualFile.toPath()); final Sink sink = new StenoLogSink.Builder().setDirectory(createDirectory("./target/StenoLogSinkTest")) .setName("testEmptySerialization-Query").setImmediateFlush(Boolean.TRUE).build(); sink.record(new TsdEvent(ANNOTATIONS, TEST_EMPTY_SERIALIZATION_TIMERS, TEST_EMPTY_SERIALIZATION_COUNTERS, TEST_EMPTY_SERIALIZATION_GAUGES)); // TODO(vkoskela): Add protected option to disable async [MAI-181]. Thread.sleep(100);/*from w w w . j a va 2 s . c om*/ final String actualOriginalJson = fileToString(actualFile); assertMatchesJsonSchema(actualOriginalJson); final String actualComparableJson = actualOriginalJson .replaceAll("\"time\":\"[^\"]*\"", "\"time\":\"<TIME>\"") .replaceAll("\"threadId\":\"[^\"]*\"", "\"threadId\":\"<THREADID>\"") .replaceAll("\"processId\":\"[^\"]*\"", "\"processId\":\"<PROCESSID>\"") .replaceAll("\"host\":\"[^\"]*\"", "\"host\":\"<HOST>\"") .replaceAll("\"id\":\"[^\"]*\"", "\"id\":\"<ID>\""); final JsonNode actual = OBJECT_MAPPER.readTree(actualComparableJson); final JsonNode expected = OBJECT_MAPPER.readTree(EXPECTED_EMPTY_METRICS_JSON); Assert.assertEquals("expectedJson=" + OBJECT_MAPPER.writeValueAsString(expected) + " vs actualJson=" + OBJECT_MAPPER.writeValueAsString(actual), expected, actual); }
From source file:sonicScream.models.ScriptTest.java
@After public void tearDown() throws IOException { Files.deleteIfExists(Paths.get("testProfile.xml")); Files.deleteIfExists(Paths.get("testProfiles.xml")); }
From source file:org.digidoc4j.main.DigiDoc4JTest.java
@Test public void createsContainerWithTypeSettingDDoc() throws Exception { String fileName = "test1.bdoc"; Files.deleteIfExists(Paths.get(fileName)); String[] params = new String[] { "-in", fileName, "-type", "DDOC", "-add", "testFiles/test.txt", "text/plain", "-pkcs12", "testFiles/signout.p12", "test" }; callMainWithoutSystemExit(params);/*from w ww.j a v a2 s. c o m*/ Container container = ContainerOpener.open(fileName); assertEquals("DDOC", container.getType()); }
From source file:co.cask.cdap.security.store.FileSecureStoreTest.java
@After public void tearDown() throws IOException { Files.deleteIfExists(Paths.get(STORE_PATH, "securestore")); }