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:de.nrw.hbz.regal.sync.ingest.DippMapping.java

private String flux(File file, String pid) throws IOException, RecognitionException {
    File outfile = File.createTempFile("lobid", "rdf");
    outfile.deleteOnExit();
    System.out.println(/*  w  w w .  ja  va2  s .c o  m*/
            Thread.currentThread().getContextClassLoader().getResource("dipp-qdc-to-lobid.flux").toString());
    File fluxFile = createFile("dipp-qdc-to-lobid.flux", "/tmp/dipp-qdc-to-lobid.flux");
    createFile("dipp-qdc-to-lobid.xml", "/tmp/dipp-qdc-to-lobid.xml");

    Flux.main(new String[] { fluxFile.getAbsolutePath(), "in=" + file.getAbsolutePath(),
            "out=" + outfile.getAbsolutePath(), "subject=" + pid });
    return FileUtils.readFileToString(outfile).trim();
}

From source file:EmbeddedFlume.EmbeddedFlume.TestFlumeEmbeddedAgentnew.java

public void run(String args[]) throws Exception {

    Map<String, String> config = new HashMap<String, String>();
    parseHostsAndPort(config);// ww  w .  j  a v a  2  s.c o  m

    File dcDir = Files.createTempDir();
    dcDir.deleteOnExit();
    config.put("source.type", "embedded");
    config.put("channel.type", "memory");
    config.put("channel.capacity", "100000");
    config.put("channel.dataDirs", dcDir.toString() + "/data");
    config.put("channel.checkpointDir", dcDir.toString() + "/checkpoint");
    agent.configure(config);
    agent.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        public void run() {
            agent.stop();
        }
    }));
}

From source file:net.sf.taverna.raven.launcher.TestPreLauncher.java

@Test
public void launchHelloWorld() throws Exception {
    System.setProperty("raven.launcher.app.name", "helloworld");
    System.setProperty("raven.launcher.app.main", "net.sf.taverna.raven.helloworld.HelloWorld");
    List<URL> urls = makeClassPath("TestPreLauncher-helloworld/");
    URLClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[0]), getClass().getClassLoader());
    Thread.currentThread().setContextClassLoader(classLoader);
    classLoader.loadClass("org.apache.log4j.Logger");

    File outFile = File.createTempFile(getClass().getCanonicalName(), "test");
    outFile.deleteOnExit();

    PreLauncher.main(new String[] { outFile.getAbsolutePath() });
    String out = FileUtils.readFileToString(outFile, "utf8");
    assertEquals("Did not match expected output", "This is the test data.\n", out);
}

From source file:$.MyMapping.java

private String flux(File file, String pid) throws URISyntaxException, IOException, RecognitionException {
        File outfile = File.createTempFile("lobid", "rdf");
        outfile.deleteOnExit();
        File fluxFile = createFile("my-xmetadissplus-to-lobid.flux", "/tmp/my-xmetadissplus-to-lobid.flux");
        createFile("my-xmetadissplus-to-lobid.xml", "/tmp/my-xmetadissplus-to-lobid.xml");

        Flux.main(new String[] { fluxFile.getAbsolutePath(), "in=" + file.getAbsolutePath(),
                "out=" + outfile.getAbsolutePath(), "subject=" + pid });
        return FileUtils.readFileToString(outfile).trim();
    }//from w w  w  .  jav a2  s .  c  o  m

From source file:annis.visualizers.component.graph.DebugVisualizer.java

@Override
public void createDotContent(VisualizerInput input, StringBuilder sb) {
    try {/*ww  w. j  a v  a2  s .  c o m*/
        File tmpFile = File.createTempFile("annisdebugvis", ".dot");
        tmpFile.deleteOnExit();
        Salt2DOT converter = new Salt2DOT();
        converter.salt2Dot(input.getDocument().getSDocumentGraph(),
                URI.createFileURI(tmpFile.getCanonicalPath()));

        sb.append(FileUtils.readFileToString(tmpFile));

        if (!tmpFile.delete()) {
            log.warn("Cannot delete " + tmpFile.getAbsolutePath());
        }
    } catch (IOException ex) {
        log.error("could not create temporary file for dot", ex);
    }
}

From source file:de.nrw.hbz.regal.sync.ingest.OpusMapping.java

private String flux(File file, String pid) throws IOException, RecognitionException {
    File outfile = File.createTempFile("lobid", "rdf");
    outfile.deleteOnExit();
    File fluxFile = createFile("opus-xmetadissplus-to-lobid.flux", "/tmp/opus-xmetadissplus-to-lobid.flux");
    createFile("opus-xmetadissplus-to-lobid.xml", "/tmp/opus-xmetadissplus-to-lobid.xml");

    Flux.main(new String[] { fluxFile.getAbsolutePath(), "in=" + file.getAbsolutePath(),
            "out=" + outfile.getAbsolutePath(), "subject=" + pid });
    return FileUtils.readFileToString(outfile).trim();
}

From source file:org.zht.framework.web.controller.AjaxUploadController.java

@RequestMapping(value = "ajaxUpload/delete", method = RequestMethod.POST)
@ResponseBody/*from  w ww.  j  av  a 2  s.c om*/
public String ajaxUploadDelete(HttpServletRequest request, @RequestParam(value = "filename") String filename)
        throws Exception {

    if (StringUtils.isEmpty(filename) || filename.contains("\\.\\.")) {
        return "";
    }
    filename = URLDecoder.decode(filename, "UTF-8");

    String filePath = FileUploadUtils.extractUploadDir(request) + "/" + filename;

    File file = new File(filePath);
    file.deleteOnExit();

    return "";
}

From source file:de.tudarmstadt.ukp.dkpro.core.io.rtf.RTFReaderTest.java

/**
 * Simple test for reader / CASDumpWriter output.
 *
 * @throws UIMAException/*ww  w  . j a  v  a2 s .c om*/
 * @throws IOException
 */
@Test
public void test() throws UIMAException, IOException {
    File testFile = new File("src/test/resources/testfile.rtf");
    File output = new File("target/output.dump");
    output.deleteOnExit();
    File testDump = new File("src/test/resources/testfile.dump");

    CollectionReaderDescription reader = createReaderDescription(RTFReader.class,
            RTFReader.PARAM_SOURCE_LOCATION, testFile, RTFReader.PARAM_LANGUAGE, "en");

    AnalysisEngineDescription writer = createEngineDescription(CasDumpWriter.class,
            CasDumpWriter.PARAM_OUTPUT_FILE, output);

    SimplePipeline.runPipeline(reader, writer);
    assertEquals(FileUtils.readFileToString(testDump), FileUtils.readFileToString(output));
}

From source file:net.oletalk.hellospringboot.controller.HelloController.java

@PostMapping("/upload")
public String handleFileUpload(@RequestParam("file") MultipartFile file, RedirectAttributes attributes) {
    // multipart file upload is slightly different

    String originalName = file.getOriginalFilename();
    // TODO any way of getting files uploaded without transferring to a temp file?
    //  It seems to want to know the complete path but MultipartFile doesn't give us that.
    String returnMsg;//from   w w  w  .  ja  v  a2s.  c  o m
    try {
        LOG.info("Creating temp file for upload");
        File tmpFile = File.createTempFile("s3upload", null);
        tmpFile.deleteOnExit();
        file.transferTo(tmpFile);
        returnMsg = s3service.uploadDocument("test/" + originalName, tmpFile);
        attributes.addFlashAttribute("message", returnMsg);
    } catch (IOException ioe) {
        LOG.error("Error creating temp file for upload:" + ioe.toString());
        attributes.addFlashAttribute("message", "Problem preparing upload to S3");
    }
    return "redirect:/hello/doc/";
}

From source file:com.playonlinux.core.webservice.HTTPDownloaderTest.java

@Test
public void testGet_DownloadFile_FileIsDownloaded() throws Exception {
    mockServer.when(request().withMethod("GET").withPath("/test.txt")).respond(
            response().withStatusCode(200).withHeaders(new Header("Content-Type", "application/config"))
                    .withBody("Content file to download"));

    File temporaryFile = File.createTempFile("test", "txt");
    temporaryFile.deleteOnExit();
    new HTTPDownloader(mockServerURL).get(temporaryFile);

    String fileContent = IOUtils.toString(new FileReader(temporaryFile));

    assertEquals("Content file to download", fileContent);
}