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:net.sf.jooreports.openoffice.converter.AbstractConverterTest.java

protected File createTempFile(String extension) throws IOException {
    File tempFile = File.createTempFile("document", "." + extension);
    tempFile.deleteOnExit();
    return tempFile;
}

From source file:org.openmrs.module.moduledistro.web.controller.ModuleDistroManagementController.java

@RequestMapping(value = "/module/moduledistro/manage-upload", method = RequestMethod.POST)
public void handleUpload(@RequestParam("distributionZip") MultipartFile uploaded, HttpServletRequest request,
        Model model) {/*from ww  w .  ja va 2 s .c om*/
    // write this to a known file on disk, so we can use ZipFile, since ZipInputStream is buggy
    File file = null;
    try {
        file = File.createTempFile("distribution", ".zip");
        file.deleteOnExit();
        FileUtils.copyInputStreamToFile(uploaded.getInputStream(), file);
    } catch (Exception ex) {
        throw new RuntimeException("Error getting uploaded data", ex);
    }

    List<String> log = Context.getService(ModuleDistroService.class).uploadDistro(file,
            request.getSession().getServletContext());
    model.addAttribute("log", log);
}

From source file:org.sventon.web.ctrl.template.ExportControllerTest.java

@Test
public void testExport() throws Exception {
    final File tempFile = File.createTempFile("sventon-", "-test");
    tempFile.deleteOnExit();

    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final UserRepositoryContext context = new UserRepositoryContext();
    final MultipleEntriesCommand command = new MultipleEntriesCommand();
    final PathRevision[] entriesToExport = new PathRevision[] {
            new PathRevision("/trunk/file1", Revision.create(100)),
            new PathRevision("/tags/test/file2", Revision.create(101)) };
    command.setName(new RepositoryName("test"));
    command.setEntries(entriesToExport);

    assertFalse(context.getIsWaitingForExport());
    assertNull(context.getExportUuid());

    final ExportController ctrl = new ExportController(new ExportExecutor() {
        public UUID submit(MultipleEntriesCommand command, SVNConnection connection, long pegRevision) {
            return UUID.fromString(UUID_STRING);
        }//from w ww . j  av a2 s. c om

        public void downloadByUUID(UUID uuid, HttpServletRequest request, HttpServletResponse response)
                throws IOException {
        }

        public void delete(UUID uuid) {
        }

        public int getProgress(UUID uuid) {
            return 1;
        }
    });

    final ModelAndView modelAndView = ctrl.svnHandle(null, command, 123, context, request, response, null);
    assertNotNull(modelAndView);

    assertTrue(context.getIsWaitingForExport());
    assertEquals(UUID_STRING, context.getExportUuid().toString());
}

From source file:com.splunk.shuttl.server.mbeans.ShuttlArchiverMBeanTest.java

public void load_preconfiguredFile_givesCorrectValues() throws Exception {
    List<String> archiveFormats = asList("SPLUNK_BUCKET", "CSV");
    String clusterName = "some_cluster_name";
    String serverName = "some_server_name";
    String archiverRootURI = "hdfs://localhost:1234";
    String configFilePreset = TUtilsMBean.XML_HEADER
            + "<ns2:archiverConf xmlns:ns2=\"com.splunk.shuttl.server.model\">\n" + "<archiveFormats>\n"
            + "<archiveFormat>SPLUNK_BUCKET</archiveFormat>\n" + "<archiveFormat>CSV</archiveFormat>\n"
            + "</archiveFormats>\n" + "<clusterName>" + clusterName + "</clusterName>\n" + "    <serverName>"
            + serverName + "</serverName>\n" + "    <archiverRootURI>" + archiverRootURI
            + "</archiverRootURI>\n" + "    <bucketFormatPriority>" + "SPLUNK_BUCKET"
            + "</bucketFormatPriority>\n" + "</ns2:archiverConf>";

    File file = createFile();
    file.deleteOnExit();
    FileUtils.writeStringToFile(file, configFilePreset);
    archiverMBean = ShuttlArchiver.createWithConfFile(file);
    assertEquals(archiverMBean.getArchiveFormats(), archiveFormats);
    assertEquals(archiverMBean.getClusterName(), clusterName);
    assertEquals(archiverMBean.getServerName(), serverName);
    assertEquals(archiverMBean.getArchiverRootURI(), archiverRootURI);
}

From source file:com.wavemaker.tools.webapp.WebXmlSupportTest.java

public void testReadWrite() throws Exception {

    File f = new ClassPathResource("com/wavemaker/tools/webapp/" + ProjectConstants.WEB_XML).getFile();
    assertTrue(f.exists());/* w  w w  .ja  va2s.  c  o m*/

    WebAppType wat = WebXmlSupport.readWebXml(new FileSystemResource(f));

    for (Object o : wat.getDescriptionAndDisplayNameAndIcon()) {
        if (o instanceof DisplayNameType) {
            DisplayNameType dnt = (DisplayNameType) o;
            assertEquals("ActiveGrid Studio", dnt.getValue());
        } else if (o instanceof ServletType) {
            ServletType st = (ServletType) o;
            assertEquals("springapp", st.getServletName().getValue());
        } else {
            // System.out.println("o: "+o);
        }
    }

    File fp = File.createTempFile("TestWebXmlSupport_testReadWrite", ".xml");
    fp.deleteOnExit();

    try {
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(fp));
        WebXmlSupport.writeWebXml(wat, osw);
        String fpContents = FileUtils.readFileToString(fp);

        assertTrue(fpContents.contains("ActiveGrid Studio"));
        assertTrue(fpContents.contains("springapp"));

        WebXmlSupport.readWebXml(new FileSystemResource(fp));
    } finally {
        fp.delete();
    }
}

From source file:fll.web.schedule.UploadSchedule.java

@Override
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response,
        final ServletContext application, final HttpSession session) throws IOException, ServletException {
    clearSesionVariables(session);/*w  w  w.  j  ava2  s. co m*/

    final File file = File.createTempFile("fll", null);
    file.deleteOnExit();
    try {
        // must be first to ensure the form parameters are set
        UploadProcessor.processUpload(request);

        // process file and keep track of filename in session.scheduleFilename
        final FileItem scheduleFileItem = (FileItem) request.getAttribute("scheduleFile");
        if (null == scheduleFileItem || scheduleFileItem.getSize() == 0) {
            session.setAttribute(SessionAttributes.MESSAGE,
                    "<p class='error'>A file containing a schedule must be specified</p>");
            WebUtils.sendRedirect(application, response, "/admin/index.jsp");
            return;
        } else {
            scheduleFileItem.write(file);
            session.setAttribute("uploadSchedule_file", file);

            WebUtils.sendRedirect(application, response, "/schedule/CheckScheduleExists");
            return;
        }
    } catch (final FileUploadException e) {
        LOGGER.error("There was an error processing the file upload", e);
        throw new FLLRuntimeException("There was an error processing the file upload", e);
    } catch (final Exception e) {
        final String message = "There was an error writing the uploaded file to the filesystem";
        LOGGER.error(message, e);
        throw new FLLRuntimeException(message, e);
    }

}

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

@Test
public void testTrainingDefault() 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));/*from   ww w . java2s .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);

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

From source file:com.logsniffer.model.file.FileLogTest.java

@Test
public void testReadArray() throws IOException {
    File openFile = File.createTempFile("test", "txt");
    openFile.deleteOnExit();
    FileOutputStream out = new FileOutputStream(openFile);
    FileLog flog = new FileLog(openFile);
    IOUtils.write("line1\n", out);
    out.flush();/*  ww  w  . j a  v  a  2  s .co m*/
    ByteLogInputStream lis = new DirectFileLogAccess(flog).getInputStream(null);
    byte[] buffer = new byte[1024];
    // Log instantiated before data is written
    assertEquals(-1, lis.read(buffer));
    flog = new FileLog(openFile);
    lis = new DirectFileLogAccess(flog).getInputStream(null);

    assertEquals(6, lis.read(buffer));
    assertEquals(-1, lis.read(buffer));

    // Write more, but lis doesn't see the new data due to size limitation
    IOUtils.write("l2\n", out);
    out.flush();
    assertEquals(-1, lis.read(buffer));
    LogPointer pointer = lis.getPointer();

    // Reopen input stream
    flog = new FileLog(openFile);
    lis = new DirectFileLogAccess(flog).getInputStream(pointer);
    assertEquals(3, lis.read(buffer, 0, 3));
    assertEquals(-1, lis.read(buffer, 0, 1));
    assertEquals('l', buffer[0]);
    assertEquals('2', buffer[1]);
    assertEquals('\n', buffer[2]);
}

From source file:com.eyeq.pivot4j.export.poi.FopExporterIT.java

@Test
public void testExportPdf() throws IOException {
    OutputStream out = null;/*from   www.  ja va  2  s.co m*/

    File file = File.createTempFile("pivot4j-", ".pdf");

    if (deleteTestFile) {
        file.deleteOnExit();
    }

    try {
        out = new FileOutputStream(file);

        FopExporter exporter = new FopExporter(out);

        exporter.setShowParentMembers(true);
        exporter.setShowDimensionTitle(true);
        exporter.setHideSpans(false);
        exporter.setOrientation(OrientationRequested.LANDSCAPE);

        exporter.render(getPivotModel());
    } finally {
        out.flush();
        IOUtils.closeQuietly(out);
    }
}

From source file:com.splunk.shuttl.server.mbeans.ShuttlArchiverMBeanArchiverRootURITest.java

private void createArchiverMbeanWithArchiverRootURI(String archiverRootURI) throws IOException {
    String configFilePreset = TUtilsMBean.XML_HEADER
            + "<ns2:archiverConf xmlns:ns2=\"com.splunk.shuttl.server.model\">\n" + "    <archiverRootURI>"
            + archiverRootURI + "</archiverRootURI>\n" + "</ns2:archiverConf>";
    File file = createFile();
    file.deleteOnExit();
    FileUtils.writeStringToFile(file, configFilePreset);
    archiverMBean = ShuttlArchiver.createWithConfFile(file);
}