List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:org.apache.whirr.util.integration.BlobCacheTest.java
private File createTemporaryFile(String content) throws IOException { File tempFile = File.createTempFile("whirr", ".txt"); tempFile.deleteOnExit(); Files.write(content, tempFile, Charset.defaultCharset()); return tempFile; }
From source file:eu.scape_project.archiventory.identifiers.DroidIdentification.java
/** * Constructor which initialises a given specified signature file * * @param sigFilePath//from ww w . j a va 2 s . c o m */ public DroidIdentification(Resource resource) throws IOException { try { InputStream is = resource.getInputStream(); File tmpFile = IOUtils.copyInputStreamToTempFile(is, "DroidSignatureFile", ".xml"); tmpFile.deleteOnExit(); bsi = new BinarySignatureIdentifier(); bsi.setSignatureFile(tmpFile.getAbsolutePath()); bsi.init(); } catch (SignatureParseException ex) { logger.error("Signature parse error", ex); } }
From source file:com.izforge.izpack.compiler.container.TestCompilationContainer.java
/** * Fills the container.// w ww. ja va2 s . c om * * @param container the underlying container * @throws ContainerException if initialisation fails, or the container has already been initialised */ @Override protected void fillContainer(MutablePicoContainer container) { super.fillContainer(container); deleteLock(); URL resource = getClass().getClassLoader().getResource(installFile); if (resource == null) { throw new IllegalStateException("Cannot find install file: " + installFile); } File file = FileUtil.convertUrlToFile(resource); baseDir = file.getParentFile(); if (targetDir == null) { targetDir = baseDir; } File out = new File(targetDir, "out" + Math.random() + ".jar"); out.deleteOnExit(); CompilerData data = new CompilerData(file.getAbsolutePath(), baseDir.getAbsolutePath(), out.getAbsolutePath(), false); container.addConfig("installFile", file.getAbsolutePath()); container.addComponent(CompilerData.class, data); container.addComponent(File.class, out); container.addAdapter(new JarFileProvider()); }
From source file:com.sldeditor.test.unit.tool.ysld.YSLDToolTest.java
/** * Gets the SLD/YSLD file./*from www .java2 s . c o m*/ * * @param testfile the testfile * @return the SLD data file */ private static SLDData getSLDDataFile(String testfile) { SLDData sldData = null; InputStream inputStream = YSLDToolTest.class.getResourceAsStream(testfile); if (inputStream == null) { Assert.assertNotNull("Failed to find test file : " + testfile, inputStream); } else { File f = null; try { String fileExtension = ExternalFilenames.getFileExtension(testfile); f = stream2file(inputStream, ExternalFilenames.addFileExtensionSeparator(fileExtension)); String sldContents = readFile(f.getAbsolutePath()); if (fileExtension.compareTo("ysld") == 0) { StyledLayerDescriptor sld = Ysld.parse(sldContents); // Convert YSLD to SLD string SLDWriterInterface sldWriter = SLDWriterFactory.createWriter(SLDOutputFormatEnum.SLD); sldContents = sldWriter.encodeSLD(sld); } sldData = new SLDData(new StyleWrapper(f.getName()), sldContents); sldData.setSLDFile(f); SelectedSymbol.getInstance().setSld(SLDUtils.createSLDFromString(sldData)); f.deleteOnExit(); } catch (IOException e1) { e1.printStackTrace(); } } return sldData; }
From source file:com.validation.manager.core.server.core.AttachmentServer.java
public File getAttachedFile(String dest) { File result; try {//from www . j a v a 2 s .co m result = new File(dest + File.separator + getFileName()); result.deleteOnExit(); FileUtils.writeByteArrayToFile(result, getFile()); } catch (IOException ex) { Exceptions.printStackTrace(ex); result = null; } return result; }
From source file:com.hortonworks.registries.schemaregistry.avro.LocalRegistryServerHATest.java
@Before public void startZooKeeper() throws Exception { testingServer = new TestingServer(true); URI configPath = Resources.getResource("schema-registry-test-ha.yaml").toURI(); String fileContent = IOUtils.toString(configPath, "UTF-8"); File registryConfigFile = File.createTempFile("ha-", ".yaml"); registryConfigFile.deleteOnExit(); try (FileWriter writer = new FileWriter(registryConfigFile)) { IOUtils.write(fileContent.replace("__zk_connect_url__", testingServer.getConnectString()), writer); }/*from w ww . java 2s . co m*/ List<LocalSchemaRegistryServer> schemaRegistryServers = new ArrayList<>(); for (int i = 1; i < 4; i++) { LocalSchemaRegistryServer server = new LocalSchemaRegistryServer(registryConfigFile.getAbsolutePath()); schemaRegistryServers.add(server); server.start(); } registryServers = Collections.unmodifiableList(schemaRegistryServers); }
From source file:net.lmxm.ute.executers.tasks.FileSystemDeleteTaskExecuterTest.java
/** * Test delete files directory contents. *///from w w w . j a v a 2s. c om @Test public void testDeleteFilesDirectoryContents() { try { final File directory = new File(TMP_DIR, "TESTDIRECTORY"); directory.deleteOnExit(); directory.mkdir(); final File file = new File(directory, "UTE.TEST"); file.deleteOnExit(); FileUtils.touch(file); assertTrue(file.exists()); final FileReference fileReference = new FileReference(); fileReference.setName("UTE.TEST"); final List<FileReference> files = new ArrayList<FileReference>(); files.add(fileReference); executer.deleteFiles(directory.getAbsolutePath(), files, STOP_ON_ERROR); assertFalse(file.exists()); } catch (final IOException e) { fail(); } }
From source file:com.cloudera.oryx.als.computation.iterate.row.RowStep.java
@Override protected MRPipeline createPipeline() throws IOException { IterationState iterationState = getIterationState(); String iterationKey = iterationState.getIterationKey(); boolean x = iterationState.isComputingX(); int lastIteration = iterationState.getIteration() - 1; Store store = Store.get();//from ww w .j a v a 2 s. c o m JobStepConfig config = getConfig(); String instanceDir = config.getInstanceDir(); int generationID = config.getGenerationID(); if (store.exists(Namespaces.getInstanceGenerationPrefix(instanceDir, generationID) + "X/", false)) { // Actually, looks like whole computation of X/Y finished -- just proceed return null; } // Take the opportunity to clean out iteration before last, if computing X if (x) { String lastLastIterationKey = Namespaces.getIterationsPrefix(instanceDir, generationID) + (lastIteration - 1) + '/'; if (store.exists(lastLastIterationKey, false)) { log.info("Deleting old iteration data from {}", lastLastIterationKey); store.recursiveDelete(lastLastIterationKey); } } String yKey; if (x) { yKey = Namespaces.getIterationsPrefix(instanceDir, generationID) + lastIteration + "/Y/"; } else { yKey = iterationKey + "X/"; } String xKey = iterationKey + (x ? "X/" : "Y/"); String tempKey = Namespaces.getTempPrefix(instanceDir, generationID); String rKey = tempKey + (x ? "userVectors/" : "itemVectors/"); if (!validOutputPath(xKey)) { return null; } MRPipeline p = createBasicPipeline(RowReduceFn.class); Configuration conf = p.getConfiguration(); conf.set(Y_KEY_KEY, yKey); String popularKey = tempKey + (x ? "popularItemsByUserPartition/" : "popularUsersByItemPartition/"); conf.set(POPULAR_KEY, popularKey); String testPrefix = Namespaces.getInstanceGenerationPrefix(instanceDir, generationID) + "test/"; conf.set(MAP_KEY, testPrefix); YState yState = new YState(ALSTypes.DENSE_ROW_MATRIX); // Shared Y-Matrix state GroupingOptions opts = groupingOptions(); PCollection<MatrixRow> matrix = PTables.asPTable(p.read(input(rKey, ALSTypes.SPARSE_ROW_MATRIX))) .groupByKey(opts).parallelDo("rowReduce", new RowReduceFn(yState), ALSTypes.DENSE_ROW_MATRIX) .write(output(xKey)); if (!x) { matrix.parallelDo("asPair", MatrixRow.AS_PAIR, Avros.tableOf(Avros.longs(), ALSTypes.FLOAT_ARRAY)) .parallelDo("convergenceSample", new ConvergenceSampleFn(yState), Avros.strings()) .write(compressedTextOutput(p.getConfiguration(), iterationKey + "Yconvergence")); } if (x && ConfigUtils.getDefaultConfig().getDouble("model.test-set-fraction") > 0.0 && store.exists(testPrefix, false)) { PCollection<Double> aps = matrix .parallelDo("asPair", MatrixRow.AS_PAIR, Avros.tableOf(Avros.longs(), ALSTypes.FLOAT_ARRAY)) .parallelDo("computeAP", new ComputeUserAPFn(yState), Avros.doubles()); Mean meanAveragePrecision = new Mean(); for (double ap : aps.materialize()) { meanAveragePrecision.increment(ap); } log.info("Mean average precision: {}", meanAveragePrecision.getResult()); File tempMAPFile = File.createTempFile("MAP", ".txt"); tempMAPFile.deleteOnExit(); Files.write(Double.toString(meanAveragePrecision.getResult()), tempMAPFile, StandardCharsets.UTF_8); store.upload(iterationKey + "MAP", tempMAPFile, false); IOUtils.delete(tempMAPFile); } return p; }
From source file:com.legstar.cob2xsd.Cob2XsdIOTest.java
/** * Check that the XML Schema produced has the correct encoding from a file * standpoint.//from w ww . j a va2s . c om */ @Test public void testFileOutputEncoding() { try { configProps.put(Cob2XsdConfig.XSD_ENCODING, "UTF-8"); configProps.put(Cob2XsdConfig.ADD_LEGSTAR_ANNOTATIONS, Boolean.toString(true)); Cob2XsdIO cob2xsd = new Cob2XsdIO(new Cob2XsdConfig(configProps)); File tempCobolFile = File.createTempFile("test", ".cob"); tempCobolFile.deleteOnExit(); FileUtils.write(tempCobolFile, " 01 A.\n 02 B PIC G(4) VALUE '?'.", "UTF8"); File xmlSchema = cob2xsd.translate(tempCobolFile, "UTF8", tempDir, "http://www.mycompany.com/test", null); for (String line : FileUtils.readLines(xmlSchema, "UTF8")) { if (line.contains("cobolName=\"B\"")) { assertTrue(line.contains("value=\"?\"")); } } xmlSchema.deleteOnExit(); } catch (Exception e) { e.printStackTrace(); fail(); } }
From source file:com.premiumminds.persistence.utils.HibernateEnversDDLTest.java
@Test public void testUpdateCommandWithoutFile() throws Exception { File file = File.createTempFile("updatedb", ".sql"); file.deleteOnExit(); String[] args = new String[] { "--update", "application-data-unit-export-test", "jdbc:h2:" + getClass().getResource("/foobar_versioned.mv.db").getFile().replace(".mv.db", ""), "foo", "bar" }; HibernateEnversDDL.main(args);/*from w w w. ja v a2 s. co m*/ assertEquals( "\n" + " alter table FooBar \n" + " add column bar integer not null;\n" + "\n" + " alter table FooBar_AUD \n" + " add column bar integer;\n", outContent.toString()); }