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:net.paissad.jcamstream.utils.PropertiesConfTest.java

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    tempFile = File.createTempFile("testPropsTemp", ".conf", null);
}

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

public static File createTrackedDir(String prefix, String suffix, File baseDir, Object tracker)
        throws IOException {
    File f = File.createTempFile(prefix, suffix, baseDir);
    f.delete();//from   w  w  w.jav a 2  s  . c o  m
    f.mkdirs();
    cleaner.track(f, tracker, FileDeleteStrategy.FORCE);
    return trackFile(f, tracker);
}

From source file:net.przemkovv.sphinx.Utils.java

public static File createRandomTempDirectory(String prefix, String tmp_dir) throws IOException {
    final File temp;
    File tmp_dir_file = null;//ww  w .  j  av  a2 s  .  com
    if (tmp_dir != null && !tmp_dir.isEmpty()) {
        tmp_dir_file = new File(tmp_dir);
    }
    temp = File.createTempFile(prefix, null, tmp_dir_file);
    if (!(temp.delete())) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }
    if (!(temp.mkdir())) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }
    return (temp);
}

From source file:be.isl.desamouryv.sociall.service.FileServiceImpl.java

@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@Override//from w  ww. j  a  v a 2  s. c o  m
public String storeFile(InputStream input, String fileName, String uploadPath) throws IOException {
    logger.log(Level.INFO, "uploadPath: {0}", uploadPath);

    String prefix = FilenameUtils.getBaseName(fileName).replaceAll(" ", "");
    String suffix = FilenameUtils.getExtension(fileName);

    File tempFile = File.createTempFile(prefix + "-", "." + suffix, new File(uploadPath));
    OutputStream output = new FileOutputStream(tempFile);

    try {
        IOUtils.copy(input, output);
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
    logger.log(Level.INFO, "file uploaded at: {0}", tempFile.getAbsolutePath());
    return tempFile.getName();
}

From source file:org.wso2.am.integration.services.jaxrs.peoplesample.Starter.java

private static File createBaseDirectory() throws IOException {
    final File base = File.createTempFile("tmp-", "",
            new File("/home/dharshana/reaserch/jetty/jetty2/src/main/resources"));

    if (!base.delete()) {
        throw new IOException("Cannot (re)create base folder: " + base.getAbsolutePath());
    }/*from www  . java  2 s .  com*/

    if (!base.mkdir()) {
        throw new IOException("Cannot create base folder: " + base.getAbsolutePath());
    }
    return base;
}

From source file:com.indeed.lsmtree.core.TestVolatileGeneration.java

@Override
public void setUp() throws Exception {
    tmpDir = File.createTempFile("tmp", "", new File("."));
    tmpDir.delete();//from   www .j a v a  2  s  .  c om
    tmpDir.mkdirs();
}

From source file:org.jboss.as.test.manualmode.mgmt.elytron.HttpMgmtInterfaceElytronAuthenticationTestCase.java

public static void prepareServerConfiguration() throws Exception {
    tempFolder = File.createTempFile(
            "ely-" + HttpMgmtInterfaceElytronAuthenticationTestCase.class.getSimpleName(), "", null);
    if (tempFolder.exists()) {
        tempFolder.delete();//from   ww w  .j av  a2  s . com
        tempFolder.mkdir();
    }
    String fsRealmPath = tempFolder.getAbsolutePath() + File.separator + "fs-realm-users";

    try (CLIWrapper cli = new CLIWrapper(true)) {
        final String levelStr = "";
        final List<String> roles = new ArrayList<>();

        cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:add(path=\"%s\", %s)",
                MANAGEMENT_FILESYSTEM_NAME, escapePath(fsRealmPath), levelStr));
        cli.sendLine(String.format("/subsystem=elytron/filesystem-realm=%s:add-identity(identity=%s)",
                MANAGEMENT_FILESYSTEM_NAME, USER));
        cli.sendLine(String.format(
                "/subsystem=elytron/filesystem-realm=%s:set-password(identity=%s, clear={password=\"%s\"})",
                MANAGEMENT_FILESYSTEM_NAME, USER, CORRECT_PASSWORD));
        if (!roles.isEmpty()) {
            cli.sendLine(String.format(
                    "/subsystem=elytron/filesystem-realm=%s:add-identity-attribute=%s:add-attribute(name=groups, value=[%s])",
                    MANAGEMENT_FILESYSTEM_NAME, USER, String.join(",", roles)));
        }

        cli.sendLine(String.format(
                "/subsystem=elytron/security-domain=%1$s:add(realms=[{realm=%1$s,role-decoder=groups-to-roles},{realm=local,role-mapper=super-user-mapper}],default-realm=%1$s,permission-mapper=default-permission-mapper)",
                MANAGEMENT_FILESYSTEM_NAME));
        cli.sendLine(String.format(
                "/subsystem=elytron/http-authentication-factory=%1$s:add(http-server-mechanism-factory=%2$s,security-domain=%1$s,"
                        + "mechanism-configurations=[{mechanism-name=BASIC,mechanism-realm-configurations=[{realm-name=\"%1$s\"}]}])",
                MANAGEMENT_FILESYSTEM_NAME, PREDEFINED_HTTP_SERVER_MECHANISM_FACTORY));
        cli.sendLine(String.format(
                "/core-service=management/management-interface=http-interface:write-attribute(name=http-authentication-factory,value=%s)",
                MANAGEMENT_FILESYSTEM_NAME));
        cli.sendLine("reload");
    }
}

From source file:com.tecapro.inventory.common.util.FileTempUtil.java

public OutputStream write(String name, int index) {

    try {// w w w . ja  v  a 2s. com
        File writeFile = File.createTempFile("TMP", "", new File(getBaseDir()));
        setTempName(name, writeFile.getName(), index);

        return new FileOutputStream(new File(getBaseDir(), writeFile.getName()));
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }

}

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

/**
 * {@inheritDoc}// w ww  .  j a va  2  s .  co m
 * 
 * @throws StorageServiceException
 */

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

    Document document = new Document();
    document.setUniversalResourceLocator(outputFile.getAbsolutePath());
    return document;
}

From source file:com.indeed.lsmtree.recordlog.TestRecordLogDirectoryQuickly.java

@Override
public void setUp() throws Exception {
    dir = File.createTempFile("tmp", "", new File("."));
    dir.delete();/* w  w w . j av  a  2s . c o  m*/
    dir.mkdirs();

}