/** * 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); }
@Override byte[] getOptionsAsProperties(final Object opts) throws IOException { final LZMA2Options options = getOptions(opts); final byte props = (byte) ((options.getPb() * 5 + options.getLp()) * 9 + options.getLc()); int dictSize = options.getDictSize(); byte[] o = new byte[5]; o[0] = props; ByteUtils.toLittleEndian(o, dictSize, 1, 4); return o; }
@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 Object getOptionsFromCoder(final Coder coder, final InputStream in) throws IOException { final byte propsByte = coder.properties[0]; int props = propsByte & 0xFF; int pb = props / (9 * 5); props -= pb * 9 * 5; int lp = props / 9; int lc = props - lp * 9; LZMA2Options opts = new LZMA2Options(); opts.setPb(pb); opts.setLcLp(lc, lp); opts.setDictSize(getDictionarySize(coder)); return opts; }
FileInputStream inFile = new FileInputStream("src.tar"); FileOutputStream outfile = new FileOutputStream("src.tar.xz"); LZMA2Options options = new LZMA2Options(); options.setPreset(7); // play with this number: 6 is default but 7 works better for mid sized archives ( > 8mb) XZOutputStream out = new XZOutputStream(outfile, options); byte[] buf = new byte[8192]; int size; while ((size = inFile.read(buf)) != -1) out.write(buf, 0, size); 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; }
final LZMA2Options options; try { options = new LZMA2Options(level); } catch (UnsupportedOptionsException e) { throw new IllegalStateException("LZMA2Option configuration failed", e); dictSize = options.getDictSize();
options = new LZMA2Options(level); } catch (UnsupportedOptionsException e) { throw new IllegalStateException("LZMA2Option configuration failed", e); options = new LZMA2Options(level); } catch (UnsupportedOptionsException e) { throw new IllegalStateException("LZMA2Option configuration failed", e); final org.tukaani.xz.FinishableOutputStream lzma2 = options.getOutputStream(wrapped); return new FinishableOutputStreamAdapter(lzma2) { @Override
private int getDictSize(final Object opts) { if (opts instanceof LZMA2Options) { return ((LZMA2Options) opts).getDictSize(); } return numberOptionOrDefault(opts); }
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; }
public static void main(String[] args) throws Exception { // InputStream fis; //File file = new File(DEFAULT_DIR, TEMP_FILE); // This works both within Eclipse project and in runnable JAR //InputStream fis = StandardCompressXz.class.getResourceAsStream("SurfaceMarsMap.dat"); // This works both within Eclipse project and in runnable JAR //InputStream fis = this.getClass().getClassLoader().getResourceAsStream("/map/SurfaceMarsMap.dat"); //fis = this.getClass().getClassLoader().getResourceAsStream("examples/resources/verdana.ttf"); // fis = StandardCompressXz.class.getClassLoader().getResourceAsStream("SurfaceMarsMap.dat.7z"); FileInputStream inFile = new FileInputStream(StandardCompressXz.class.getClassLoader().getResource("/map/SurfaceMarsMap.dat").toExternalForm());//"SurfaceMarsMap.dat"); FileOutputStream outfile = new FileOutputStream("/map/SurfaceMarsMap.xz"); LZMA2Options options = new LZMA2Options(); options.setPreset(7); // play with this number: 6 is default but 7 works better for mid sized archives ( > 8mb) XZOutputStream out = new XZOutputStream(outfile, options); byte[] buf = new byte[8192]; int size; while ((size = inFile.read(buf)) != -1) out.write(buf, 0, size); out.finish(); } }
@Override Object getOptionsFromCoder(final Coder coder, final InputStream in) throws IOException { final byte propsByte = coder.properties[0]; int props = propsByte & 0xFF; int pb = props / (9 * 5); props -= pb * 9 * 5; int lp = props / 9; int lc = props - lp * 9; LZMA2Options opts = new LZMA2Options(); opts.setPb(pb); opts.setLcLp(lc, lp); opts.setDictSize(getDictionarySize(coder)); return opts; }
final LZMA2Options options; try { options = new LZMA2Options(level); } catch (UnsupportedOptionsException e) { throw new IllegalStateException("LZMA2Option configuration failed", e); dictSize = options.getDictSize();
options = new LZMA2Options(level); } catch (UnsupportedOptionsException e) { throw new IllegalStateException("LZMA2Option configuration failed", e); options = new LZMA2Options(level); } catch (UnsupportedOptionsException e) { throw new IllegalStateException("LZMA2Option configuration failed", e); options.getOutputStream(wrapped); return new FinishableOutputStreamAdapter(lzma2) { @Override
private int getDictSize(final Object opts) { if (opts instanceof LZMA2Options) { return ((LZMA2Options) opts).getDictSize(); } return numberOptionOrDefault(opts); }
/** * 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()); }
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; }
private static byte[] xz(byte[] data, byte[] checksums, File path) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); LZMA2Options options = new LZMA2Options(); options.setPreset(8); XZOutputStream xz = new XZOutputStream(out, options); int x = checksums.length; xz.write(data); xz.write(checksums); xz.write(new byte[]{ (byte) (x & 0x000000FF), (byte)((x & 0x0000FF00) >> 8), (byte)((x & 0x00FF0000) >> 16), (byte)((x & 0xFF000000) >> 24) }); xz.write("SIGN".getBytes()); //Add our sign to validate xz.close(); byte[] xzed = out.toByteArray(); Files.write(xzed, new File(path.getAbsolutePath() + ".pack.xz")); return xzed; }
@Override byte[] getOptionsAsProperties(final Object opts) throws IOException { final LZMA2Options options = getOptions(opts); final byte props = (byte) ((options.getPb() * 5 + options.getLp()) * 9 + options.getLc()); int dictSize = options.getDictSize(); byte[] o = new byte[5]; o[0] = props; ByteUtils.toLittleEndian(o, dictSize, 1, 4); return o; }
@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); }