List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:de.thischwa.pmcms.tool.compression.Zip.java
/** * Static method to compress all files based on the ImputStream in 'entries' into 'zip'. * Each entry has a InputStream and its String representation in the zip. * //from ww w. ja va 2s . c om * @param zip The zip file. It will be deleted if exists. * @param entries Map<File, String> * @param monitor Must be initialized correctly by the caller. * @throws IOException */ public static void compress(final File zip, final Map<InputStream, String> entries, final IProgressMonitor monitor) throws IOException { if (zip == null || entries == null || CollectionUtils.isEmpty(entries.keySet())) throw new IllegalArgumentException("One ore more parameters are empty!"); if (zip.exists()) zip.delete(); else if (!zip.getParentFile().exists()) zip.getParentFile().mkdirs(); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zip))); out.setLevel(Deflater.BEST_COMPRESSION); try { for (InputStream inputStream : entries.keySet()) { // skip beginning slash, because can cause errors in other zip apps ZipEntry zipEntry = new ZipEntry(skipBeginningSlash(entries.get(inputStream))); out.putNextEntry(zipEntry); IOUtils.copy(inputStream, out); out.closeEntry(); inputStream.close(); if (monitor != null) monitor.worked(1); } } finally { // cleanup IOUtils.closeQuietly(out); } }
From source file:com.rapleaf.hank.storage.curly.CurlyMerger.java
@Override public long[] merge(final CurlyFilePath base, final List<String> deltaRemoteFiles, final PartitionRemoteFileOps partitionRemoteFileOps) throws IOException { long[] offsetAdjustments = new long[deltaRemoteFiles.size() + 1]; offsetAdjustments[0] = 0;/*from www .j a v a2 s . com*/ // Open the base in append mode File baseFile = new File(base.getPath()); FileOutputStream baseFileOutputStream = new FileOutputStream(baseFile, true); OutputStream baseOutputStream = new BufferedOutputStream(baseFileOutputStream); try { // Loop over deltas and append them to the base in order, keeping track of offset adjustments long totalOffset = baseFile.length(); int i = 1; for (String deltaRemoteFile : deltaRemoteFiles) { offsetAdjustments[i] = totalOffset; InputStream deltaRemoteInputStream = partitionRemoteFileOps.getInputStream(deltaRemoteFile); try { LOG.info("Merging remote file " + deltaRemoteFile + " into file " + base.getPath()); long bytesCopied = IOUtils.copyLarge(deltaRemoteInputStream, baseOutputStream); totalOffset += bytesCopied; } finally { deltaRemoteInputStream.close(); } i++; } } finally { // Close base streams baseOutputStream.close(); baseFileOutputStream.close(); } return offsetAdjustments; }
From source file:com.oprisnik.semdroid.utils.FileUtils.java
public static void writeObjectToFile(Object object, File file) throws IOException { if (!file.exists()) { file.getParentFile().mkdirs();// w w w . java2 s .c o m } ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.writeObject(object); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:com.ooxx.mqtt.internal.wire.MqttOutputStream.java
public MqttOutputStream(ClientState clientState, OutputStream out) { this.clientState = clientState; this.out = new CountingOutputStream(new BufferedOutputStream(out)); }
From source file:accumulo.AccumuloStuff.java
private static void setCoreSite(MiniAccumuloClusterImpl cluster) throws Exception { File csFile = new File(cluster.getConfig().getConfDir(), "core-site.xml"); if (csFile.exists()) throw new RuntimeException(csFile + " already exist"); Configuration coreSite = new Configuration(false); coreSite.set("fs.file.impl", RawLocalFileSystem.class.getName()); OutputStream out = new BufferedOutputStream( new FileOutputStream(new File(cluster.getConfig().getConfDir(), "core-site.xml"))); coreSite.writeXml(out);//ww w . j a va2s . c o m out.close(); }
From source file:com.compomics.pladipus.core.control.util.ZipUtils.java
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException { if (entry.isDirectory()) { createDir(new File(outputDir, entry.getName())); return;//ww w . java 2s . co m } File outputFile = new File(outputDir, entry.getName()); if (!outputFile.getParentFile().exists()) { createDir(outputFile.getParentFile()); } LOGGER.debug("Extracting: " + entry); try (BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) { IOUtils.copy(inputStream, outputStream); outputStream.flush(); } }
From source file:com.googlecode.lineblog.websocket.TokenThread.java
public TokenThread(Socket socket) throws IOException { if (socket == null) throw new RuntimeException("socket is not null!"); this.socket = socket; this.in = new BufferedInputStream(this.socket.getInputStream()); this.out = new BufferedOutputStream(this.socket.getOutputStream()); this.accept();//? }
From source file:edu.jhu.hlt.concrete.serialization.TarGzCompactCommunicationSerializer.java
@Override public void toTarGz(Collection<Communication> commColl, Path outPath) throws ConcreteException { try (OutputStream os = Files.newOutputStream(outPath); BufferedOutputStream bos = new BufferedOutputStream(os); GzipCompressorOutputStream gzos = new GzipCompressorOutputStream(bos); TarArchiveOutputStream tos = new TarArchiveOutputStream(gzos);) { for (Communication c : commColl) { TarArchiveEntry entry = new TarArchiveEntry(c.getId() + ".concrete"); byte[] cbytes = this.toBytes(c); entry.setSize(cbytes.length); tos.putArchiveEntry(entry);/* w w w .j a v a2s . c o m*/ try (ByteArrayInputStream bis = new ByteArrayInputStream(cbytes)) { IOUtils.copy(bis, tos); tos.closeArchiveEntry(); } } } catch (IOException e) { throw new ConcreteException(e); } }
From source file:com.music.service.LocalFileStorageService.java
@Override public void storeFile(String path, InputStream inputStream, long size) throws IOException { OutputStream os = new BufferedOutputStream(new FileOutputStream(path)); IOUtils.copy(inputStream, os);/*w w w.j av a2 s . com*/ os.close(); }
From source file:org.paxml.bean.UnzipTag.java
public static void unzip(File file, File dir) { dir.mkdirs();// w ww.j ava 2 s .c o m ZipFile zipFile = null; try { zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { new File(dir, entry.getName()).mkdirs(); continue; } InputStream in = null; OutputStream out = null; try { zipFile.getInputStream(entry); out = new BufferedOutputStream(new FileOutputStream(entry.getName())); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } catch (IOException ioe) { throw new PaxmlRuntimeException( "Cannot unzip file: " + file.getAbsolutePath() + " under dir: " + dir.getAbsolutePath(), ioe); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { // do nothing } } } }