List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:de.tudarmstadt.ukp.dkpro.core.io.rtf.RTFReaderTest.java
/** * Test for reading multiple (two) files. * * @throws UIMAException//w w w .j av a 2s.c o m * @throws IOException */ @Test public void testTwoFiles() throws UIMAException, IOException { String testFiles = "src/test/resources/*.rtf"; File output = new File("target/output2.dump"); output.deleteOnExit(); File testDump = new File("src/test/resources/testfiles.dump"); CollectionReaderDescription reader = createReaderDescription(RTFReader.class, RTFReader.PARAM_SOURCE_LOCATION, testFiles, RTFReader.PARAM_LANGUAGE, "en"); AnalysisEngineDescription writer = createEngineDescription(CasDumpWriter.class, CasDumpWriter.PARAM_OUTPUT_FILE, output); SimplePipeline.runPipeline(reader, writer); assertEquals(FileUtils.readFileToString(testDump), FileUtils.readFileToString(output)); }
From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java
public void testTempClassLoader_getClass() throws Exception { File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile(); File jar = File.createTempFile("testTempClassLoader_getClass", ".jar"); jar.deleteOnExit(); FileUtils.copyFile(sourceJar, jar);/* w w w . j a v a 2 s .c o m*/ try { ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar); Class<?> klass = ClassLoaderUtils.loadClass("foo.bar.baz.JarType", cl); assertNotNull(klass); } finally { jar.delete(); } }
From source file:org.opencredo.cloud.storage.si.adapter.WritingMessageHandlerTest.java
@Test public void testSendFile() throws IOException { File payload = File.createTempFile("test_file_to_send", null); payload.deleteOnExit(); MessageBuilder<File> mb = MessageBuilder.withPayload(payload); boolean send = outputChannel.send(mb.build(), 3000); assertTrue("Message should be sent", send); verify(template).send(eq(TestPropertiesAccessor.getDefaultContainerName()), anyString(), eq(payload)); }
From source file:com.cloudera.kitten.TestKittenDistributedShell.java
@Test public void testKittenShell() throws Exception { String config = "lua/distshell.lua"; // For the outputs File tmpFile = File.createTempFile("distshell", ".txt"); tmpFile.deleteOnExit(); KittenClient client = new KittenClient(ImmutableMap.<String, Object>of("TEST_FILE", tmpFile.getAbsolutePath(), "PWD", (new File(".")).getAbsolutePath())); conf.set(LocalDataHelper.APP_BASE_DIR, "file:///tmp/"); client.setConf(conf);/*from w w w.j a v a2 s.c o m*/ assertEquals(0, client.run(new String[] { config, "distshell" })); assertEquals(12, Files.readLines(tmpFile, Charsets.UTF_8).size()); }
From source file:com.logsniffer.model.file.WildcardLogSourceTest.java
@Test public void testLogsResolving() throws IOException { File tmp = File.createTempFile("sdkj", "jk"); tmp.deleteOnExit(); File tmpFolder1 = new File(tmp.getPath() + "d", "f1"); tmpFolder1.mkdirs();/*from w w w. ja va 2 s . co m*/ tmpFolder1.deleteOnExit(); File tmpFolder2 = new File(tmp.getPath() + "d", "f2"); tmpFolder2.mkdirs(); tmpFolder2.deleteOnExit(); FileUtils.write(new File(tmpFolder1, "1.txt"), "txt"); FileUtils.write(new File(tmpFolder1, "2.txt"), "txt"); FileUtils.write(new File(tmpFolder1, "3.log"), "log"); FileUtils.write(new File(tmpFolder2, "22.txt"), "txt"); File tmpDir = new File(tmpFolder2, "folder.txt"); tmpDir.mkdir(); tmpDir.deleteOnExit(); // Check now WildcardLogsSource source = new WildcardLogsSource(); source.setPattern(tmp.getPath() + "d/*.txt"); Assert.assertEquals(0, source.getLogs().size()); source.setPattern(tmp.getPath() + "d/**/*.txt"); Log[] logs = source.getLogs().toArray(new Log[0]); Assert.assertEquals(3, logs.length); Arrays.sort(logs, new Comparator<Log>() { @Override public int compare(final Log o1, final Log o2) { return o1.getPath().compareTo(o2.getPath()); } }); Assert.assertTrue(logs[0].getPath().endsWith("1.txt")); Assert.assertTrue(logs[1].getPath().endsWith("2.txt")); Assert.assertTrue(logs[2].getPath().endsWith("22.txt")); }
From source file:com.wavemaker.common.util.ClassLoaderUtilsTest.java
public void testTempClassLoader_getResource() throws Exception { File sourceJar = new ClassPathResource("com/wavemaker/common/foojar.jar").getFile(); File jar = File.createTempFile("testTempClassLoader_getClass", ".jar"); jar.deleteOnExit(); FileUtils.copyFile(sourceJar, jar);/* www.ja v a2 s. com*/ try { ClassLoader cl = ClassLoaderUtils.getTempClassLoaderForFile(jar); InputStream is = ClassLoaderUtils.getResourceAsStream("foo/bar/baz/JarType.java", cl); assertNotNull(is); assertTrue(is.available() > 0); is.close(); } finally { jar.delete(); } }
From source file:com.cloudera.flume.handlers.avro.TestAvroDataFile.java
@Test public void testAvroDataFileWriteRead() throws IOException, FlumeSpecException, InterruptedException { MemorySinkSource mem = MemorySinkSource.cannedData("test ", 5); // setup sink. File f = File.createTempFile("avrodata", ".avro"); f.deleteOnExit(); LOG.info("filename before escaping: " + f.getAbsolutePath()); String custom = "text(\"" + StringEscapeUtils.escapeJava(f.getAbsolutePath()) + "\", \"avrodata\")"; LOG.info("sink to parse: " + custom); EventSink snk = FlumeBuilder.buildSink(new Context(), custom); snk.open();/*from w w w.j a v a 2s . co m*/ mem.open(); EventUtil.dumpAll(mem, snk); snk.close(); mem.open(); DatumReader<EventImpl> dtm = new ReflectDatumReader<EventImpl>(EventImpl.class); DataFileReader<EventImpl> dr = new DataFileReader<EventImpl>(f, dtm); EventImpl eout = null; for (Object o : dr) { eout = (EventImpl) o; // TODO (jon) fix AVRO -- this is gross Event expected = mem.next(); Assert.assertTrue(Arrays.equals(eout.getBody(), expected.getBody())); } }
From source file:com.linkedin.pinot.core.indexsegment.utils.MmapMemoryManagerFileCleanupTest.java
@BeforeClass public void setUp() { _tmpDir = System.getProperty("java.io.tmpdir") + "/" + MmapMemoryManagerTest.class.getSimpleName(); File dir = new File(_tmpDir); FileUtils.deleteQuietly(dir);//from w ww.j a v a 2 s . com dir.mkdir(); dir.deleteOnExit(); }
From source file:edu.umn.msi.tropix.proteomics.test.InstrumentsTest.java
public void testInstruments(final boolean fromFile) throws IOException { Instruments instruments;/* www . j a va 2 s. c om*/ if (fromFile) { final File tempFile = File.createTempFile("tpxtest", ""); tempFile.deleteOnExit(); final FileOutputStream stream = new FileOutputStream(tempFile); IOUtils.copy(getClass().getResourceAsStream("instruments.csv"), stream); instruments = new Instruments(tempFile.getAbsolutePath()); } else { instruments = new Instruments(ProteomicsTests.getResourceAsStream("instruments.csv")); } assert instruments.ionUsed("Default", "1+ fragments") != null : "Null check 1"; assert instruments.ionUsed("Default", "w or w' series ions") != null : "Null check 2"; assert instruments.ionUsed("MALDI QIT TOF", "1+ fragments") != null : "Null check 3"; assert instruments.ionUsed("MALDI QIT TOF", "w or w' series ions") != null : "Null check 4"; assert instruments.ionUsed("ETD TRAP", "c series ions") != null : "Null check 5"; assert instruments.ionUsed("Default", "c series ions") != null : "Null check 6"; assert instruments.ionUsed("MALDI QUAD TOF", "c series ions") != null : "Null check 7"; assert instruments.ionUsed("NOT AN INSTRUMENT", "NOT AN ION SERIES") == null; assert instruments.ionUsed("Default", "1+ fragments") : "Check 1"; assert !instruments.ionUsed("Default", "w or w' series ions") : "Check 2"; assert instruments.ionUsed("MALDI QIT TOF", "1+ fragments") : "Check 3"; assert !instruments.ionUsed("MALDI QIT TOF", "w or w' series ions") : "Check 4"; assert instruments.ionUsed("ETD TRAP", "c series ions") : "Check 5"; assert !instruments.ionUsed("Default", "c series ions") : "Check 6"; assert !instruments.ionUsed("MALDI QUAD TOF", "c series ions") : "Check 7"; }
From source file:com.mirth.connect.plugins.pdfviewer.PDFViewer.java
public void viewAttachments(String channelId, Long messageId, String attachmentId) { try {/*w w w .java 2s. co m*/ Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId); byte[] rawData = attachment.getContent(); Base64InputStream in = new Base64InputStream(new ByteArrayInputStream(rawData)); File temp = File.createTempFile(attachment.getId(), ".pdf"); temp.deleteOnExit(); OutputStream out = new FileOutputStream(temp); IOUtils.copy(in, out); out.close(); new MirthPDFViewer(true, temp); } catch (Exception e) { parent.alertThrowable(parent, e); } }