Example usage for java.io File createTempFile

List of usage examples for java.io File createTempFile

Introduction

In this page you can find the example usage for java.io File createTempFile.

Prototype

public static File createTempFile(String prefix, String suffix) throws IOException 

Source Link

Document

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

Usage

From source file:com.proofpoint.zookeeper.io.TempLocalDirectory.java

private File createTempDir(File parent) throws IOException {
    File dir;//  w w  w.  j  ava2s . co m
    if (parent == null) {
        dir = File.createTempFile(PREFIX, SUFFIX);
    } else {
        dir = File.createTempFile(PREFIX, SUFFIX, parent);
    }

    if (!dir.delete()) {
        throw new IOException("Could not delete temp file: " + path.getAbsolutePath());
    }
    if (!dir.mkdir()) {
        throw new IOException("Could not create temp dir: " + path.getAbsolutePath());
    }

    return dir;
}

From source file:de.uni_siegen.wineme.come_in.thumbnailer.util.TemporaryFilesManager.java

/**
 * Create a new, read-only temporary file.
 * //w  ww. j  av a  2s  . c  om
 * @param file         Original file that you need a copy of
 * @param newExtension   The extension that the new file should have
 * @return File (read-only) 
 * @throws IOException
 */
public File createTempfileCopy(File file, String newExtension) throws IOException {
    File destFile = files.get(file);
    if (destFile == null) {
        destFile = File.createTempFile("temp", "." + newExtension);
        createNewCopy(file, destFile);
        destFile.setWritable(false, false);
    } else {
        String newFilename = FilenameUtils.removeExtension(destFile.getAbsolutePath()) + "." + newExtension;
        File newFile = new File(newFilename);
        boolean renameSucces = destFile.renameTo(newFile);
        if (!renameSucces) {
            createNewCopy(file, newFile);
        }
        files.put(file, newFile);
        destFile = newFile;
    }
    return destFile;
}

From source file:Main.java

static File makeTempJar(File moduleFile) throws IOException {
    String prefix = moduleFile.getName();
    if (prefix.endsWith(".jar") || prefix.endsWith(".JAR")) { // NOI18N
        prefix = prefix.substring(0, prefix.length() - 4);
    }/* ww w. j ava  2s.co m*/
    if (prefix.length() < 3)
        prefix += '.';
    if (prefix.length() < 3)
        prefix += '.';
    if (prefix.length() < 3)
        prefix += '.';
    String suffix = "-test.jar"; // NOI18N
    File physicalModuleFile = File.createTempFile(prefix, suffix);
    physicalModuleFile.deleteOnExit();
    InputStream is = new FileInputStream(moduleFile);
    try {
        OutputStream os = new FileOutputStream(physicalModuleFile);
        try {
            byte[] buf = new byte[4096];
            int i;
            while ((i = is.read(buf)) != -1) {
                os.write(buf, 0, i);
            }
        } finally {
            os.close();
        }
    } finally {
        is.close();
    }
    return physicalModuleFile;
}

From source file:eu.europa.ec.markt.dss.signature.StreamDocument.java

private void createTemporaryFileOfStream(InputStream stream) {
    logger.debug("");
    byte[] bytes = new byte[MAX_SIZE_IN_MEMORY];

    FileOutputStream out = null;//from  w  w w.ja v  a2s.  c o m

    try {
        temporaryFile = File.createTempFile("digidoc4j", ".tmp");
        out = new FileOutputStream(temporaryFile);
        int result;
        while ((result = stream.read(bytes)) > 0) {
            out.write(bytes, 0, result);
        }
        out.flush();
    } catch (IOException e) {
        logger.error(e.getMessage());
        throw new DSSException(e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:blog.detect.DetectSingleFaceFromFileExample.java

public static void main(String[] args) throws IOException {
    FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),
            System.getProperty("azure.cognitive.emotion.subscriptionKey"));
    File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic");
    //create a new java.io.File from a remote file
    FileUtils.copyURLToFile(new URL(FILE_LOCATION_OF_US_PRESIDENT), imageFile);
    FileUtils.forceDeleteOnExit(imageFile);
    ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile);
    imageOverlayBuilder.outlineFaceOnImage(faceScenarios.findSingleFace(imageFile), RectangleType.FULL)
            .launchViewer();/*from  w ww .j  av  a 2  s  .  c o m*/
}

From source file:com.digitalpebble.stormcrawler.parse.filter.DebugParseFilter.java

@SuppressWarnings("rawtypes")
@Override//from  w  ww .j a va 2  s .  c o  m
public void configure(Map stormConf, JsonNode filterParams) {
    try {
        File outFile = File.createTempFile("DOMDump", ".xml");
        os = FileUtils.openOutputStream(outFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.digitalpebble.storm.crawler.parse.filter.DebugParseFilter.java

@SuppressWarnings("rawtypes")
@Override//  w  w  w .  j a v  a2 s .  c  om
public void configure(Map stormConf, JsonNode filterParams) {
    try {
        File outFile = File.createTempFile("DOMDump", ".txt");
        os = FileUtils.openOutputStream(outFile);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.ikon.util.FileUtils.java

/**
 * Create temp file/*  w  w  w. j av  a  2s.c o  m*/
 */
public static File createTempFile() throws IOException {
    return File.createTempFile("okm", ".tmp");
}

From source file:com.googlecode.t7mp.TomcatArtifactDispatcherTest.java

@Before
public void setUp() throws IOException {
    catalinaBaseDir = new File(new File(System.getProperty("java.io.tmpdir")), "catalinaBase_" + (++counter));
    catalinaBaseDir.mkdirs();//from   w  ww.j  av a  2 s. c om
    catalinaBaseDir.deleteOnExit();
    sourceFile = File.createTempFile("sourceTest", ".tmp");
}

From source file:com.yfiton.oauth.receiver.GraphicalReceiver.java

@Override
public AuthorizationData requestAuthorizationData(String authorizationUrl,
        String authorizationCodeParameterName, String... requestParameterNames) throws NotificationException {
    try {//from  ww  w  . jav a2s.c o  m
        File tmpFile = File.createTempFile("yfiton", ".auth");

        ProcessBuilder processBuilder = new ProcessBuilder();
        processBuilder.inheritIO();
        processBuilder.command("java",
                //"-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005",
                "-classpath", getClasspath(), WebBrowser.class.getName(),
                "--authorization-code-parameter-name=" + authorizationCodeParameterName,
                "--authorization-file=" + tmpFile.getAbsolutePath(), "--authorization-url=" + authorizationUrl,
                "--debug=" + (debug ? "true" : "false"),
                "--webengine-listener-class=" + webEngineListenerClazz.getName());

        Process process = processBuilder.start();

        int returnCode = process.waitFor();

        switch (returnCode) {
        case 0:
            return OAuthUtils.readAuthorizationInfo(tmpFile.toPath());
        case 255:
            throw new NotificationException("Authorization process aborted");
        default:
            throw new NotificationException(
                    "Error occurred while waiting for process: return code " + returnCode);
        }
    } catch (ClassNotFoundException | ConfigurationException | IOException | InterruptedException e) {
        throw new NotificationException(e.getMessage());
    }
}