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

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

Introduction

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

Prototype

public static void forceDeleteOnExit(File file) throws IOException 

Source Link

Document

Schedules a file to be deleted when JVM exits.

Usage

From source file:com.joyent.manta.client.multipart.TestMultipartManager.java

public TestMultipartManager() {
    try {//from w w w  .  ja va 2s.c  om
        this.partsDirectory = Files.createTempDirectory("multipart").toFile();
        FileUtils.forceDeleteOnExit(partsDirectory);
        this.destinationDirectory = Files.createTempDirectory("multipart-final").toFile();
        FileUtils.forceDeleteOnExit(destinationDirectory);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:blog.detect.DetectSingleFaceFromFileExample.java

public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),
            System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(FILE_LOCATION_OF_US_PRESIDENT), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    imageOverlayBuilder.outlineFaceOnImage(faceScenarios.findSingleFace(imageFile), RectangleType.FULL)
            .launchViewer();//from www  . ja v  a  2s. co  m
}

From source file:com.joyent.manta.config.ConfigContextTest.java

public void canValidateContextWithKeyPaths() throws IOException {
    File mantaAuthPrivateKey = File.createTempFile("manta-key", "");
    FileUtils.forceDeleteOnExit(mantaAuthPrivateKey);
    FileUtils.write(mantaAuthPrivateKey, UnitTestConstants.PRIVATE_KEY, StandardCharsets.US_ASCII);

    File encryptionPrivateKey = File.createTempFile("encryption-key", "");
    FileUtils.forceDeleteOnExit(encryptionPrivateKey);
    FileUtils.writeByteArrayToFile(encryptionPrivateKey, keyBytes);

    StandardConfigContext config = new StandardConfigContext();
    config.setMantaURL(DefaultsConfigContext.DEFAULT_MANTA_URL);
    config.setMantaUser("username");
    config.setMantaKeyId(UnitTestConstants.FINGERPRINT);
    config.setMantaKeyPath(mantaAuthPrivateKey.getAbsolutePath());
    config.setClientEncryptionEnabled(true);
    config.setEncryptionKeyId("test-key-1");
    config.setEncryptionAuthenticationMode(EncryptionAuthenticationMode.DEFAULT_MODE);
    config.setPermitUnencryptedDownloads(false);
    config.setEncryptionPrivateKeyPath(encryptionPrivateKey.getAbsolutePath());
    config.setEncryptionAlgorithm(AesGcmCipherDetails.INSTANCE_128_BIT.getCipherId());

    ConfigContext.validate(config);/*from w  w w  .  jav  a 2s  . co m*/
}

From source file:de.flapdoodle.embedmongo.Files.java

public static boolean forceDelete(File fileOrDir) {
    boolean ret = false;

    try {/*  w ww  . j a  v  a 2 s . co  m*/
        if (fileOrDir != null) {
            FileUtils.forceDelete(fileOrDir);
            _logger.info("Could delete " + fileOrDir);
            ret = true;
        }
    } catch (IOException e) {
        _logger.warning("Could not delete " + fileOrDir + ". Will try to delete it again when program exits.");
        try {
            FileUtils.forceDeleteOnExit(fileOrDir);
            ret = true;
        } catch (IOException ioe) {
            _logger.severe("Could not delete " + fileOrDir);
            throw new IllegalStateException("Could not delete " + fileOrDir);
        }
    }

    return ret;
}

From source file:com.joyent.manta.client.AuthAwareConfigContextTest.java

public void canMonitorRelevantFieldsInConfig() throws IOException {
    final AuthAwareConfigContext authConfig = new AuthAwareConfigContext(config);
    final KeyPair currentKeyPair = authConfig.getKeyPair();
    Assert.assertNotNull(currentKeyPair);

    // key file (move key content to a file)
    final File keyFile = File.createTempFile("private-key", "");
    FileUtils.forceDeleteOnExit(keyFile);
    FileUtils.writeStringToFile(keyFile, authConfig.getPrivateKeyContent(), StandardCharsets.UTF_8);
    authConfig.setPrivateKeyContent(null);
    authConfig.setMantaKeyPath(keyFile.getAbsolutePath());
    authConfig.reload();/*from   w  ww. j  av a2  s.  c o  m*/
    differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair());

    // key id
    authConfig.setMantaKeyId("MD5:" + KeyFingerprinter.md5Fingerprint(authConfig.getKeyPair()));
    authConfig.reload();
    differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair());

    // disable native signatures
    final ThreadLocalSigner currentSigner = authConfig.getSigner();
    authConfig.setDisableNativeSignatures(true);
    authConfig.reload();
    Assert.assertNotSame(currentSigner, authConfig.getSigner());

    // disable auth entirely
    authConfig.setNoAuth(true);
    authConfig.reload();
    Assert.assertNull(authConfig.getKeyPair());
}

From source file:com.vmware.photon.controller.model.helpers.BaseModelTest.java

@AfterClass
public void tearDownClass() throws Throwable {
    if (host != null) {
        host.stop();/*w w w  .  j  a v a  2 s.c om*/
        host = null;
    }
    File sandbox = new File(sandboxDirectory.toUri());
    if (sandbox.exists()) {
        try {
            FileUtils.forceDelete(sandbox);
        } catch (FileNotFoundException | IllegalArgumentException ex) {
            logger.debug("Sandbox file was not found");
        } catch (IOException ex) {
            FileUtils.forceDeleteOnExit(sandbox);
        }
    }
}

From source file:com.opengamma.transport.TaxonomyGatheringFudgeMessageSenderTest.java

@Test(timeOut = 10000)
public void taxonomyGathering() throws IOException, InterruptedException {
    File tmpFile = File.createTempFile("TaxonomyGatheringFudgeMessageSenderTest_taxonomyGathering",
            ".properties");
    FileUtils.forceDelete(tmpFile);//from  w  ww  .  ja v a 2  s .c o m
    FileUtils.forceDeleteOnExit(tmpFile);

    FudgeContext context = new FudgeContext();
    CollectingFudgeMessageReceiver collectingReceiver = new CollectingFudgeMessageReceiver();
    ByteArrayFudgeMessageReceiver fudgeReceiver = new ByteArrayFudgeMessageReceiver(collectingReceiver);
    DirectInvocationByteArrayMessageSender byteArraySender = new DirectInvocationByteArrayMessageSender(
            fudgeReceiver);
    ByteArrayFudgeMessageSender fudgeSender = new ByteArrayFudgeMessageSender(byteArraySender, context);
    TaxonomyGatheringFudgeMessageSender gatheringSender = new TaxonomyGatheringFudgeMessageSender(fudgeSender,
            tmpFile.getAbsolutePath(), context, 1000L);

    MutableFudgeMsg msg1 = context.newMessage();
    msg1.add("name1", 1);
    msg1.add("name2", 1);
    msg1.add("name3", 1);
    msg1.add("name1", 1);
    MutableFudgeMsg msg2 = context.newMessage();
    msg1.add("name4", msg2);
    msg2.add(14, 1);
    msg2.add("name5", "foo");

    gatheringSender.send(msg1);

    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name1"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name2"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name3"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name4"));
    assertTrue(gatheringSender.getCurrentTaxonomy().containsKey("name5"));
    assertEquals(5, gatheringSender.getCurrentTaxonomy().size());

    Properties props = new Properties();
    gatheringSender.waitForNextWrite();
    InputStream is = new FileInputStream(tmpFile);
    props.load(new BufferedInputStream(is));
    is.close();

    for (Map.Entry<Object, Object> propEntry : props.entrySet()) {
        Integer ordinal = gatheringSender.getCurrentTaxonomy().get(propEntry.getValue());
        assertEquals(ordinal.intValue(), Integer.parseInt((String) propEntry.getKey()));
    }
    assertEquals(5, props.size());
}

From source file:blog.attributes.DetectGenderAgeFromFileExample.java

public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),
            System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(IMAGE_LOCATION), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    CognitiveJColourPalette colourPalette = CognitiveJColourPalette.STRAWBERRY;
    List<Face> faces = faceScenarios.findFaces(imageFile);
    faces.forEach(face -> imageOverlayBuilder.outlineFaceOnImage(face, RectangleType.FULL,
            ImageOverlayBuilder.DEFAULT_BORDER_WEIGHT, colourPalette)
            .writeAge(face, colourPalette, RectangleTextPosition.TOP_OF));
    imageOverlayBuilder.launchViewer();//from  w w  w. j ava2  s. co m

}

From source file:com.joyent.manta.client.crypto.SecretKeyUtilsTest.java

public void canLoadKeyFromURIPath() throws IOException {
    File file = File.createTempFile("ciphertext-", ".data");
    FileUtils.forceDeleteOnExit(file);
    FileUtils.writeByteArrayToFile(file, keyBytes);
    URI uri = file.toURI();/* ww  w  .j a  v  a 2  s  . c  o  m*/

    SecretKey expected = SecretKeyUtils.loadKey(keyBytes, AesGcmCipherDetails.INSTANCE_128_BIT);
    SecretKey actual = SecretKeyUtils.loadKeyFromPath(Paths.get(uri), AesGcmCipherDetails.INSTANCE_128_BIT);

    Assert.assertEquals(actual.getAlgorithm(), expected.getAlgorithm());
    Assert.assertTrue(Arrays.equals(expected.getEncoded(), actual.getEncoded()),
            "Secret key loaded from URI doesn't match");
}

From source file:gobblin.util.TemplateTest.java

@BeforeClass
public void setUp() throws IOException, URISyntaxException {

    // Creating userCustomized stuff
    this.jobConfigDir = Files
            .createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName()))
            .toFile();/*from  w ww .  jav  a2s  .  co  m*/
    FileUtils.forceDeleteOnExit(this.jobConfigDir);

    //User specified file content:
    this.userProp = new Properties();
    userProp.setProperty("a", "1");
    userProp.setProperty("templated0", "2");
    userProp.setProperty("required0", "r0");
    userProp.setProperty("required1", "r1");
    userProp.setProperty("required2", "r2");
    userProp.setProperty("job.template", "templates/test.template");

    // User specified file's name : /[jobConfigDirName]/user.attr
    userProp.store(new FileWriter(new File(this.jobConfigDir, "user.attr")), "");
}