Example usage for java.io File deleteOnExit

List of usage examples for java.io File deleteOnExit

Introduction

In this page you can find the example usage for java.io File deleteOnExit.

Prototype

public void deleteOnExit() 

Source Link

Document

Requests that the file or directory denoted by this abstract pathname be deleted when the virtual machine terminates.

Usage

From source file:com.googlecode.fannj.FannTrainerTest.java

@Test
public void testTrainingQuickprop() throws IOException {

    File temp = File.createTempFile("fannj_", ".tmp");
    temp.deleteOnExit();
    IOUtils.copy(this.getClass().getResourceAsStream("xor.data"), new FileOutputStream(temp));

    List<Layer> layers = new ArrayList<Layer>();
    layers.add(Layer.create(2));/* w w w  .j  a v  a2 s. c  o m*/
    layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
    layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));

    Fann fann = new Fann(layers);
    Trainer trainer = new Trainer(fann);

    trainer.setTrainingAlgorithm(TrainingAlgorithm.FANN_TRAIN_QUICKPROP);

    float desiredError = .001f;
    float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
    assertTrue("" + mse, mse <= desiredError);
}

From source file:com.projecteight.SimpleArtifactConsumerTest.java

private void setUpMockRepository() throws RepositoryAdminException {
    File repoDir = new File("target/test-consumer-repo");
    repoDir.mkdirs();//from w  ww. j a  va  2  s.  c  o m
    repoDir.deleteOnExit();

    testRepository = new ManagedRepository();
    testRepository.setName("Test-Consumer-Repository");
    testRepository.setId("test-consumer-repository");
    testRepository.setLocation(repoDir.getAbsolutePath());

    when(managedRepositoryAdmin.getManagedRepository(testRepository.getId())).thenReturn(testRepository);
}

From source file:com.googlecode.fannj.FannTrainerTest.java

@Test
public void testTrainingBackprop() throws IOException {

    File temp = File.createTempFile("fannj_", ".tmp");
    temp.deleteOnExit();
    IOUtils.copy(this.getClass().getResourceAsStream("xor.data"), new FileOutputStream(temp));

    List<Layer> layers = new ArrayList<Layer>();
    layers.add(Layer.create(2));//ww w.ja  v a 2 s.c  om
    layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
    layers.add(Layer.create(2, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
    layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));

    Fann fann = new Fann(layers);
    Trainer trainer = new Trainer(fann);

    trainer.setTrainingAlgorithm(TrainingAlgorithm.FANN_TRAIN_INCREMENTAL);

    float desiredError = .001f;
    float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
    assertTrue("" + mse, mse <= desiredError);
}

From source file:com.netscape.certsrv.client.PKIRESTProvider.java

@Override
public StreamingOutput readFrom(Class<StreamingOutput> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
        throws IOException, WebApplicationException {

    final File file = File.createTempFile("PKIRESTProvider-", ".tmp");
    file.deleteOnExit();

    FileOutputStream out = new FileOutputStream(file);
    IOUtils.copy(entityStream, out);//from w ww  .  j  a  va 2  s . c  o m

    return new StreamingOutput() {

        @Override
        public void write(OutputStream out) throws IOException, WebApplicationException {
            FileInputStream in = new FileInputStream(file);
            IOUtils.copy(in, out);
        }

        public void finalize() {
            file.delete();
        }
    };
}

From source file:com.apifest.doclet.integration.tests.DocletModeTest.java

private void findFile(String directory, String name, final String extension) {
    File dir = new File(directory);

    File[] files = dir.listFiles(new FilenameFilter() {
        public boolean accept(File directory, String fileName) {
            if (fileName.startsWith("all") && fileName.endsWith(extension)) {
                return true;
            }//from  w w w . j  a  va  2 s . c om
            return false;
        }
    });
    for (File f : files) {
        Assert.assertEquals(name, f.getName());
        f.deleteOnExit();
    }
}

From source file:de.tudarmstadt.ukp.dkpro.core.mallet.topicmodel.io.MalletTopicsProportionsSortedWriterTest.java

@Test
public void test() throws UIMAException, IOException {
    File targetFile = new File("target/topics.txt");
    targetFile.deleteOnExit();

    int expectedLines = 2;
    int nTopicsOutput = 3;
    String expectedLine0Regex = "dummy1.txt(\t[0-9]+:0\\.[0-9]{4}){" + nTopicsOutput + "}";
    String expectedLine1Regex = "dummy2.txt(\t[0-9]+:0\\.[0-9]{4}){" + nTopicsOutput + "}";

    CollectionReaderDescription reader = createReaderDescription(TextReader.class,
            TextReader.PARAM_SOURCE_LOCATION, CAS_DIR, TextReader.PARAM_PATTERNS, CAS_FILE_PATTERN,
            TextReader.PARAM_LANGUAGE, LANGUAGE);
    AnalysisEngineDescription segmenter = createEngineDescription(BreakIteratorSegmenter.class);

    AnalysisEngineDescription inferencer = createEngineDescription(MalletTopicModelInferencer.class,
            MalletTopicModelInferencer.PARAM_MODEL_LOCATION, MODEL_FILE,
            MalletTopicModelInferencer.PARAM_USE_LEMMA, USE_LEMMAS);

    AnalysisEngineDescription writer = createEngineDescription(MalletTopicsProportionsSortedWriter.class,
            MalletTopicsProportionsSortedWriter.PARAM_TARGET_LOCATION, targetFile,
            MalletTopicsProportionsSortedWriter.PARAM_N_TOPICS, nTopicsOutput);

    SimplePipeline.runPipeline(reader, segmenter, inferencer, writer);
    List<String> lines = FileUtils.readLines(targetFile);
    assertTrue(lines.get(0).matches(expectedLine0Regex));
    assertTrue(lines.get(1).matches(expectedLine1Regex));
    assertEquals(expectedLines, lines.size());

    /* assert first field */
    lines.stream().map(line -> line.split("\t")).forEach(fields -> assertTrue(fields[0].startsWith("dummy")));
}

From source file:com.seleniumtests.GenericTest.java

protected File createFileFromResource(String resource) throws IOException {
    File tempFile = File.createTempFile("img", null);
    tempFile.deleteOnExit();
    FileUtils.copyInputStreamToFile(//from   ww w . j av a2  s. co  m
            Thread.currentThread().getContextClassLoader().getResourceAsStream(resource), tempFile);

    return tempFile;
}

From source file:gov.nih.nci.caintegrator.application.analysis.ClassificationsToClsConverterTest.java

@Test
public void testWriteAsGct() throws IOException {
    SampleClassificationParameterValue parameterValue = createTestParameterValue();
    String testFilePath = System.getProperty("java.io.tmpdir") + File.separator + "clsTest.cls";
    File clsFile = new File(testFilePath);
    ClassificationsToClsConverter.writeAsCls(parameterValue, testFilePath);
    clsFile.deleteOnExit();
    checkFile(clsFile);/*  w w w. j av a 2s .co  m*/
}

From source file:com.healthmarketscience.rmiio.RemoteStreamServerTest.java

private static File getTempFile(String prefix, List<List<File>> tempFiles, boolean doPartial, boolean doAbort,
        boolean doSkip) throws IOException {
    File tempFile = File.createTempFile(prefix, ".out");
    if (_deleteOnExit) {
        tempFile.deleteOnExit();
    }/* ww w .j a v  a2 s.  co m*/
    if (tempFiles != null) {
        if ((!doPartial) && (!doAbort) && (!doSkip)) {
            tempFiles.get(0).add(tempFile);
        } else {
            tempFiles.get(1).add(tempFile);
        }
    }
    return tempFile;
}

From source file:eu.scape_project.up2ti.identifiers.DroidIdentification.java

/**
 * Constructor which initialises a given specified signature file
 *
 * @param sigFilePath/*from w w  w  .ja v  a  2s  .  co  m*/
 */
public DroidIdentification(Resource resource) throws IOException {
    try {
        InputStream is = resource.getInputStream();
        File tmpFile1 = File.createTempFile("DroidSignatureFile", ".xml");
        FileUtils.copyInputStreamToFile(is, tmpFile1);
        File tmpFile = tmpFile1;
        tmpFile.deleteOnExit();
        bsi = new BinarySignatureIdentifier();
        bsi.setSignatureFile(tmpFile.getAbsolutePath());
        bsi.init();
    } catch (SignatureParseException ex) {
        LOG.error("Signature parse error", ex);
    }
}