List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:MockFedoraIT.java
@SuppressWarnings("unused") private File getJunkFile(int kbytes) { File junk = null;//from www . j a v a2 s . co m try { junk = File.createTempFile("test", "junk"); try (OutputStream out = new FileOutputStream(junk)) { byte[] buffer = new byte[4096]; for (int i = 0; i < buffer.length; i++) { buffer[i] = 'C'; } for (int i = 0; i * 4 < kbytes; i++) { out.write(buffer); } } } catch (IOException e) { e.printStackTrace(); } LOG.debug("junk file created"); return junk; }
From source file:com.whizzosoftware.hobson.scheduler.ical.ICalTaskProviderTest.java
@Test public void testEmptyCalendarFile() throws Exception { File sfile = File.createTempFile("hobsonschedule", ".ics"); sfile.delete();//from w w w .ja v a2 s .c om try { ICalTaskProvider scheduler = new ICalTaskProvider("pluginId", null, null); scheduler.setScheduleExecutor(new MockScheduledTaskExecutor()); scheduler.setScheduleFile(sfile); } finally { sfile.delete(); } }
From source file:io.neba.core.mvc.SlingMultipartFileTest.java
@Test public void testTransferToFile() throws Exception { withMultipartFileContents("Junit Test"); withDestinationFile(File.createTempFile("junt-test", ".tmp")); transferMultipartFileToDestinationFile(); assertDestinationFileContentIsMultiPartContent(); }
From source file:com.stratio.ingestion.sink.cassandra.CassandraSinkIT.java
private void _do() throws TTransportException, IOException, InterruptedException { final Context context = new Context(); final InetSocketAddress contactPoint = CassandraTestHelper.getCassandraContactPoint(); context.put("tables", "keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT"); context.put("hosts", contactPoint.getAddress().getHostAddress()); context.put("batchSize", "1"); context.put("consistency", "QUORUM"); final File cqlFile = File.createTempFile("flumeTest", "cql"); cqlFile.deleteOnExit();//from w w w . j a v a 2 s . c o m IOUtils.write( "CREATE KEYSPACE IF NOT EXISTS keyspaceTestCassandraSinkIT WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };\n\n" + "CREATE TABLE IF NOT EXISTS keyspaceTestCassandraSinkIT.tableTestCassandraSinkIT (" + "id uuid, bool_field boolean, int_field int, PRIMARY KEY (int_field)" + ");\n\n", new FileOutputStream(cqlFile)); context.put("cqlFile", cqlFile.getAbsolutePath()); sink = new CassandraSink(); sink.configure(context); Context channelContext = new Context(); channelContext.put("capacity", "10000"); channelContext.put("transactionCapacity", "200"); channel = new MemoryChannel(); channel.setName("junitChannel"); Configurables.configure(channel, channelContext); sink.setChannel(channel); sink.start(); sink.stop(); }
From source file:com.cloud.utils.PropertiesUtilsTest.java
@Test public void processConfigFile() throws IOException { File tempFile = File.createTempFile("temp", ".properties"); FileUtils.writeStringToFile(tempFile, "a=b\nc=d\n"); Map<String, String> config = PropertiesUtil.processConfigFile(new String[] { tempFile.getAbsolutePath() }); Assert.assertEquals("b", config.get("a")); Assert.assertEquals("d", config.get("c")); tempFile.delete();// w w w .j av a 2s.c om }
From source file:cx.jbzdak.diesIrae.genieConnector.ParamTest.java
@Before public void startup() throws Exception { connector = new SimpleConnector(); File f = new File("C:\\GENIE2K\\CAMFILES\\NBSSTD.CNF"); File temp = File.createTempFile("gcTest", "CNF"); temp.deleteOnExit();//from w w w .j a va2s. co m FileUtils.copyFile(f, temp); connector.setFlush(FlushType.AUTO_COMMIT); connector.openFile(temp, EnumSet.of(OpenMode.READ_WRITE, OpenMode.SYSTEM_WRITE, OpenMode.EXCLUSIVE, OpenMode.TAKE_CONTROL, OpenMode.TAKE_OVER)); //connector.openSource("DET_1", EnumSet.of(OpenMode.READ_WRITE, OpenMode.SYSTEM_WRITE, OpenMode.EXCLUSIVE), SourceType.DETECTOR); }
From source file:edu.harvard.med.screensaver.ui.arch.searchresults.CsvDataExporter.java
@Override public InputStream export(Iterator<T> iter) throws IOException { assert _columns != null : "must call setTableColumns() first"; CSVPrintWriter csvWriter = null;//from ww w. j av a 2 s .c om try { File file = File.createTempFile("screensaver", "csv"); Writer writer = new BufferedWriter(new FileWriter(file)); csvWriter = new CSVPrintWriter(writer, "\n"); writeFile(csvWriter, iter); csvWriter.close(); return new BufferedInputStream(new FileInputStream(file)); } catch (Exception e) { if (e instanceof IOException) { throw (IOException) e; } throw new DevelopmentException(e.getMessage()); } finally { if (csvWriter != null) { IOUtils.closeQuietly(csvWriter); } } }
From source file:de.hpi.fgis.hdrs.node.Index.java
/** * Create an index in the temp directory. * Used for testing.// ww w . ja v a2s . com * @throws IOException */ public static Index createTmpIndex(Triple.COLLATION order) throws IOException { File root = File.createTempFile("hdrs_index_root", ""); if (!root.delete()) { throw new IOException("Couldn't create tmp directory."); } Index index = createIndex(root, order, new SegmentIdGenerator() { private long id = 0; @Override public synchronized long generateSegmentId() { return ++id; } }); // create initial segment index.createSeedSegment(); return index; }
From source file:com.adaptris.core.fs.CompositeFileFilterTest.java
@Test public void testFilterMatches() throws Exception { File src = File.createTempFile(this.getClass().getSimpleName(), ".xml"); write(2048, src);//from w w w. j a v a 2 s . c o m CompositeFileFilter df = new CompositeFileFilter(FILTER_SIZE, true); boolean accepted = df.accept(src); String text = src + ", size=" + src.length() + " should match"; src.delete(); assertTrue(text, accepted); }
From source file:edu.umn.msi.tropix.proteomics.test.CreateMzXML.java
@Test(groups = { "create" }) public void createMzXML() throws Exception { final DTAToMzXMLConverterImpl converter = new DTAToMzXMLConverterImpl(); final InMemoryDTAListImpl dtaList = new InMemoryDTAListImpl(); final String[] dtaNames = new String[] { "mrr.103.106.1.dta", "mrr.1105.1106.2.dta", "mrr.1105.1106.3.dta", "mrr.2025.2026.2.dta", "mrr.2025.2026.3.dta", "mrr.3009.3011.1.dta" }; for (final String dtaName : dtaNames) { final InputStream dtaStream = ProteomicsTests.getResourceAsStream(dtaName); dtaList.add(IOUtils.toByteArray(dtaStream), dtaName); }/* w w w . jav a 2 s. c o m*/ final MzXML mzxml = converter.dtaToMzXML(dtaList, null); final MzXMLUtility mzxmlUtility = new MzXMLUtility(); mzxmlUtility.serialize(mzxml, File.createTempFile("valid", "mzxml")); System.out.println(mzxmlUtility.toString(mzxml)); }