List of usage examples for org.apache.commons.compress.utils CountingOutputStream CountingOutputStream
public CountingOutputStream(final OutputStream out)
From source file:htsjdk.samtools.reference.FastaReferenceWriter.java
/** * Creates a reference FASTA file writer (private...use the builder: {@link FastaReferenceWriterBuilder}. * <p>/*from ww w . j a va2s . c o m*/ * You can specify a specific output stream to each file: the main fasta output, its index and its dictionary. * You can only provide a compressed stream to the fastaOutput, and only in the case that an index isn't written. * <p> * <p> * </p> * * @param fastaOutput the (uncompressed) output fasta file path. * @param indexOutput the (uncompressed) output stream to the index file, if requested, {@code null} if none should be generated. * @param dictOutput the (uncompressed) output stream to the dictFile, if requested, {@code null} if none should be generated. * @throws IllegalArgumentException if {@code fastaFile} is {@code null} or {@code basesPerLine} is 0 or negative. */ FastaReferenceWriter(final int basesPerLine, final boolean addMd5, final OutputStream fastaOutput, final OutputStream indexOutput, final OutputStream dictOutput) { try { this.md5Digester = addMd5 ? MessageDigest.getInstance("MD5") : null; } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Couldn't get md5 algorithm!", e); } this.defaultBasePerLine = basesPerLine; this.fastaStream = new CountingOutputStream(fastaOutput); this.indexWriter = indexOutput == null ? NullWriter.NULL_WRITER : new OutputStreamWriter(indexOutput, CHARSET); this.dictWriter = dictOutput == null ? NullWriter.NULL_WRITER : new OutputStreamWriter(dictOutput, CHARSET); this.dictCodec = new SAMSequenceDictionaryCodec(dictWriter); this.dictCodec.encodeHeaderLine(false); }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private CountingOutputStream setupFileOutputStream() throws IOException { if (files.isEmpty()) { throw new IllegalStateException("No current 7z entry"); }//w ww . j av a2s.c o m OutputStream out = new OutputStreamWrapper(); final ArrayList<CountingOutputStream> moreStreams = new ArrayList<CountingOutputStream>(); boolean first = true; for (final SevenZMethodConfiguration m : getContentMethods(files.get(files.size() - 1))) { if (!first) { final CountingOutputStream cos = new CountingOutputStream(out); moreStreams.add(cos); out = cos; } out = Coders.addEncoder(out, m.getMethod(), m.getOptions()); first = false; } if (!moreStreams.isEmpty()) { additionalCountingStreams = moreStreams.toArray(new CountingOutputStream[moreStreams.size()]); } return new CountingOutputStream(out) { @Override public void write(final int b) throws IOException { super.write(b); crc32.update(b); } @Override public void write(final byte[] b) throws IOException { super.write(b); crc32.update(b); } @Override public void write(final byte[] b, final int off, final int len) throws IOException { super.write(b, off, len); crc32.update(b, off, len); } }; }
From source file:srebrinb.compress.sevenzip.SevenZOutputFile.java
private CountingOutputStream setupFileOutputStream() throws IOException { if (files.isEmpty()) { throw new IllegalStateException("No current 7z entry"); }/* w w w . j a v a2 s. c o m*/ OutputStream out = new OutputStreamWrapper(); final ArrayList<CountingOutputStream> moreStreams = new ArrayList<>(); boolean first = true; for (final SevenZMethodConfiguration m : getContentMethods(files.get(files.size() - 1))) { if (!first) { final CountingOutputStream cos = new CountingOutputStream(out); moreStreams.add(cos); out = cos; } out = Coders.addEncoder(out, m.getMethod(), m.getOptions()); first = false; } if (!moreStreams.isEmpty()) { additionalCountingStreams = moreStreams.toArray(new CountingOutputStream[moreStreams.size()]); } return new CountingOutputStream(out) { @Override public void write(final int b) throws IOException { super.write(b); crc32.update(b); } @Override public void write(final byte[] b) throws IOException { super.write(b); crc32.update(b); } @Override public void write(final byte[] b, final int off, final int len) throws IOException { super.write(b, off, len); crc32.update(b, off, len); } }; }