Example usage for java.nio.file Files deleteIfExists

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

Introduction

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

Prototype

public static boolean deleteIfExists(Path path) throws IOException 

Source Link

Document

Deletes a file if it exists.

Usage

From source file:it.greenvulcano.configuration.BaseConfigurationManager.java

@Override
public void delete(String name) throws IOException, FileNotFoundException {
    Path configurationPath = getConfigurationPath(name);
    if (!Files.deleteIfExists(configurationPath)) {
        throw new FileNotFoundException(configurationPath.toString());
    }//from  ww w.j a va 2 s .  c o m
}

From source file:org.ballerinalang.stdlib.system.FileSystemTest.java

@Test(description = "Test for changing file path to already existing file path")
public void testFileRenameWithInvalidPath() throws IOException {
    try {//from   w  w  w  .  j  av a  2  s. c o  m
        Files.copy(srcFilePath, tempSourcePath, StandardCopyOption.REPLACE_EXISTING,
                StandardCopyOption.COPY_ATTRIBUTES);
        Files.copy(srcFilePath, tempDestPath, StandardCopyOption.REPLACE_EXISTING,
                StandardCopyOption.COPY_ATTRIBUTES);

        BValue[] args = { new BString(tempSourcePath.toString()), new BString(tempDestPath.toString()) };
        BValue[] returns = BRunUtil.invoke(compileResult, "testRename", args);
        assertTrue(returns[0] instanceof BError);
        BError error = (BError) returns[0];
        assertEquals(error.getReason(), "{ballerina/system}OPERATION_FAILED");
        log.info("Ballerina error: " + error.getDetails().stringValue());
    } finally {
        Files.deleteIfExists(tempSourcePath);
        Files.deleteIfExists(tempDestPath);
    }
}

From source file:org.apache.asterix.replication.storage.ReplicaResourcesManager.java

public void markLSMComponentReplicaAsValid(LSMComponentProperties lsmComponentProperties) throws IOException {
    //remove mask to mark component as valid
    String maskPath = lsmComponentProperties.getMaskPath(this);
    Path path = Paths.get(maskPath);
    Files.deleteIfExists(path);

    //add component LSN to the index LSNs map
    Map<Long, Long> lsnMap = getReplicaIndexLSNMap(lsmComponentProperties.getReplicaComponentPath(this));
    lsnMap.put(lsmComponentProperties.getOriginalLSN(), lsmComponentProperties.getReplicaLSN());

    //update map on disk
    updateReplicaIndexLSNMap(lsmComponentProperties.getReplicaComponentPath(this), lsnMap);
}

From source file:com.spectralogic.ds3client.helpers.FileObjectPutter_Test.java

private void getFileWithPutter(final Path dir, final Path file) throws IOException {
    try {/*  w  w w  . j  a v  a 2s . c  om*/
        final FileObjectPutter putter = new FileObjectPutter(dir);
        try (final SeekableByteChannel newChannel = putter.buildChannel(file.getFileName().toString())) {
            assertThat(newChannel, is(notNullValue()));
            final ByteBuffer buff = ByteBuffer.allocate(testData.length);
            assertThat(newChannel.read(buff), is(testData.length));
            assertThat(new String(buff.array(), Charset.forName("UTF-8")), is(testString));
        }
    } finally {
        Files.deleteIfExists(file);
    }
}

From source file:org.digidoc4j.main.DigiDoc4JTest.java

@Test
public void createsContainerWithSignatureProfileIsTSForBDoc() throws Exception {
    String fileName = "test1.bdoc";
    Files.deleteIfExists(Paths.get(fileName));

    String[] params = new String[] { "-in", fileName, "-type", "BDOC", "-add", "testFiles/test.txt",
            "text/plain", "-pkcs12", "testFiles/signout.p12", "test", "-profile", "LT" };

    System.setProperty("digidoc4j.mode", "TEST");
    callMainWithoutSystemExit(params);// ww  w. jav a 2 s .  com

    Container container = ContainerOpener.open(fileName);
    assertEquals(SignatureProfile.LT, container.getSignature(0).getProfile());
    System.clearProperty("digidoc4j.mode");
}

From source file:org.ballerinalang.test.auth.ConfigAuthProviderTest.java

@AfterClass
public void tearDown() throws IOException {
    Files.deleteIfExists(secretCopyPath);
}

From source file:sadl.detectors.AnomalyDetector.java

public boolean[] areAnomalies(TimedInput testSequences) {
    if (Settings.isDebug()) {
        final Path testLabelFile = Paths.get("testLabels.csv");
        try {/*from   www  . j a va2 s.c om*/
            Files.deleteIfExists(testLabelFile);
            Files.createFile(testLabelFile);
        } catch (final IOException e1) {
            logger.error("Unexpected exception occured", e1);
        }
        try (BufferedWriter bw = Files.newBufferedWriter(testLabelFile, StandardCharsets.UTF_8)) {
            for (final TimedWord s : testSequences) {
                bw.append(s.getLabel().toString());
                bw.append('\n');
            }
        } catch (final IOException e) {
            logger.error("Unexpected exception occured", e);
        }
    }
    final boolean[] result = new boolean[testSequences.size()];

    // parallelism does not destroy determinism
    final IntConsumer f = (i -> {
        final TimedWord s = testSequences.get(i);
        result[i] = isAnomaly(s);
    });
    if (Settings.isParallel()) {
        IntStream.range(0, testSequences.size()).parallel().forEach(f);
    } else {
        IntStream.range(0, testSequences.size()).forEach(f);
    }
    return result;
}

From source file:ch.bender.evacuate.EvacuateMainTest.java

/**
 * This method is executed just after each test method
 * /*w  ww .j a  va 2 s.  c om*/
 * @throws Throwable
 *         On any problem
 */
@After
public final void tearDown() throws Throwable {
    myLog.debug("entering...");

    try {
        if (Files.exists(Testconstants.ROOT_DIR)) {
            Helper.deleteDirRecursive(Testconstants.ROOT_DIR);
        }

        Files.deleteIfExists(myExcludeFile);

        myLog.debug("leaving...");
    } catch (Throwable t) {
        myLog.error("Throwable caught in tearDown()", t);
        throw t;
    }
}

From source file:com.spotify.scio.util.RemoteFileUtil.java

/**
 * Delete a single downloaded local file.
 *//*from  www. j  av a2  s  .co  m*/
public void delete(URI src) {
    Path dst = paths.remove(src);
    try {
        Files.deleteIfExists(dst);
    } catch (IOException e) {
        String msg = String.format("Failed to delete %s -> %s", src, dst);
        LOG.error(msg, e);
    }
}

From source file:org.wso2.carbon.event.simulator.core.internal.generator.csv.util.FileUploaderTest.java

private void deleteFile(String fileName) {
    try {//from  w ww .j a v a2  s  .co m
        Files.deleteIfExists(Paths.get(Paths.get(testDir.toString(), "tempCSVFolder", fileName).toString()));
    } catch (IOException e) {
        Assert.assertTrue(false);
    }
}