List of usage examples for java.io File createTempFile
public static File createTempFile(String prefix, String suffix) throws IOException
From source file:de.pdark.dsmp.ProxyDownloadTest.java
@Test @Ignore// ww w .ja va2 s . c o m public void testDownload() throws Exception { URL url = new URL("http://repo1.maven.org/maven2/org/apache/commons/commons-parent/1/commons-parent-1.pom"); File f = File.createTempFile("zz", "commons-parent-1.pom"); ProxyDownload d = new ProxyDownload(url, f, config); d.download(); assertEquals(7616, f.length()); }
From source file:com.baasbox.db.async.ExportJob.java
@Override public void run() { FileOutputStream dest = null; ZipOutputStream zip = null;/* w ww.j a v a2 s . co m*/ FileOutputStream tempJsonOS = null; FileInputStream in = null; try { //File f = new File(this.fileName); File f = File.createTempFile("export", ".temp"); dest = new FileOutputStream(f); zip = new ZipOutputStream(dest); File tmpJson = File.createTempFile("export", ".json"); tempJsonOS = new FileOutputStream(tmpJson); DbHelper.exportData(this.appcode, tempJsonOS); BaasBoxLogger.info(String.format("Writing %d bytes ", tmpJson.length())); tempJsonOS.close(); ZipEntry entry = new ZipEntry("export.json"); zip.putNextEntry(entry); in = new FileInputStream(tmpJson); final int BUFFER = BBConfiguration.getImportExportBufferSize(); byte buffer[] = new byte[BUFFER]; int length; while ((length = in.read(buffer)) > 0) { zip.write(buffer, 0, length); } zip.closeEntry(); in.close(); File manifest = File.createTempFile("manifest", ".txt"); FileUtils.writeStringToFile(manifest, BBInternalConstants.IMPORT_MANIFEST_VERSION_PREFIX + BBConfiguration.getApiVersion()); ZipEntry entryManifest = new ZipEntry("manifest.txt"); zip.putNextEntry(entryManifest); zip.write(FileUtils.readFileToByteArray(manifest)); zip.closeEntry(); tmpJson.delete(); manifest.delete(); File finaldestination = new File(this.fileName); FileUtils.moveFile(f, finaldestination); } catch (Exception e) { BaasBoxLogger.error(ExceptionUtils.getMessage(e)); } finally { try { if (zip != null) zip.close(); if (dest != null) dest.close(); if (tempJsonOS != null) tempJsonOS.close(); if (in != null) in.close(); } catch (Exception ioe) { BaasBoxLogger.error(ExceptionUtils.getMessage(ioe)); } } }
From source file:eu.scape_project.tool.toolwrapper.data.components_spec.utils.Utils.java
/** * Method that creates a {@link Components} instance from the provided * component spec file, validating it against component spec XML Schema * // w w w. j ava 2 s . co m * @param componentSpecFilePath * path to the component spec file */ public static Components createComponents(String componentSpecFilePath) { Components component = null; File schemaFile = null; try { JAXBContext context = JAXBContext.newInstance(Components.class); Unmarshaller unmarshaller = context.createUnmarshaller(); // copy XML Schema from resources to a temporary location schemaFile = File.createTempFile("schema", null); FileUtils.copyInputStreamToFile(Utils.class.getResourceAsStream(COMPONENTS_SPEC_FILENAME_IN_RESOURCES), schemaFile); Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile); // validate provided toolspec against XML Schema unmarshaller.setSchema(schema); // unmarshal it final FileInputStream stream = new FileInputStream(new File(componentSpecFilePath)); try { component = unmarshaller.unmarshal(new StreamSource(stream), Components.class).getValue(); } finally { stream.close(); } } catch (JAXBException e) { log.error("The component spec provided doesn't validate against its schema!", e); } catch (SAXException e) { log.error("The XML Schema is not valid!", e); } catch (IOException e) { log.error("An error occured while copying the XML Schema from the resources to a temporary location!", e); } catch (Exception e) { log.error("An error occured!", e); } finally { if (schemaFile != null) { schemaFile.deleteOnExit(); } } return component; }
From source file:de.tudarmstadt.ukp.dkpro.discourse.pdtbparser.PDTBParserWrapper.java
public PDTBParserWrapper() throws IOException { tempDirectory = Files.createTempDirectory("temp_pdtb"); // FileUtils.copyFileToDirectory(); File tempDir = tempDirectory.toFile(); File tmpFile = File.createTempFile("tmp_pdtb", ".zip"); InputStream stream = getClass().getClassLoader().getResourceAsStream("pdtb-parser-v120415.zip"); FileUtils.copyInputStreamToFile(stream, tmpFile); ZipFile zipFile;/*from w ww .j a v a2 s . com*/ try { zipFile = new ZipFile(tmpFile); zipFile.extractAll(tempDir.getAbsolutePath()); } catch (ZipException e) { throw new IOException(e); } // delete temp file FileUtils.forceDelete(tmpFile); String folderPrefix = "/pdtb-parser-v120415/src"; String srcDir = tempDir.getCanonicalPath() + folderPrefix; // copy rewritten rb files copyFiles(new File(srcDir), "article.rb", "parser.rb"); Files.walkFileTree(tempDirectory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Set<PosixFilePermission> permissions = new HashSet<>(); permissions.add(PosixFilePermission.OWNER_EXECUTE); permissions.add(PosixFilePermission.GROUP_EXECUTE); permissions.add(PosixFilePermission.OTHERS_EXECUTE); permissions.add(PosixFilePermission.OWNER_READ); permissions.add(PosixFilePermission.GROUP_READ); permissions.add(PosixFilePermission.OTHERS_READ); Files.setPosixFilePermissions(file, permissions); return super.visitFile(file, attrs); } }); parserRubyScript = srcDir + "/parser.rb"; System.out.println(parserRubyScript); }
From source file:eu.cloud4soa.frontend.upload.ArtifactsHolderImpl.java
@Override public void addFileItem(String fileName, InputStream stream) throws IOException { File tempFile = File.createTempFile("c4s", "tmp"); FileItem fileItem = new FileItem(tempFile, fileName); // Process the input stream FileOutputStream out = new FileOutputStream(tempFile); int len;//from w w w . ja v a 2s . c om byte[] buffer = new byte[8192]; while ((len = stream.read(buffer, 0, buffer.length)) != -1) { out.write(buffer, 0, len); } uploadedFiles.add(fileItem); }
From source file:net.itransformers.utils.graphmlmerge.GraphmlMergeTestCase.java
@Test public void testMerge() throws IOException, URISyntaxException { File f1 = new File(getClass().getResource("/graphmlmerge/1.graphml").toURI()); File f2 = new File(getClass().getResource("/graphmlmerge/2.graphml").toURI()); File f3 = new File(getClass().getResource("/graphmlmerge/3.graphml").toURI()); File f3Actual = File.createTempFile("graphml_merge", ".xml"); Map<String, String> edgesTypes = null; Map<String, String> vertexTypes = null; new GrahmlMerge().merge(new File[] { f1, f2 }, f3Actual, vertexTypes, edgesTypes, "undirected"); String xml3 = FileUtils.readFileToString(f3).replaceAll("\r", ""); String xml3Actual = FileUtils.readFileToString(f3Actual).replaceAll("
", ""); xml3Actual = xml3Actual.replaceAll("\r", ""); Assert.assertEquals(xml3.replaceAll("\r", ""), xml3Actual.replaceAll("\r", "")); }
From source file:com.ettrema.zsync.Scratch.java
@Before public void setUp() throws IOException { fOrig = new File("src/test/resources/large-text-server.txt"); // this represents the remote file we want to download fUpdated = new File("src/test/resources/large-text-local.txt"); // this represents the current version of the local file we want to update fTemp = File.createTempFile("milton-test", "orig"); TransferService transferService = new TransferService(null, null); ZSyncClient zSyncClient = new ZSyncClient(transferService); host = new Host("localhost", "webdav", 8080, "user1", "pwd1", null, 30000, null, zSyncClient); pl = new TestProgressListener(); FileUtils.copyFile(fOrig, fTemp);//from w w w .jav a2 s . c o m }
From source file:eu.scape_project.archiventory.identifiers.ArcFilesTestMap.java
private ArcFilesTestMap() throws IOException { InputStream testFileStream = ArcFilesTestMap.class.getResourceAsStream("test.arc.gz"); tmpTestFile = File.createTempFile("test", ".arc.gz"); FileOutputStream fos = new FileOutputStream(tmpTestFile); IOUtils.copy(testFileStream, fos);/* w w w . j a v a 2 s . c om*/ fos.close(); FileInputStream fileInputStream = new FileInputStream(tmpTestFile); map = new ArcContainer(); map.init(tmpTestFile.getAbsolutePath(), fileInputStream); }
From source file:com.playonlinux.python.PythonInstallerTest.java
@Test public void testPythonInstaller_DefineLogContextWithMethod_ContextIsSet() throws IOException, ScriptFailureException { File temporaryScript = File.createTempFile("testDefineLogContext", "py"); FileOutputStream fileOutputStream = new FileOutputStream(temporaryScript); fileOutputStream.write(("#!/usr/bin/env/python\n" + "from com.playonlinux.framework.templates import Installer\n" + "\n" + "class PlayOnLinuxBashInterpreter(Installer):\n" + " def main(self):\n" + " pass\n" + " def logContext(self):\n" + " return \"Mock Log Context\"\n").getBytes()); Interpreter interpreter = Interpreter.createInstance(); interpreter.execfile(temporaryScript.getAbsolutePath()); PythonInstaller<ScriptTemplate> pythonInstaller = new PythonInstaller<>(interpreter, ScriptTemplate.class); assertEquals("Mock Log Context", pythonInstaller.extractLogContext()); }
From source file:edu.scripps.fl.test.pubchem.test.FetchFromDepositionSystemTest.java
private static void displayFile(int aid, InputStream is, String ext) throws IOException { File file = File.createTempFile("AID" + aid + "-", "." + ext); file.deleteOnExit();//from w ww . j a va 2 s. c o m IOUtils.copy(is, new FileOutputStream(file)); is.close(); log.info("Created file " + file); // Desktop.getDesktop().open(file); }