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.premiumminds.persistence.utils.HibernateEnversDDLTest.java

@Test
public void testCreateDropCommandWithFile() throws Exception {

    File file = File.createTempFile("updatedb", ".sql");
    file.deleteOnExit();

    String[] args = new String[] { "--create-drop", "application-data-unit-export-test",
            file.getAbsolutePath() };/* w  w  w  .ja v  a2s .c o m*/

    HibernateEnversDDL.main(args);

    assertTrue(outContent.toString().isEmpty());
    assertEquals("\n" + "    drop table FooBar if exists;\n" + "\n" + "    drop table FooBar_AUD if exists;\n"
            + "\n" + "    drop table REVINFO if exists;\n" + "\n" + "    create table FooBar (\n"
            + "        id integer not null,\n" + "        bar integer not null,\n"
            + "        foo varchar(255),\n" + "        primary key (id)\n" + "    );\n" + "\n"
            + "    create table FooBar_AUD (\n" + "        id integer not null,\n"
            + "        REV integer not null,\n" + "        REVTYPE tinyint,\n" + "        bar integer,\n"
            + "        foo varchar(255),\n" + "        primary key (id, REV)\n" + "    );\n" + "\n"
            + "    create table REVINFO (\n" + "        REV integer generated by default as identity,\n"
            + "        REVTSTMP bigint,\n" + "        primary key (REV)\n" + "    );\n" + "\n"
            + "    alter table FooBar_AUD \n" + "        add constraint FK_hq6lvb9twe0idlwiwq4locy79 \n"
            + "        foreign key (REV) \n" + "        references REVINFO;\n",
            IOUtils.toString(new FileReader(file)));
}

From source file:net.sourceforge.jukebox.model.ProfileTest.java

/**
 * Tests the <code>load</code> and <code>save</code> methods.
 * @throws IOException IOException/* w  w  w.  ja va2 s  .  c om*/
 * @throws ConfigurationException ConfigurationException
 */
@Test
public final void testLoad() throws IOException, ConfigurationException {
    Profile profile = new Profile();
    profile.setNewPassword("abcdefghijklmnopqrstuvwxyz");

    File file = File.createTempFile("dummy", "properties");

    file.deleteOnExit();
    PropertiesConfiguration configuration = new PropertiesConfiguration(file);
    configuration.setDelimiterParsingDisabled(true);

    profile.save(configuration);

    Profile savedProfile = new Profile();
    savedProfile.load(configuration);

    assertEquals(profile.getNewPassword(), savedProfile.getOldPassword());
}

From source file:com.googlecode.japi.checker.cli.Main.java

private File writeToTempFile(FileObject fo) throws IOException {
    File temp = File.createTempFile("lib-", fo.getName().getExtension());
    temp.deleteOnExit();
    InputStream is = fo.getContent().getInputStream();
    OutputStream os = new FileOutputStream(temp);
    int c = 0;/* www .  ja v  a  2 s  . c  o  m*/
    try {
        while ((c = is.read()) != -1) {
            os.write(c);
        }
    } finally {
        os.close();
        is.close();
    }
    return temp;
}

From source file:com.playonlinux.core.python.PythonInstallerTest.java

@Test
public void testPythonInstaller_DefineVariableAttributes_AttributesAreSet()
        throws IOException, PlayOnLinuxException {
    File temporaryOutput = new File("/tmp/testPythonInstaller_DefineVariableAttributes.log");
    temporaryOutput.deleteOnExit();

    if (temporaryOutput.exists()) {
        temporaryOutput.delete();/*  www .java2  s.  com*/
    }

    File temporaryScript = File.createTempFile("defineVariableAttributes", "py");
    temporaryScript.deleteOnExit();

    try (FileOutputStream fileOutputStream = new FileOutputStream(temporaryScript)) {
        fileOutputStream.write(("from com.playonlinux.framework.templates import MockWineSteamInstaller\n"
                + "\n" + "class Example(MockWineSteamInstaller):\n"
                + "    title = \"testPythonInstaller_DefineVariableAttributes\"\n" + "    prefix = \"Prefix\"\n"
                + "    wineversion = \"1.7.34\"\n" + "    steamId = 130\n"
                + "    packages = [\"package1\", \"package2\"]\n").getBytes());
    }

    PythonInterpreter interpreter = defaultJythonInterpreterFactory.createInstance();
    interpreter.execfile(temporaryScript.getAbsolutePath());
    PythonInstaller<ScriptTemplate> pythonInstaller = new PythonInstaller<>(interpreter, ScriptTemplate.class);

    pythonInstaller.exec();

    assertTrue(FileUtils.readFileToString(temporaryOutput)
            .contains("Implementation has to be done, but we have access to prefix (Prefix), "
                    + "wineversion (1.7.34), steamId (130) and packages (['package1', 'package2'])."
                    + " First package (to check that we have a list: package1\n"));
}

From source file:eu.excitementproject.eop.distsim.redisinjar.EmbeddedRedisServerRunner.java

private File extractExecutableFromJar(String scriptName) throws IOException {
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();

    File command = new File(tmpDir, scriptName);
    FileUtils.copyURLToFile(Resources.getResource(scriptName), command);
    command.deleteOnExit();//from w ww . j av a2s. co m
    command.setExecutable(true);

    return command;
}

From source file:com.jaxio.celerio.configuration.database.support.MetaDataExtractorTest.java

@Test
public void outputIsSameAsInput()
        throws ClassNotFoundException, SQLException, XmlMappingException, IOException {
    EmbeddedDatabase embeddedDatabase = createMinimalEmbeddedDatabase(ALL_RELATIONS_SCRIPT);

    Metadata meta = extractor.extract(embeddedDatabase.getConnection());

    assertThat(countTables(meta)).isEqualTo(18);
    assertThat(countColumns(meta)).isEqualTo(49);
    assertThat(countPrimaryKeys(meta)).isEqualTo(18);
    assertThat(countIndexes(meta)).isEqualTo(21);
    assertThat(countEnums(meta)).isEqualTo(3);

    File tempFile = File.createTempFile(getClass().getName(), ".xml");
    tempFile.deleteOnExit();
    loader.write(meta, tempFile);/*  w  w  w . j ava2 s  .  co  m*/

    Metadata loadedMeta = loader.load(tempFile);
    assertThat(countTables(meta)).isEqualTo(countTables(loadedMeta));
    assertThat(countColumns(meta)).isEqualTo(countColumns(loadedMeta));
    assertThat(countPrimaryKeys(meta)).isEqualTo(countPrimaryKeys(loadedMeta));
    assertThat(countIndexes(meta)).isEqualTo(countIndexes(loadedMeta));
    assertThat(countEnums(meta)).isEqualTo(countEnums(loadedMeta));

    embeddedDatabase.shutdown();
}

From source file:org.ngrinder.script.controller.SvnDavControllerTest.java

private void prepareSVN() throws IOException, SVNException {
    File tempRepo = new File(System.getProperty("java.io.tmpdir"), "repo");
    fileEntityRepository.setUserRepository(new File(tempRepo, getTestUser().getUserId()));
    tempRepo.deleteOnExit();
    File testUserRoot = fileEntityRepository.getUserRepoDirectory(getTestUser()).getParentFile();
    FileUtils.deleteQuietly(testUserRoot);
    testUserRoot.mkdirs();/*w  ww .j av  a2 s.co m*/
    CompressionUtils.unzip(new ClassPathResource("TEST_USER.zip").getFile(), testUserRoot);
    testUserRoot.deleteOnExit();
    MockServletConfig servletConfig = new MockServletConfig();
    servletConfig.addInitParameter("SVNParentPath", testUserRoot.getAbsolutePath());
    DAVConfig davConfig = new DAVConfig(servletConfig);
    svnController.setDAVConfig(davConfig);
}

From source file:com.dtolabs.rundeck.core.common.impl.TestURLFileUpdater.java

/**
 * Test use of file: url// w w  w.java2s.  c  o m
 */
public void testUpdateFileUrl() throws Exception {

    final File file = new File("src/test/resources/com/dtolabs/rundeck/core/common/test-nodes1.xml");
    URLFileUpdater updater = new URLFileUpdater(file.toURI().toURL(), null, -1, null, null, false, null, null);

    File tempfile = File.createTempFile("test", ".yaml");
    tempfile.deleteOnExit();
    updater.updateFile(tempfile);
    assertTrue(tempfile.isFile());
    assertEquals(file.length(), tempfile.length());
}

From source file:UnpackedJarFile.java

public static File createTempFile() throws IOException {
    File tempFile = File.createTempFile("geronimo-deploymentUtil", ".tmpdir");
    tempFile.deleteOnExit();
    return tempFile;
}