From 283569b8ede00003c24776961e77051f37dc5594 Mon Sep 17 00:00:00 2001 From: Nico Kruber Date: Mon, 28 Jan 2013 20:05:24 +0100 Subject: jinterface, OtpOutputStream: add a write_compressed(object, level) method Now that we use an own deflater, we can also allow the user to specify the compression level as in Erlang's term_to_binary/2. --- .../com/ericsson/otp/erlang/OtpOutputStream.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/jinterface/java_src/com/ericsson/otp') diff --git a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java index 884a0cd21c..f7d5891a27 100644 --- a/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java +++ b/lib/jinterface/java_src/com/ericsson/otp/erlang/OtpOutputStream.java @@ -796,11 +796,23 @@ public class OtpOutputStream extends ByteArrayOutputStream { /** * Write an arbitrary Erlang term to the stream in compressed format. - * + * * @param o - * the Erlang tem to write. + * the Erlang term to write. */ public void write_compressed(final OtpErlangObject o) { + write_compressed(o, Deflater.DEFAULT_COMPRESSION); + } + + /** + * Write an arbitrary Erlang term to the stream in compressed format. + * + * @param o + * the Erlang term to write. + * @param level + * the compression level (0..9) + */ + public void write_compressed(final OtpErlangObject o, int level) { final OtpOutputStream oos = new OtpOutputStream(o); /* * similar to erts_term_to_binary() in external.c: @@ -825,7 +837,7 @@ public class OtpOutputStream extends ByteArrayOutputStream { // -> if compression uses more, use the uncompressed term! int destCount = startCount + oos.size(); this.fixedSize = destCount; - Deflater def = new Deflater(); + Deflater def = new Deflater(level); final java.util.zip.DeflaterOutputStream dos = new java.util.zip.DeflaterOutputStream( this, def); try { -- cgit v1.2.3