List of usage examples for java.io File deleteOnExit
public void deleteOnExit()
From source file:com.adobe.ac.pmd.engines.AbstractFlexPmdEngine.java
private static File extractDefaultRuleSet() throws URISyntaxException, IOException { final String rulesetURI = "/com/adobe/ac/pmd/default_flex.xml"; final InputStream resourceAsStream = AbstractFlexPmdEngine.class.getResourceAsStream(rulesetURI); final File temporaryRuleset = File.createTempFile("default_flex", ".xml"); temporaryRuleset.deleteOnExit(); final FileOutputStream writter = new FileOutputStream(temporaryRuleset); IOUtil.copy(resourceAsStream, writter); resourceAsStream.close();/*from w w w . jav a 2 s .c om*/ return temporaryRuleset; }
From source file:com.fun.util.TesseractUtil.java
/** * /*from w w w . j a v a 2 s . c o m*/ * * @param imageFile * @param enlargeTimes * @param isEnlarge * @return * @throws IOException */ public static String recognize(File imageFile, int enlargeTimes, boolean isEnlarge) throws IOException { // 3??? File tmpScaledImage = File.createTempFile("tesseract-ocr-scaled", null); tmpScaledImage.deleteOnExit(); if (isEnlarge) scaled(imageFile, enlargeTimes, tmpScaledImage); // File tmpOutputBase = new File(tmpScaledImage.getAbsolutePath() + ".out"); File tmpOutputText = new File(tmpScaledImage.getAbsolutePath() + ".out.txt"); try { int exitCode = Runtime.getRuntime().exec(new String[] { "tesseract", // command tmpScaledImage.getAbsolutePath(), // imagename tmpOutputBase.getAbsolutePath(), // outputbase "-psm", "8", // pagesegmode, treat the image as a single word }).waitFor(); tmpScaledImage.delete(); // } catch (Exception e) { e.printStackTrace(); } // ? String text = Files.readFirstLine(tmpOutputText, Charsets.UTF_8); tmpOutputText.delete(); // if (StringUtils.isNotBlank(text)) { return text.trim().replaceAll("\\s|,", ""); } tmpOutputBase.delete(); return StringUtils.EMPTY; }
From source file:com.milaboratory.core.io.sequence.fasta.FastaReaderTest.java
private static TestItem createTestData(long seed, int readsCount, boolean withWildcards) throws IOException { Well1024a rnd = new Well1024a(seed); File tempFile = File.createTempFile("temp" + seed, ".fasta"); tempFile.deleteOnExit(); FileOutputStream output = new FileOutputStream(tempFile); SingleRead[] reads = new SingleRead[readsCount]; WildcardSymbol[] wildcards = NucleotideSequence.ALPHABET.getAllWildcards().toArray(new WildcardSymbol[0]); long id = 0;//from www .ja v a 2s .c om for (int i = 0; i < readsCount; ++i) { char[] seq = new char[50 + rnd.nextInt(100)]; char[] seqExp = new char[seq.length]; int qPointer = 0; byte[] qualityData = new byte[seq.length]; Arrays.fill(qualityData, SequenceQuality.GOOD_QUALITY_VALUE); for (int j = 0; j < seq.length; ++j) { seq[j] = seqExp[j] = NucleotideSequence.ALPHABET.symbolFromCode((byte) rnd.nextInt(4)); if (j != 0 && j != seq.length - 1 && ((4 * j) % seq.length == 0) && rnd.nextBoolean()) { //next line for sequence seq[j] = seqExp[j] = '\n'; --qPointer; } else if (withWildcards && j % 5 == 0) {//wildcard WildcardSymbol wildcard = wildcards[rnd.nextInt(wildcards.length)]; if (NucleotideSequence.ALPHABET.codeFromSymbol(wildcard.getSymbol()) == -1) { seq[j] = wildcard.getSymbol(); seqExp[j] = NucleotideSequence.ALPHABET .symbolFromCode(wildcard.getUniformlyDistributedSymbol(id ^ (j + qPointer)));//as used in FastaReader#getSequenceWithQuality(..) qualityData[j + qPointer] = SequenceQuality.BAD_QUALITY_VALUE; } } } String description = ">seq" + i; String sequenceString = new String(seq); output.write(description.getBytes()); output.write('\n'); output.write(sequenceString.getBytes()); output.write('\n'); reads[i] = new SingleReadImpl(id, new NSequenceWithQuality(new NucleotideSequence(new String(seqExp).replace("\n", "")), new SequenceQuality(Arrays.copyOfRange(qualityData, 0, seq.length + qPointer))), description.substring(1)); ++id; } output.close(); return new TestItem(tempFile, reads); }
From source file:es.uvigo.ei.sing.laimages.core.entities.datasets.HorizontalElementDatasetTest.java
private final static File exportElementToTmpCSVFile(ElementData data, FileFormat format) throws IOException { File exportFile = File.createTempFile(data.getName(), ".csv"); exportFile.deleteOnExit(); dataset.toCSV(data, exportFile, new CSVFormat(format)); return exportFile; }
From source file:uk.ac.ebi.eva.test.utils.JobTestUtils.java
public static File createTempFile() throws IOException { File tempFile = File.createTempFile(EVA_PIPELINE_TEMP_PREFIX, EVA_PIPELINE_TEMP_POSTFIX); tempFile.deleteOnExit(); return tempFile; }
From source file:com.axelor.apps.base.service.imports.importer.Importer.java
private static File createDefaultWorkspace() { File file = Files.createTempDir(); file.deleteOnExit(); return file; }
From source file:Main.java
public static void deleteAndReport(File file) { if (file != null && file.exists()) { // remove garbage if (!file.delete()) { Log.w(t, file.getAbsolutePath() + " will be deleted upon exit."); file.deleteOnExit(); } else {/*from w ww . j av a2s. co m*/ Log.w(t, file.getAbsolutePath() + " has been deleted."); } } }
From source file:com.thoughtworks.go.helpers.FileSystemUtils.java
public static File createDirectory(String directoryName) { File directory = new File(getTestRootDir(), directoryName); deleteDirectory(directory);//from w w w . j a va 2s .co m directory.mkdir(); directory.deleteOnExit(); return directory; }
From source file:labr_client.ehealth.e_health_session_manager.java
private static void storeAndReload(String indentPwd, String hokPwd, String encPwd, SessionManager sessionmgmt) throws IOException, TechnicalConnectorException { SessionItem item = sessionmgmt.getSession(); Element originalAssertion = item.getSAMLToken().getAssertion(); String serializedToken = toXMLString(originalAssertion); File temp = new File("tempToken"); temp.deleteOnExit(); write(serializedToken.getBytes(), new FileOutputStream(temp)); sessionmgmt.unloadSession();/*from w w w. j a v a 2s . c o m*/ Element savedAssertion = toElement(IOUtils.toString(new FileReader(temp))); ConfigValidator config = getConfigValidator(); String hokKeystore = config.getProperty("sessionmanager.holderofkey.keystore"); String hokAlias = config.getProperty("sessionmanager.holderofkey.alias", "authentication"); SAMLToken token = SAMLTokenFactory.getInstance().createSamlToken(savedAssertion, new KeyStoreCredential(hokKeystore, hokAlias, hokPwd)); sessionmgmt.loadSession(token, hokPwd, encPwd); }
From source file:edu.unc.lib.dl.util.ZipFileUtil.java
/** * Create a temporary directory, unzip the contents of the given zip file to * it, and return the directory.//www . j a va2 s . c o m * * If anything goes wrong during this process, clean up the temporary * directory and throw an exception. */ public static File unzipToTemp(File zipFile) throws IOException { // get a temporary directory to work with File tempDir = File.createTempFile("ingest", null); tempDir.delete(); tempDir.mkdir(); tempDir.deleteOnExit(); log.info("Unzipping to temporary directory: " + tempDir.getPath()); try { unzip(new FileInputStream(zipFile), tempDir); return tempDir; } catch (IOException e) { // attempt cleanup, then re-throw org.apache.commons.io.FileUtils.deleteDirectory(tempDir); throw e; } }