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, File directory) throws IOException 

Source Link

Document

Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its name.

Usage

From source file:com.adaptris.core.stubs.TempFileUtils.java

public static File createTrackedFile(String prefix, String suffix, File baseDir, Object tracker)
        throws IOException {
    File f = File.createTempFile(prefix, suffix, baseDir);
    f.delete();/*from   w  ww.j a va2s  .  c  o  m*/
    return trackFile(f, tracker);
}

From source file:Main.java

/**
 * Creates the temporary image file in the cache directory.
 *
 * @return The temporary image file.//ww w .ja va 2 s.  com
 * @throws IOException Thrown if there is an error creating the file
 */
static File createTempImageFile(Context context) throws IOException {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = context.getExternalCacheDir();

    return File.createTempFile(imageFileName, /* prefix */
            ".jpg", /* suffix */
            storageDir /* directory */
    );
}

From source file:com.ggvaidya.TaxRef.Net.DownloadITIS.java

public static DarwinCSV getIt(JFrame mainFrame) {
    try {/*  ww  w.  j a  va2 s .  c o  m*/
        URL url = new URL(url_itisDwCtab);

        File tempFile = File.createTempFile("itis_dwctab", ".txt", null);
        FileUtils.copyURLToFile(url, tempFile, 10000, 100000);

        return new DarwinCSV(tempFile, DarwinCSV.FILE_CSV_DELIMITED);
    } catch (MalformedURLException ex) {
        MessageBox.messageBox(mainFrame, "Malformed URL", "Malformed URL (" + ex + "): " + url_itisDwCtab);
    } catch (IOException ex) {
        MessageBox.messageBox(mainFrame, "Unable to download ITIS-DwCA file", ex.getLocalizedMessage());
    }
    return null;
}

From source file:Main.java

public static File getTempFile(String prefix, String suffix) {
    File file = null;//from   w w  w.jav a  2  s  .c  o m
    try {
        file = File.createTempFile(prefix, suffix, getApp().getApplicationContext().getExternalCacheDir());
        myTempFiles.add(file);
    } catch (Exception e) {
    }
    return file;
}

From source file:hudson.plugins.dimensionsscm.CheckInAPITask.java

public Boolean execute(File area, VirtualChannel channel) throws IOException {

    boolean bRet = true;

    try {/*from   w w w . j  a v  a2  s.c  om*/
        listener.getLogger()
                .println("[DIMENSIONS] Scanning workspace for files to be saved into Dimensions...");
        listener.getLogger().flush();
        FilePath wd = new FilePath(area);
        Logger.Debug("Scanning directory for files that match patterns '" + wd.getRemote() + "'");
        File dir = new File(wd.getRemote());
        FileScanner fs = new FileScanner(dir, patterns, -1);
        File[] validFiles = fs.toArray();

        if (fs.getFiles().size() > 0) {
            listener.getLogger()
                    .println("[DIMENSIONS] Loading files into Dimensions project \"" + projectId + "\"...");
            listener.getLogger().flush();

            Calendar nowDateCal = Calendar.getInstance();
            File logFile = new File("a");
            FileWriter logFileWriter = null;
            PrintWriter fmtWriter = null;
            File tmpFile = null;

            try {
                tmpFile = logFile.createTempFile("dmCm" + nowDateCal.getTimeInMillis(), null, null);
                logFileWriter = new FileWriter(tmpFile);
                fmtWriter = new PrintWriter(logFileWriter, true);

                for (File f : validFiles) {
                    Logger.Debug("Found file '" + f.getAbsolutePath() + "'");
                    fmtWriter.println(f.getAbsolutePath());
                }
                fmtWriter.flush();
            } catch (Exception e) {
                bRet = false;
                throw new IOException("Unable to write command log - " + e.getMessage());
            } finally {
                fmtWriter.close();
            }

            // Debug for printing out files
            //String filesToLoad = new String(fu.loadFile(tmpFile));
            //if (filesToLoad!=null)
            //    filesToLoad += "\n";
            //if (filesToLoad != null) {
            //    filesToLoad = filesToLoad.replaceAll("\n\n","\n");
            //    listener.getLogger().println(filesToLoad.replaceAll("\n","\n[DIMENSIONS] - "));
            //}

            {
                String requests = myResolver.resolve("DM_TARGET_REQUEST");

                if (requests != null) {
                    requests = requests.replaceAll(" ", "");
                    requests = requests.toUpperCase();
                }

                DimensionsResult res = dmSCM.UploadFiles(key, wd, projectId, tmpFile, jobId, buildNo, requests,
                        isForceCheckIn, isForceTip, owningPart);
                if (res == null) {
                    listener.getLogger()
                            .println("[DIMENSIONS] New artifacts failed to get loaded into Dimensions");
                    listener.getLogger().flush();
                    bRet = false;
                } else {
                    listener.getLogger()
                            .println("[DIMENSIONS] Build artifacts were successfully loaded into Dimensions");
                    listener.getLogger().println(
                            "[DIMENSIONS] (" + res.getMessage().replaceAll("\n", "\n[DIMENSIONS] ") + ")");
                    listener.getLogger().flush();
                }
            }

            if (tmpFile != null) {
                tmpFile.delete();
            } else {
                listener.getLogger().println("[DIMENSIONS] No build artifacts were detected");
                listener.getLogger().flush();
            }
        } else {
            listener.getLogger().println("[DIMENSIONS] No build artifacts found for checking in");
        }

        listener.getLogger().flush();
    } catch (Exception e) {
        String errMsg = e.getMessage();
        if (errMsg == null) {
            errMsg = "An unknown error occurred. Please try the operation again.";
        }
        listener.fatalError("Unable to run checkin callout - " + errMsg);
        // e.printStackTrace();
        //throw new IOException("Unable to run checkin callout - " + e.getMessage());
        bRet = false;
    }
    return bRet;
}

From source file:ifpb.pod.proj.appdata.gerenciador.TXTNotificacao.java

public String criarNotificacao(String content) throws IOException {

    File filetxt = File.createTempFile("not", ".txt", new File(this.getClass().getResource("/msg/").getFile()));
    FileUtils.write(filetxt, content);/*from w  w w  .  j a v  a2  s  .c o  m*/

    String fileName = filetxt.getName();
    String token = fileName.substring(0, fileName.length() - 4);

    return token;

}

From source file:com.google.jenkins.plugins.credentials.oauth.KeyUtils.java

/**
 * Creates a file with the given prefix/suffix in a standard Google auth
 * directory, and sets the permissions of the file to owner-only read/write.
 *
 * @throws IOException if filesystem interaction fails.
 *//*from w w w .ja v  a 2s  .com*/
public static File createKeyFile(String prefix, String suffix) throws IOException {
    File keyFolder = new File(Jenkins.getInstance().getRootDir(), "gauth");
    if (keyFolder.exists() || keyFolder.mkdirs()) {
        File result = File.createTempFile(prefix, suffix, keyFolder);
        if (result == null) {
            throw new IOException("Failed to create key file");
        }
        updatePermissions(result);
        return result;
    } else {
        throw new IOException("Failed to create key folder");
    }
}

From source file:Utils.java

/**
 * Unpack an archive from a URL/*from   w  w  w  .  j av  a  2s  .  c om*/
 * 
 * @param url
 * @param targetDir
 * @return the file to the url
 * @throws IOException
 */
public static File unpackArchive(URL url, File targetDir) throws IOException {
    if (!targetDir.exists()) {
        targetDir.mkdirs();
    }
    InputStream in = new BufferedInputStream(url.openStream(), 1024);
    // make sure we get the actual file
    File zip = File.createTempFile("arc", ".zip", targetDir);
    OutputStream out = new BufferedOutputStream(new FileOutputStream(zip));
    copyInputStream(in, out);
    out.close();
    return unpackArchive(zip, targetDir);
}

From source file:com.gs.obevo.util.FileUtilsCobra.java

public static File createTempDir(String tmpDirPrefix) {
    File tmpFile;//  w  ww  . jav a 2  s . c  o m
    try {
        tmpFile = File.createTempFile(tmpDirPrefix, ".tmp", SystemUtils.getJavaIoTmpDir());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    FileUtils.deleteQuietly(tmpFile);
    String tmpFilePath = tmpFile.getAbsolutePath();

    return new File(tmpFilePath.substring(0, tmpFilePath.length() - 4)); // trim the extension
}

From source file:gov.nih.nci.calims2.business.storage.StorageServiceImpl.java

/**
 * {@inheritDoc}/*from   www. j  ava  2 s .co  m*/
 * 
 * @throws StorageServiceException
 */

public File get(Document document, File dir) throws StorageServiceException {
    File inputFile = new File(document.getUniversalResourceLocator());
    File outputFile;
    try {
        outputFile = File.createTempFile("LPGLIMS", "", dir);
        FileUtils.copyFile(inputFile, outputFile);
    } catch (IOException e) {
        throw new StorageServiceException("Error saving file from storage" + e.getMessage());
    }
    return outputFile;
}