List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:org.eclipse.gemini.blueprint.test.internal.util.jar.storage.FileSystemStorage.java
public OutputStream getOutputStream() { try {/*from w w w . j a va2 s . c o m*/ return new BufferedOutputStream(new FileOutputStream(storage)); } catch (IOException ex) { throw new RuntimeException("cannot return file stream", ex); } }
From source file:net.sf.jabref.exporter.OpenDocumentSpreadsheetCreator.java
private static void storeOpenDocumentSpreadsheetFile(File file, InputStream source) throws Exception { try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { //addResourceFile("mimetype", "/resource/ods/mimetype", out); ZipEntry ze = new ZipEntry("mimetype"); String mime = "application/vnd.oasis.opendocument.spreadsheet"; ze.setMethod(ZipEntry.STORED); ze.setSize(mime.length());/*from w w w.j a v a 2 s . co m*/ CRC32 crc = new CRC32(); crc.update(mime.getBytes()); ze.setCrc(crc.getValue()); out.putNextEntry(ze); for (int i = 0; i < mime.length(); i++) { out.write(mime.charAt(i)); } out.closeEntry(); ZipEntry zipEntry = new ZipEntry("content.xml"); //zipEntry.setMethod(ZipEntry.DEFLATED); out.putNextEntry(zipEntry); int c; while ((c = source.read()) >= 0) { out.write(c); } out.closeEntry(); // Add manifest (required for OOo 2.0) and "meta.xml": These are in the // resource/ods directory, and are copied verbatim into the zip file. OpenDocumentSpreadsheetCreator.addResourceFile("meta.xml", "/resource/ods/meta.xml", out); OpenDocumentSpreadsheetCreator.addResourceFile("META-INF/manifest.xml", "/resource/ods/manifest.xml", out); } }
From source file:com.qwazr.extractor.ParserAbstract.java
protected static Path createTempFile(final InputStream inputStream, final String extension) throws IOException { final Path tempFile = Files.createTempFile("oss-extractor", extension); try (final OutputStream out = Files.newOutputStream(tempFile); final BufferedOutputStream bOut = new BufferedOutputStream(out);) { IOUtils.copy(inputStream, bOut); bOut.close();/*from w w w. j ava2 s .c om*/ return tempFile; } }
From source file:com.hs.mail.util.FileUtils.java
public static void uncompress(File srcFile, File destFile) throws IOException { InputStream input = null;// ww w . jav a 2 s .c o m OutputStream output = null; try { input = new GZIPInputStream(new FileInputStream(srcFile)); output = new BufferedOutputStream(new FileOutputStream(destFile)); IOUtils.copyLarge(input, output); } finally { IOUtils.closeQuietly(output); IOUtils.closeQuietly(input); } }
From source file:com.textocat.textokit.commons.wfstore.DefaultWordformStore.java
@Override public void persist(File outFile) throws Exception { // serialize store object ObjectOutputStream modelOS = null; try {/* w w w .j a v a 2 s .c o m*/ OutputStream os = new BufferedOutputStream(openOutputStream(outFile)); modelOS = new ObjectOutputStream(os); modelOS.writeObject(this); } finally { IOUtils.closeQuietly(modelOS); } log.info("Succesfully serialized to {}, size = {} bytes", outFile, outFile.length()); }
From source file:net.sf.sahi.util.Utils.java
public static byte[] getBytes(final InputStream in, final int contentLength) throws IOException { BufferedInputStream bin = new BufferedInputStream(in, BUFFER_SIZE); if (contentLength != -1) { int totalBytesRead = 0; byte[] buffer = new byte[contentLength]; while (totalBytesRead < contentLength) { int bytesRead = -1; try { bytesRead = bin.read(buffer, totalBytesRead, contentLength - totalBytesRead); } catch (EOFException e) { }//from w w w.ja v a 2 s . c o m if (bytesRead == -1) { break; } totalBytesRead += bytesRead; } return buffer; } else { ByteArrayOutputStream byteArOut = new ByteArrayOutputStream(); BufferedOutputStream bout = new BufferedOutputStream(byteArOut); try { int totalBytesRead = 0; byte[] buffer = new byte[BUFFER_SIZE]; while (true) { int bytesRead = -1; try { bytesRead = bin.read(buffer); } catch (EOFException e) { } if (bytesRead == -1) { break; } bout.write(buffer, 0, bytesRead); totalBytesRead += bytesRead; } } catch (SocketTimeoutException ste) { ste.printStackTrace(); } bout.flush(); bout.close(); return byteArOut.toByteArray(); } }
From source file:fitnesse.responders.files.UploadResponder.java
public void writeFile(File file, UploadedFile uploadedFile) throws Exception { boolean renamed = uploadedFile.getFile().renameTo(file); if (!renamed) { InputStream input = null; OutputStream output = null; try {/*from ww w. ja va2 s . c om*/ input = new BufferedInputStream(new FileInputStream(uploadedFile.getFile())); output = new BufferedOutputStream(new FileOutputStream(file)); FileUtil.copyBytes(input, output); } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); uploadedFile.delete(); } } }
From source file:mase.stat.CompetitiveBestStat.java
@Override public void setup(EvolutionState state, Parameter base) { super.setup(state, base); compress = state.parameters.getBoolean(base.push(P_COMPRESS), null, true); int n = state.parameters.getInt(new Parameter("pop.subpops"), null); outFile = new File[n]; for (int i = 0; i < n; i++) { outFile[i] = state.parameters.getFile(base.push(P_FILE), null); String newName = compress ? outFile[i].getName().replace(".tar.gz", "." + i + ".tar.gz") : outFile[i].getName() + "." + i; outFile[i] = new File(outFile[i].getParent(), jobPrefix + newName); }/*from w ww . j av a 2 s . co m*/ if (compress) { taos = new TarArchiveOutputStream[n]; for (int i = 0; i < n; i++) { try { taos[i] = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(outFile[i])))); } catch (IOException ex) { Logger.getLogger(BestSolutionGenStat.class.getName()).log(Level.SEVERE, null, ex); } } } for (int i = 0; i < n; i++) { if (!compress && !outFile[i].exists()) { outFile[i].mkdirs(); } } if (state.parameters.getBoolean(base.push(P_KEEP_LAST), null, true)) { last = new File[n]; for (int i = 0; i < n; i++) { last[i] = new File(outFile[i].getParent(), jobPrefix + "last." + i + ".xml"); } } }
From source file:adams.core.io.LzfUtils.java
/** * Decompresses the specified lzma archive. * * @param archiveFile the lzma file to decompress * @param buffer the buffer size to use * @param outputFile the destination file * @return the error message, null if everything OK *///from w w w . j av a2 s .c o m public static String decompress(File archiveFile, int buffer, File outputFile) { String result; LZFInputStream in; OutputStream out; FileInputStream fis; FileOutputStream fos; String msg; in = null; fis = null; out = null; fos = null; result = null; try { // does file already exist? if (outputFile.exists()) System.err.println("WARNING: overwriting '" + outputFile + "'!"); fis = new FileInputStream(archiveFile.getAbsolutePath()); in = new LZFInputStream(fis); fos = new FileOutputStream(outputFile.getAbsolutePath()); out = new BufferedOutputStream(fos); IOUtils.copy(in, out, buffer); } catch (Exception e) { msg = "Failed to decompress '" + archiveFile + "': "; System.err.println(msg); e.printStackTrace(); result = msg + e; } finally { FileUtils.closeQuietly(in); FileUtils.closeQuietly(fis); FileUtils.closeQuietly(out); FileUtils.closeQuietly(fos); } return result; }
From source file:com.dianping.phoenix.dev.core.tools.wms.AgentWorkspaceServiceImpl.java
public String getFromUrl(String url, File baseDir, OutputStream out) throws Exception { if (StringUtils.isBlank(url)) { return null; }/* w w w . j a v a 2s . c om*/ String fileName = extractFileName(url); BufferedInputStream is = null; BufferedOutputStream os = null; try { is = new BufferedInputStream(new URL(url).openStream()); os = new BufferedOutputStream(new FileOutputStream(new File(baseDir, fileName))); IOUtils.copyLarge(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } ZipUtil.explode(new File(baseDir, fileName)); return fileName; }