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:cx.jbzdak.diesIrae.genieConnector.ParamTest.java

@Before
public void startup() throws Exception {
    connector = new SimpleConnector();
    File f = new File("C:\\GENIE2K\\CAMFILES\\NBSSTD.CNF");
    File temp = File.createTempFile("gcTest", "CNF");
    temp.deleteOnExit();
    FileUtils.copyFile(f, temp);//www. j  a  v a 2  s.  c  o m
    connector.setFlush(FlushType.AUTO_COMMIT);
    connector.openFile(temp, EnumSet.of(OpenMode.READ_WRITE, OpenMode.SYSTEM_WRITE, OpenMode.EXCLUSIVE,
            OpenMode.TAKE_CONTROL, OpenMode.TAKE_OVER));
    //connector.openSource("DET_1", EnumSet.of(OpenMode.READ_WRITE, OpenMode.SYSTEM_WRITE, OpenMode.EXCLUSIVE), SourceType.DETECTOR);
}

From source file:org.openengsb.openengsbplugin.tools.OpenEngSBVersionResolver.java

private File createTmpFile(String content) throws IOException {
    File temp = File.createTempFile("metadata", ".xml");
    temp.deleteOnExit();
    BufferedWriter out = new BufferedWriter(new FileWriter(temp));
    out.write(content);/*from w  w w  .  ja  v a2  s .c  om*/
    out.close();
    return temp;
}

From source file:edu.umn.msi.tropix.proteomics.test.ProteomicsInputTest.java

public void testProteomicsInput(final boolean readFromFile) throws Exception {
    BiomlWriter input = null;//from  w  w  w  . j  a v a  2 s  .com
    if (readFromFile) {
        final File tempFile = File.createTempFile("tpxtest", "");
        tempFile.deleteOnExit();
        FileUtils.writeStringToFile(tempFile,
                IOUtils.toString(getClass().getResourceAsStream("proteomicsInput1.xml")));
        input = new BiomlWriter(tempFile.getAbsolutePath());
    } else {
        input = new BiomlWriter(getClass().getResourceAsStream("proteomicsInput1.xml"));

    }
    boolean wasException = false;
    try {
        input.addVariable("test heading", "test");
    } catch (final IllegalArgumentException e) {
        wasException = true;
    }
    assert wasException;
    input.addHeader("test heading 2");
    input.addVariable("test heading 2", "param1", "param1 value again");
    input.addVariable("test heading 2", "param2", "param2 value");
    final String xml = input.toString();
    assert xml.contains("label=\"test heading 2\"") : "XML did not contain heading 2 label";
    assert xml.contains("label=\"test heading 2, param1\"") : "XML did not contain param1 input";
    assert xml.contains("label=\"test heading 2, param2\"") : "XML did not contain param2 input";
    assert xml.contains(">param1 value again<") : "XML did not contain param1 value";
    assert xml.contains(">param2 value<") : "XML did not contain param2 value";
    assert xml.contains("label=\"test heading, param1\"") : "XML did not contain old param1 value";
    assert xml.contains(">param1 value<") : "XML did not contain old param1 value";
}

From source file:com.wavemaker.commons.util.utils.ClassLoaderUtilsTest.java

@Test
public void tempClassLoader_getClassTest() throws Exception {

    File sourceJar = new ClassPathResource("com/wavemaker/commons/foojar.jar").getFile();
    File jar = File.createTempFile("tempClassLoader_getClassTest", ".jar");
    jar.deleteOnExit();
    FileUtils.copyFile(sourceJar, jar);/* ww w .  j  a v  a2  s. c o  m*/

    try {
        ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar);
        Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl);
        assertNotNull(klass);
    } finally {
        jar.delete();
    }
}

From source file:com.thoughtworks.go.domain.ConsoleStreamerTest.java

private File makeConsoleFile(String... message) throws IOException {
    File console = File.createTempFile("console", ".log");
    console.deleteOnExit();

    Files.write(console.toPath(), StringUtils.join(message, "\n").getBytes());
    return console;
}

From source file:com.github.javarch.support.data.LocalFileStorage.java

public String storeFile(FileData fileData) {
    File file = new File(storageDirectory, fileData.getName());
    if (file.exists()) {
        file.delete();/*from w w  w .  ja  v a  2s .  c  om*/
    }
    File parent = file.getParentFile();
    if (parent != null && !parent.equals(storageDirectory)) {
        parent.mkdirs();
    }
    LinkedList<File> parents = new LinkedList<File>();
    while (parent != null && !parent.equals(storageDirectory)) {
        parents.addFirst(parent);
        parent = parent.getParentFile();
    }
    if (deleteOnExit) {
        for (File p : parents) {
            p.deleteOnExit();
        }
        file.deleteOnExit();
    }
    try {
        file.createNewFile();
        FileOutputStream os = new FileOutputStream(file);
        os.write(fileData.getBytes());
    } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return file.toURI().toString();
}

From source file:com.a544jh.kanamemory.io.FileIoTest.java

@After
public void tearDown() {
    File tmpfile = new File("profiles_test.tmp");
    tmpfile.deleteOnExit();
}

From source file:com.wavemaker.commons.util.utils.ClassLoaderUtilsTest.java

@Test
public void tempClassLoader_getResourceTest() throws Exception {

    File sourceJar = new ClassPathResource("com/wavemaker/commons/foojar.jar").getFile();
    File jar = File.createTempFile("tempClassLoader_getClassTest", ".jar");
    jar.deleteOnExit();
    FileUtils.copyFile(sourceJar, jar);/* w  ww.  ja  va2 s.co  m*/

    try {
        ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar);
        InputStream is = ClassLoaderUtils.getResourceAsStream("foo/bar/baz/JarType.java", cl);
        assertNotNull(is);
        assertTrue(is.available() > 0);
        is.close();
    } finally {
        jar.delete();
    }
}

From source file:com.hortonworks.registries.util.HdfsFileStorageTest.java

@Test
public void testUploadJar() throws Exception {
    Map<String, String> config = new HashMap<>();
    config.put(HdfsFileStorage.CONFIG_FSURL, "file:///");
    fileStorage.init(config);//w  ww.  jav  a 2  s  .co m

    File file = File.createTempFile("test", ".tmp");
    file.deleteOnExit();

    List<String> lines = Arrays.asList("test-line-1", "test-line-2");
    Files.write(file.toPath(), lines, Charset.forName("UTF-8"));
    String jarFileName = "test.jar";

    fileStorage.deleteFile(jarFileName);

    fileStorage.uploadFile(new FileInputStream(file), jarFileName);

    InputStream inputStream = fileStorage.downloadFile(jarFileName);
    List<String> actual = IOUtils.readLines(inputStream);
    Assert.assertEquals(lines, actual);
}

From source file:cn.guoyukun.spring.web.controller.AjaxUploadController.java

@RequestMapping(value = "ajaxUpload/delete", method = RequestMethod.POST)
@ResponseBody/*from   ww w . j a  v  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, Constants.ENCODING);

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

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

    return "";
}