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.cloudera.kitten.util.LocalDataHelper.java

public void copyConfiguration(String key, Configuration conf) throws IOException {
    File tmpFile = File.createTempFile("job", ".xml");
    tmpFile.deleteOnExit();
    OutputStream os = new FileOutputStream(tmpFile);
    conf.writeXml(os);/* w  w  w .  j  a v a2s  .  c o  m*/
    os.close();
    copyToHdfs(key, tmpFile.getAbsolutePath());
}

From source file:com.migratebird.script.runner.impl.BaseNativeScriptRunner.java

protected File createTemporaryScriptFile(Script script) throws IOException {
    File temporaryScriptsDir = createTemporaryScriptsDir();
    File temporaryScriptFile = new File(temporaryScriptsDir, getTemporaryScriptName(script));
    temporaryScriptFile.deleteOnExit();

    Reader scriptContentReader = script.getScriptContentHandle().openScriptContentReader();
    try {// ww w .ja v a 2 s . c om
        createFile(temporaryScriptFile, scriptContentReader);
    } finally {
        scriptContentReader.close();
    }
    return temporaryScriptFile;
}

From source file:io.gatling.mojo.Fork.java

private File createArgFile(List<String> args) throws IOException {
    final File argFile = File.createTempFile(ARG_FILE_PREFIX, ARG_FILE_SUFFIX);
    argFile.deleteOnExit();
    try (PrintWriter out = new PrintWriter(argFile)) {
        for (String arg : args) {
            out.println(arg);/*from w  w  w  .ja  v  a2  s.c  o m*/
        }
        return argFile;
    }
}

From source file:net.lmxm.ute.executers.tasks.FileSystemDeleteTaskExecuterTest.java

/**
 * Test delete files single directory./*from  w  ww . java 2  s .  co  m*/
 */
@Test
public void testDeleteFilesSingleDirectory() {
    final File directory = new File(TMP_DIR, "TESTDIRECTORY");
    directory.deleteOnExit();
    directory.mkdir();

    assertTrue(directory.exists());

    executer.deleteFiles(directory.getAbsolutePath(), null, STOP_ON_ERROR);

    assertFalse(directory.exists());
}

From source file:org.emonocot.job.common.GetResourceClientTest.java

/**
 *
 * @throws IOException//from w  w  w .  j  a  v a2s . c  om
 *             if a temporary file cannot be created or if there is a http
 *             protocol error.
 * @throws SAXException
 *             if the content retrieved is not valid xml.
 */
@Test
public final void testGetResourceSuccessfully() throws IOException, SAXException {
    File tempFile = File.createTempFile("test", "zip");
    tempFile.deleteOnExit();

    EasyMock.expect(httpClient.getParams()).andReturn(new BasicHttpParams());
    EasyMock.expect(httpClient.execute(EasyMock.isA(HttpGet.class))).andReturn(httpResponse);
    EasyMock.replay(httpClient);

    ExitStatus exitStatus = getResourceClient.getResource(testzip, Long.toString(new Date().getTime()),
            tempFile.getAbsolutePath());

    EasyMock.verify(httpClient);

    assertNotNull("ExitStatus should not be null", exitStatus);
    assertEquals("ExitStatus should be COMPLETED", exitStatus, ExitStatus.COMPLETED);
}

From source file:com.metamx.druid.realtime.plumber.RealtimePlumberSchoolTest.java

@Before
public void setUp() throws Exception {

    final File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();

    final Schema schema = new Schema("test", Lists.<SpatialDimensionSchema>newArrayList(),
            new AggregatorFactory[] { new CountAggregatorFactory("rows") }, QueryGranularity.NONE,
            new NoneShardSpec());

    RealtimePlumberSchool realtimePlumberSchool = new RealtimePlumberSchool(new Period("PT10m"), tmpDir,
            IndexGranularity.HOUR);//from www  .  j  a va 2  s .co m

    announcer = EasyMock.createMock(DataSegmentAnnouncer.class);
    announcer.announceSegment(EasyMock.<DataSegment>anyObject());
    EasyMock.expectLastCall().anyTimes();

    segmentPublisher = EasyMock.createMock(SegmentPublisher.class);
    dataSegmentPusher = EasyMock.createMock(DataSegmentPusher.class);

    serverView = EasyMock.createMock(ServerView.class);
    serverView.registerSegmentCallback(EasyMock.<Executor>anyObject(),
            EasyMock.<ServerView.SegmentCallback>anyObject());
    EasyMock.expectLastCall().anyTimes();

    emitter = EasyMock.createMock(ServiceEmitter.class);

    EasyMock.replay(announcer, segmentPublisher, dataSegmentPusher, serverView, emitter);

    realtimePlumberSchool.setConglomerate(new DefaultQueryRunnerFactoryConglomerate(
            Maps.<Class<? extends Query>, QueryRunnerFactory>newHashMap()));
    realtimePlumberSchool.setSegmentAnnouncer(announcer);
    realtimePlumberSchool.setSegmentPublisher(segmentPublisher);
    realtimePlumberSchool.setRejectionPolicyFactory(new NoopRejectionPolicyFactory());
    realtimePlumberSchool.setVersioningPolicy(new IntervalStartVersioningPolicy());
    realtimePlumberSchool.setDataSegmentPusher(dataSegmentPusher);
    realtimePlumberSchool.setServerView(serverView);
    realtimePlumberSchool.setServiceEmitter(emitter);

    plumber = realtimePlumberSchool.findPlumber(schema, new FireDepartmentMetrics());
}

From source file:org.emonocot.job.common.GetResourceClientTest.java

/**
 *
 * @throws IOException//www .  ja v  a2s.c o  m
 *             if a temporary file cannot be created or if there is a http
 *             protocol error.
 */
@Test
public final void testGetResourceNotModified() throws IOException {
    File tempFile = File.createTempFile("test", "zip");
    tempFile.deleteOnExit();
    httpResponse.setStatusLine(
            new BasicStatusLine(HttpVersion.HTTP_1_0, HttpStatus.SC_NOT_MODIFIED, "Not Modified"));

    EasyMock.expect(httpClient.getParams()).andReturn(new BasicHttpParams());
    EasyMock.expect(httpClient.execute(EasyMock.isA(HttpGet.class))).andReturn(httpResponse);
    EasyMock.replay(httpClient);

    ExitStatus exitStatus = getResourceClient.getResource(testzip, Long.toString(new Date().getTime()),
            tempFile.getAbsolutePath());

    EasyMock.verify(httpClient);

    assertNotNull("ExitStatus should not be null", exitStatus);
    assertEquals("ExitStatus should be NOT_MODIFIED", exitStatus.getExitCode(), "NOT_MODIFIED");
}

From source file:org.emonocot.job.common.GetResourceClientTest.java

/**
 *
  @throws IOException/*w  w  w .  j  a v  a  2 s  . c  om*/
 *             if a temporary file cannot be created or if there is a http
 *             protocol error.
 */
@Test
public final void testGetDocumentAnyOtherStatus() throws IOException {
    File tempFile = File.createTempFile("test", "zip");
    tempFile.deleteOnExit();
    httpResponse
            .setStatusLine(new BasicStatusLine(HttpVersion.HTTP_1_0, HttpStatus.SC_BAD_REQUEST, "Bad Request"));

    EasyMock.expect(httpClient.getParams()).andReturn(new BasicHttpParams());
    EasyMock.expect(httpClient.execute(EasyMock.isA(HttpGet.class))).andReturn(httpResponse).anyTimes();
    EasyMock.replay(httpClient);

    ExitStatus exitStatus = getResourceClient.getResource(testzip, Long.toString(new Date().getTime()),
            tempFile.getAbsolutePath());

    EasyMock.verify(httpClient);

    assertNotNull("ExitStatus should not be null", exitStatus);
    assertEquals("ExitStatus should be FAILED", exitStatus, ExitStatus.FAILED);
}

From source file:cc.recommenders.nativelibs.NativeLibLoader.java

private File createTempFile(String library) throws IOException {
    String tmpDirName = System.getProperty(JAVA_IO_TMPDIR);
    File tmpDir = new File(tmpDirName);
    if (!tmpDir.exists()) {
        tmpDir.mkdir();//from  w  w w .  j  a  v a2  s  .  c o  m
    }
    File file = File.createTempFile(library + "-", ".tmp", tmpDir);
    // Clean up the file when exiting
    file.deleteOnExit();
    return file;
}

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

@Test
public void testPythonInstaller_DefineLogContextWithAttribute_ContextIsSet()
        throws IOException, PlayOnLinuxException {
    File temporaryScript = File.createTempFile("testDefineLogContext", "py");
    temporaryScript.deleteOnExit();

    try (FileOutputStream fileOutputStream = new FileOutputStream(temporaryScript)) {
        fileOutputStream.write(//w ww. ja v a 2 s.c  o m
                ("#!/usr/bin/env/python\n" + "from com.playonlinux.framework.templates import Installer\n"
                        + "\n" + "class PlayOnLinuxBashInterpreter(Installer):\n"
                        + "   title = \"Mock Log Context 2\"\n" + "   def main(self):\n" + "        pass\n")
                                .getBytes());
    }

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

    assertEquals("Mock Log Context 2", pythonInstaller.extractLogContext());
}