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:de.hska.ld.core.config.LDLoggerConfig.java

@Autowired
private void init() throws IOException {
    File f = File.createTempFile("tinylog_conf", ".txt");
    FileOutputStream fos = new FileOutputStream(f);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
    try {//from w w w. j av a  2 s. co m
        String writer = env.getProperty("tinylog.writer");
        bw.write("tinylog.writer = " + writer);
        bw.newLine();
        /*String fileName = env.getProperty("tinylog.writer.filename");
        bw.write("tinylog.writer.filename = " + fileName);
        bw.newLine();
        String buffered = env.getProperty("tinylog.writer.buffered");
        bw.write("tinylog.writer.buffered = " + buffered);
        bw.newLine();
        String append = env.getProperty("tinylog.writer.append");
        bw.write("tinylog.writer.append = " + append);
        bw.newLine();*/
        String level = env.getProperty("tinylog.level");
        bw.write("tinylog.level = " + level);
        bw.newLine();
        String writerUrl = env.getProperty("tinylog.writer.url");
        bw.write("tinylog.writer.url = " + writerUrl);
        bw.newLine();
        String writerTable = env.getProperty("tinylog.writer.table");
        bw.write("tinylog.writer.table = " + writerTable);
        bw.newLine();
        String writerColumns = env.getProperty("tinylog.writer.columns");
        bw.write("tinylog.writer.columns = " + writerColumns);
        bw.newLine();
        String writerValues = env.getProperty("tinylog.writer.values");
        bw.write("tinylog.writer.values = " + writerValues);
        bw.newLine();
        String writerBatch = env.getProperty("tinylog.writer.batch");
        bw.write("tinylog.writer.batch = " + writerBatch);
        bw.newLine();
        String writerUsername = env.getProperty("tinylog.writer.username");
        bw.write("tinylog.writer.username = " + writerUsername);
        bw.newLine();
        String writerPassword = env.getProperty("tinylog.writer.password");
        bw.write("tinylog.writer.password = " + writerPassword);
        bw.newLine();
        String writingThread = env.getProperty("tinylog.writingthread");
        bw.write("tinylog.writingthread = " + writingThread);
        bw.newLine();
        String wTObserve = env.getProperty("tinylog.writingthread.observe");
        bw.write("tinylog.writingthread.observe = " + wTObserve);
        bw.newLine();
        String wTPriority = env.getProperty("tinylog.writingthread.priority");
        bw.write("writingthread.priority = " + wTPriority);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        bw.close();
    }
    Configurator.fromFile(f).activate();
}

From source file:com.tango.BucketSyncer.S32GCSTestFile.java

public S32GCSTestFile() throws Exception {
    file = File.createTempFile(getClass().getName(), ".tmp");
    data = S32GCSMirrorTest.random(TEST_FILE_SIZE + (RandomUtils.nextInt() % 1024));
    @Cleanup/*from   w  w  w  .ja v  a2s . c  o  m*/
    FileOutputStream out = new FileOutputStream(file);
    IOUtils.copy(new ByteArrayInputStream(data.getBytes()), out);
    file.deleteOnExit();
}

From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.storage.FileSystemStorage.java

public FileSystemStorage() {
    try {/*from ww w  .ja v a  2  s .com*/
        storage = File.createTempFile(TEMP_FILE_PREFIX, null);
    } catch (IOException ex) {
        throw new RuntimeException("cannot create temporary file", ex);
    }
    storage.deleteOnExit();
}

From source file:de.tudarmstadt.ukp.dkpro.core.lbj.IllinoisPosTaggerTest.java

@Test
public void testEnglishNative() throws Exception {
    File tempFile = File.createTempFile("dkpro", ".txt");
    FileUtils.write(tempFile, "This is a test .");
    POSTagPlain.main(new String[] { tempFile.getAbsolutePath() });
}

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

@Before
public void setUp() throws IOException {
    catalinaBaseDir = new File(new File(System.getProperty("java.io.tmpdir")), "catalinaBase_" + (++counter));
    catalinaBaseDir.mkdirs();//from w  w  w  . java 2  s.c om

    source = File.createTempFile("source", ".tmp");
    source.deleteOnExit();
    target = File.createTempFile("target", ".tmp");
    target.deleteOnExit();
    FileWriter sourceWriter = new FileWriter(source);
    sourceWriter.write(MESSAGE);
    sourceWriter.close();
}

From source file:eu.creatingfuture.propeller.webLoader.propeller.OpenSpin.java

/**
 * https://code.google.com/p/open-source-spin-compiler/wiki/CommandLine
 *
 * @param executable//from   w  ww.  j a va  2s .c  om
 * @param sourceFile
 * @return
 */
protected boolean compile(String executable, File sourceFile) {
    try {
        File temporaryDestinationFile = File.createTempFile("blocklyapp", ".binary");
        File libDirectory = new File(new File(System.getProperty("user.dir")), "/propeller-lib");
        Map map = new HashMap();
        map.put("sourceFile", sourceFile);
        map.put("destinationFile", temporaryDestinationFile);
        map.put("libDirectory", libDirectory);

        CommandLine cmdLine = new CommandLine(executable);
        cmdLine.addArgument("-o").addArgument("${destinationFile}");
        cmdLine.addArgument("-L").addArgument("${libDirectory}");
        cmdLine.addArgument("${sourceFile}");
        cmdLine.setSubstitutionMap(map);
        DefaultExecutor executor = new DefaultExecutor();
        //  executor.setExitValues(new int[]{402, 101});

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
        executor.setStreamHandler(streamHandler);

        try {
            exitValue = executor.execute(cmdLine);
        } catch (ExecuteException ee) {
            exitValue = ee.getExitValue();
            logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue);
            success = false;
            return false;
        } finally {
            temporaryDestinationFile.delete();
            output = outputStream.toString();
        }

        //            System.out.println("output: " + output);
        /*
         Scanner scanner = new Scanner(output);
                
                
         Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?");
         Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$");
         while (scanner.hasNextLine()) {
         String portLine = scanner.nextLine();
         if (chipFoundPattern.matcher(portLine).matches()) {
         Matcher portMatch = pattern.matcher(portLine);
         if (portMatch.find()) {
         //   String port = portMatch.group("comport");
                
         }
         }
         }
         */
        //            System.out.println("output: " + output);
        //            System.out.println("exitValue: " + exitValue);
        success = true;
        return true;
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, null, ioe);
        success = false;
        return false;
    }
}

From source file:io.druid.segment.EmptyIndexTest.java

@Test
public void testEmptyIndex() throws Exception {
    File tmpDir = File.createTempFile("emptyIndex", "");
    if (!tmpDir.delete()) {
        throw new IllegalStateException("tmp delete failed");
    }/*from   w w w. j a  va  2s  .c o  m*/
    if (!tmpDir.mkdir()) {
        throw new IllegalStateException("tmp mkdir failed");
    }

    try {
        IncrementalIndex emptyIndex = new IncrementalIndex.Builder().setSimpleTestingIndexSchema(/* empty */)
                .setMaxRowCount(1000).buildOnheap();

        IncrementalIndexAdapter emptyIndexAdapter = new IncrementalIndexAdapter(Intervals.of("2012-08-01/P3D"),
                emptyIndex, new ConciseBitmapFactory());
        TestHelper.getTestIndexMergerV9().merge(Lists.<IndexableAdapter>newArrayList(emptyIndexAdapter), true,
                new AggregatorFactory[0], tmpDir, new IndexSpec());

        QueryableIndex emptyQueryableIndex = TestHelper.getTestIndexIO().loadIndex(tmpDir);

        Assert.assertEquals("getDimensionNames", 0,
                Iterables.size(emptyQueryableIndex.getAvailableDimensions()));
        Assert.assertEquals("getMetricNames", 0, Iterables.size(emptyQueryableIndex.getColumnNames()));
        Assert.assertEquals("getDataInterval", Intervals.of("2012-08-01/P3D"),
                emptyQueryableIndex.getDataInterval());
        Assert.assertEquals("getReadOnlyTimestamps", 0,
                emptyQueryableIndex.getColumn(Column.TIME_COLUMN_NAME).getLength());
    } finally {
        FileUtils.deleteDirectory(tmpDir);
    }
}

From source file:com.strandls.alchemy.rest.client.stubgenerator.GuiceModuleGeneratorTest.java

/**
 * Test method for//from   w  w  w . j av a 2 s  .c o m
 * {@link com.strandls.alchemy.rest.client.stubgenerator.GuiceModuleGenerator#generateGuiceModule(java.lang.String, java.io.File, java.util.Map)}
 * .
 *
 * @throws Exception
 */
@Test
public void testGenerateModuleWithPackage() throws Exception {
    final GuiceModuleGenerator generator = new GuiceModuleGenerator();
    final File tempDir = File.createTempFile("test", "test");
    FileUtils.deleteQuietly(tempDir);

    if (!tempDir.mkdirs()) {
        throw new IOException("Cannot create temporary directory.");
    }
    try {
        final Map<String, String> map = new LinkedHashMap<String, String>();
        map.put("testStub1", "testStub1Proxy");
        map.put("testStub2", "testStub2Proxy");
        generator.generateGuiceModule("com.strandls.alchemy", tempDir, map);

        String actualGuiceStub = FileUtils
                .readFileToString(new File(tempDir, GuiceModuleGenerator.CLIENT_GUICE_MODULE_NAME + ".java"))
                .trim();
        assertEquals(
                FileUtils
                        .readFileToString(
                                new File("src/test/resources/com/strandls/alchemy/rest/client/stubgenerator/"
                                        + GuiceModuleGenerator.CLIENT_GUICE_MODULE_NAME + "WithPackage.txt"))
                        .trim(),
                actualGuiceStub);
    } finally {
        FileUtils.deleteQuietly(tempDir);
    }
}

From source file:edu.umn.msi.tropix.common.test.FileDisposableResourceImplTest.java

@Test(groups = "unit", timeOut = 1000)
public void dispose() throws IOException {
    final File tempFile = File.createTempFile("tpxtest", "");
    FileUtils.touch(tempFile);/*from  ww  w  .  j  a  va  2  s .  c om*/
    assert tempFile.exists();

    final FileDisposableResourceImpl resource = new FileDisposableResourceImpl(tempFile);

    assert resource.getFile().equals(tempFile);
    resource.dispose();
    assert !tempFile.exists();
}

From source file:eu.creatingfuture.propeller.blocklyprop.propeller.OpenSpin.java

/**
 * https://code.google.com/p/open-source-spin-compiler/wiki/CommandLine
 *
 * @param executable// ww  w .j  a va2s .c om
 * @param sourceFile
 * @return
 */
protected boolean compile(String executable, File sourceFile) {
    try {
        File temporaryDestinationFile = File.createTempFile("blocklyapp", ".binary");
        File libDirectory = new File(new File(System.getProperty("user.dir")), "/propeller-lib");
        Map map = new HashMap();
        map.put("sourceFile", sourceFile);
        map.put("destinationFile", temporaryDestinationFile);
        map.put("libDirectory", libDirectory);

        CommandLine cmdLine = new CommandLine(executable);
        cmdLine.addArgument("-o").addArgument("${destinationFile}");
        cmdLine.addArgument("-L").addArgument("${libDirectory}");
        cmdLine.addArgument("${sourceFile}");
        cmdLine.setSubstitutionMap(map);
        DefaultExecutor executor = new DefaultExecutor();
        executor.setExitValues(new int[] { 0, 1 });

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
        executor.setStreamHandler(streamHandler);

        try {
            exitValue = executor.execute(cmdLine);
        } catch (ExecuteException ee) {
            exitValue = ee.getExitValue();
            logger.log(Level.SEVERE, "Unexpected exit value: {0}", exitValue);
            success = false;
            return false;
        } finally {
            temporaryDestinationFile.delete();
            output = outputStream.toString();
        }

        //            System.out.println("output: " + output);
        /*
         Scanner scanner = new Scanner(output);
                
                
         Pattern chipFoundPattern = Pattern.compile(".*?(EVT:505).*?");
         Pattern pattern = Pattern.compile(".*?found on (?<comport>[a-zA-Z0-9]*).$");
         while (scanner.hasNextLine()) {
         String portLine = scanner.nextLine();
         if (chipFoundPattern.matcher(portLine).matches()) {
         Matcher portMatch = pattern.matcher(portLine);
         if (portMatch.find()) {
         //   String port = portMatch.group("comport");
                
         }
         }
         }
         */
        //            System.out.println("output: " + output);
        //            System.out.println("exitValue: " + exitValue);
        success = true;
        return true;
    } catch (IOException ioe) {
        logger.log(Level.SEVERE, null, ioe);
        success = false;
        return false;
    }
}