/** * Creates a new XZ compressor using the default LZMA2 options. * This is equivalent to <code>XZCompressorOutputStream(outputStream, 6)</code>. * @param outputStream the stream to wrap * @throws IOException on error */ public XZCompressorOutputStream(final OutputStream outputStream) throws IOException { out = new XZOutputStream(outputStream, new LZMA2Options()); }
/** * Creates a LZMA compressor. * * @param outputStream the stream to wrap * @throws IOException on error */ public LZMACompressorOutputStream(final OutputStream outputStream) throws IOException { out = new LZMAOutputStream(outputStream, new LZMA2Options(), -1); }
/** * Finishes compression without closing the underlying stream. * No more data can be written to this stream after finishing. * @throws IOException on error */ public void finish() throws IOException { out.finish(); }
private LZMA2Options getOptions(final Object opts) throws IOException { if (opts instanceof LZMA2Options) { return (LZMA2Options) opts; } final LZMA2Options options = new LZMA2Options(); options.setDictSize(numberOptionOrDefault(opts)); return options; }
@SuppressWarnings("resource") @Override OutputStream encode(final OutputStream out, final Object options) throws IOException { final int distance = numberOptionOrDefault(options, 1); try { return new DeltaOptions(distance).getOutputStream(new FinishableWrapperOutputStream(out)); } catch (final UnsupportedOptionsException ex) { throw new IOException(ex.getMessage()); } }
@Override OutputStream encode(final OutputStream out, final Object opts) throws IOException { final LZMA2Options options = getOptions(opts); final FinishableOutputStream wrapped = new FinishableWrapperOutputStream(out); return options.getOutputStream(wrapped); }
@Override public void write(final byte[] buf, final int off, final int len) throws IOException { out.write(buf, off, len); }
@SuppressWarnings("resource") @Override OutputStream encode(final OutputStream out, final Object options) { return new FlushShieldFilterOutputStream(opts.getOutputStream(new FinishableWrapperOutputStream(out))); } }
@Override public void close() throws IOException { out.close(); } }
private int getDictSize(final Object opts) { if (opts instanceof LZMA2Options) { return ((LZMA2Options) opts).getDictSize(); } return numberOptionOrDefault(opts); }
@Override InputStream decode(final String archiveName, final InputStream in, final long uncompressedLength, final Coder coder, final byte[] password) throws IOException { return new DeltaOptions(getOptionsFromCoder(coder)).getInputStream(in); }
/** {@inheritDoc} */ @Override public void write(final byte[] buf, final int off, final int len) throws IOException { out.write(buf, off, len); }
/** * Finishes compression without closing the underlying stream. * No more data can be written to this stream after finishing. * @throws IOException on error */ public void finish() throws IOException { out.finish(); }
@Override InputStream decode(final String archiveName, final InputStream in, final long uncompressedLength, final Coder coder, final byte[] password) throws IOException { try { return opts.getInputStream(in); } catch (final AssertionError e) { throw new IOException("BCJ filter used in " + archiveName + " needs XZ for Java > 1.4 - see " + "https://commons.apache.org/proper/commons-compress/limitations.html#7Z", e); } }
/** * Flushes the encoder and calls <code>outputStream.flush()</code>. * All buffered pending data will then be decompressible from * the output stream. Calling this function very often may increase * the compressed file size a lot. */ @Override public void flush() throws IOException { out.flush(); }
/** {@inheritDoc} */ @Override public void close() throws IOException { out.close(); } }
/** * Creates a new XZ compressor using the specified LZMA2 preset level. * <p> * The presets 0-3 are fast presets with medium compression. * The presets 4-6 are fairly slow presets with high compression. * The default preset is 6. * <p> * The presets 7-9 are like the preset 6 but use bigger dictionaries * and have higher compressor and decompressor memory requirements. * Unless the uncompressed size of the file exceeds 8 MiB, * 16 MiB, or 32 MiB, it is waste of memory to use the * presets 7, 8, or 9, respectively. * @param outputStream the stream to wrap * @param preset the preset * @throws IOException on error */ public XZCompressorOutputStream(final OutputStream outputStream, final int preset) throws IOException { out = new XZOutputStream(outputStream, new LZMA2Options(preset)); }
private LZMA2Options getOptions(final Object opts) throws IOException { if (opts instanceof LZMA2Options) { return (LZMA2Options) opts; } final LZMA2Options options = new LZMA2Options(); options.setDictSize(numberOptionOrDefault(opts)); return options; }
@Override public void write(final int b) throws IOException { out.write(b); }
/** {@inheritDoc} */ @Override public void write(final int b) throws IOException { out.write(b); }