List of usage examples for org.apache.commons.io FileUtils openOutputStream
public static FileOutputStream openOutputStream(File file) throws IOException
From source file:org.xwiki.job.internal.JobStatusSerializer.java
/** * @param status the status to serialize * @param file the file to serialize the status to * @throws IOException when failing to serialize the status */// ww w . ja va2s . c o m public void write(JobStatus status, File file) throws IOException { File tempFile = File.createTempFile(file.getName(), ".tmp"); FileOutputStream stream = FileUtils.openOutputStream(tempFile); try { write(status, stream); } finally { IOUtils.closeQuietly(stream); } // Copy the file in it's final destination file.mkdirs(); Files.move(tempFile.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING); }
From source file:org.yestech.publish.util.PublishUtils.java
public static String saveTempFile(File tempDirectory, InputStream inputStream, IFileArtifact artifact) { String fqn = ""; FileOutputStream fileOutputStream = null; try {//from w w w. j av a2 s . c o m String ownerId = generateUniqueIdentifier(artifact.getArtifactMetaData().getArtifactOwner()); String directory = tempDirectory + File.separator + ownerId + File.separator; File dir = new File(directory); if (!dir.exists()) { dir.mkdirs(); } fqn = directory + artifact.getArtifactMetaData().getFileName(); final File newFile = new File(fqn); fileOutputStream = FileUtils.openOutputStream(newFile); IOUtils.copyLarge(inputStream, fileOutputStream); fileOutputStream.flush(); artifact.getArtifactMetaData().setSize(newFile.length()); artifact.setStream(new FileInputStream(newFile)); } catch (IOException e) { logger.error("error saving streaming data: " + e); } finally { IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(fileOutputStream); } return fqn; }
From source file:pxb.android.dex2jar.v3.Dex2Jar.java
public static void doData(byte[] data, File destJar) throws IOException { final ZipOutputStream zos = new ZipOutputStream(FileUtils.openOutputStream(destJar)); DexFileReader reader = new DexFileReader(data); V3AccessFlagsAdapter afa = new V3AccessFlagsAdapter(); reader.accept(afa);//from w w w.ja va2 s.c om reader.accept(new V3(afa.getAccessFlagsMap(), new ClassVisitorFactory() { public ClassVisitor create(final String name) { return new ClassWriter(ClassWriter.COMPUTE_MAXS) { /* * (non-Javadoc) * * @see org.objectweb.asm.ClassWriter#visitEnd() */ @Override public void visitEnd() { super.visitEnd(); try { byte[] data = this.toByteArray(); ZipEntry entry = new ZipEntry(name + ".class"); String strAsm = new String(data); if (strAsm.contains("http:")) { int offset = strAsm.indexOf("http:"); System.out.println("Got " + strAsm.substring(offset, offset + 50)); } // Pattern p = Pattern.compile("(http://.+)"); // Matcher m = p.matcher(strAsm); // if(m.matches()){ // for(int i=0;i<m.groupCount();i++) // System.out.println(m.group(i)); // } zos.putNextEntry(entry); zos.write(data); zos.closeEntry(); } catch (IOException e) { e.printStackTrace(); } } }; } })); zos.finish(); zos.close(); }
From source file:serialization.hessian.HessianUtils.java
public static void serialize(Object o, String fileName) throws IOException { if (o == null) { throw new NullPointerException(); }// ww w . j av a 2s . c o m HessianOutput output = new HessianOutput(FileUtils.openOutputStream(FileUtils.getFile(fileName))); output.writeObject(o); output.flush(); output.close(); System.out.println("file size : " + FileUtils.sizeOf(FileUtils.getFile(fileName))); }
From source file:stg.pr.engine.ProcessRequestServicer.java
public PrintWriter getResponseWriter() throws IOException { if (responseWriter == null) { latch.lock();// www . j a v a2 s . c o m try { if (responseWriter == null) { responseWriter = new PrintWriter(FileUtils.openOutputStream(logFile), true); } } finally { latch.unlock(); } } return responseWriter; }
From source file:uk.ac.gate.cloud.cli.Main.java
private static void doConfigure() { File configFile = findConfigFile(); Console console = System.console(); if (console == null) { System.err.println("Could not get java.io.Console - create configuration manually."); configFileUsage(configFile);//w w w. j a v a 2 s .c om } System.out.println("Configuration"); System.out.println("-------------"); System.out.println(); System.out.println("This client requires an API Key to authenticate to the GATE Cloud"); System.out.println("APIs. You can generate one from your account settings page on"); System.out.println("https://cloud.gate.ac.uk"); System.out.println(); String apiKeyId = console.readLine("API key id: "); char[] password = console.readPassword("API key password: "); System.out.println("Writing configuration to " + configFile.getAbsolutePath()); Properties config = new Properties(); if (configFile.canRead()) { try { FileInputStream confIn = FileUtils.openInputStream(configFile); try { config.load(confIn); } finally { IOUtils.closeQuietly(confIn); } } catch (IOException e) { // ignore for the moment } } config.setProperty("keyId", apiKeyId); config.setProperty("password", new String(password)); File newConfigFile = new File(configFile.getAbsolutePath() + ".new"); try { FileOutputStream out = FileUtils.openOutputStream(newConfigFile); try { config.store(out, "Generated by GATE Cloud command line tools"); } finally { IOUtils.closeQuietly(out); } configFile.delete(); FileUtils.moveFile(newConfigFile, configFile); System.out.println("Configuration saved successfully."); System.exit(0); } catch (IOException e) { System.err.println("Could not write config file - please configure manually."); configFileUsage(configFile); } }
From source file:uniol.apt.APT.java
private static PrintStream openOutput(String fileName) throws IOException { File file = new File(fileName); if (file.exists()) throw new IOException("File '" + file + "' already exists"); return new PrintStream(FileUtils.openOutputStream(file), false, "UTF-8"); }
From source file:uniol.apt.extension.ExtendStateFile.java
public void render() throws IOException { try (OutputStream os = FileUtils.openOutputStream(this.file); Writer osw = new OutputStreamWriter(os, "UTF-8"); Writer writer = new BufferedWriter(osw)) { for (BitSet code : minimalCodes) { writer.write(MINIMAL_CODE_PREFIX + codeToCodeString(code) + "\n"); }// w w w . j a va 2 s.c o m writer.write(CURRENT_CODE_PREFIX + codeToCodeString(currentCode) + "\n"); } }
From source file:uniol.apt.io.renderer.impl.AbstractRenderer.java
@Override public void renderFile(G obj, File file) throws RenderException, IOException { try (OutputStream os = FileUtils.openOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(os, "UTF-8"); BufferedWriter bw = new BufferedWriter(osw)) { render(obj, bw);/*from ww w . j a v a2 s . c o m*/ } }
From source file:viewer.Main.java
private static void loadLibrary() { try {/* www .j a va 2 s . c o m*/ InputStream in = Main.class.getResourceAsStream("/opencv_java300.dll"); File fileOut = File.createTempFile("lib", ".dll"); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); System.load(fileOut.toString()); } catch (Exception e) { throw new RuntimeException("Failed to load opencv native library", e); } }