Author: ron.sigal(a)jboss.com
Date: 2009-08-05 11:48:06 -0400 (Wed, 05 Aug 2009)
New Revision: 5322
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java
Log:
JBREM-1077: Reuses GZIPOutputStream and BufferedOutputStream, just replacing the Deflater
with each call.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java 2009-08-05
04:27:28 UTC (rev 5321)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java 2009-08-05
15:48:06 UTC (rev 5322)
@@ -26,11 +26,13 @@
import org.jboss.remoting.marshal.VersionedMarshaller;
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
import org.jboss.remoting.serialization.SerializationStreamFactory;
+import org.jfree.util.Log;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
+import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;
@@ -81,7 +83,9 @@
public OutputStream getMarshallingStream(OutputStream outputStream) throws
IOException
{
- return outputStream;
+ GZIPOutputStream gzos = new SelfCleaningGZipOutputStream(outputStream);
+ DecomposableBufferedOutputStream bos = new DecomposableBufferedOutputStream(gzos);
+ return bos;
}
@@ -94,9 +98,19 @@
*/
public void write(Object dataObject, OutputStream output, int version) throws
IOException
{
- output.flush();
- GZIPOutputStream gzos = new SelfCleaningGZipOutputStream(output);
- BufferedOutputStream bos = new BufferedOutputStream(gzos);
+ SelfCleaningGZipOutputStream gzos = null;
+ DecomposableBufferedOutputStream bos = null;
+ if (output instanceof DecomposableBufferedOutputStream)
+ {
+ bos = (DecomposableBufferedOutputStream) output;
+ gzos = (SelfCleaningGZipOutputStream) bos.getWrappedStream();
+ gzos.refreshDeflater();
+ }
+ else
+ {
+ gzos = new SelfCleaningGZipOutputStream(output);
+ bos = new DecomposableBufferedOutputStream(gzos);
+ }
ObjectOutputStream oos =
SerializationStreamFactory.getManagerInstance(getSerializationType()).createOutput(bos);
if(wrappedMarshaller != null)
@@ -135,10 +149,25 @@
*/
static class SelfCleaningGZipOutputStream extends GZIPOutputStream
{
+ boolean used;
+
public SelfCleaningGZipOutputStream(OutputStream out) throws IOException
{
super(out);
}
+
+ void refreshDeflater()
+ {
+ if (used)
+ {
+ def = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
+ crc.reset();
+ }
+ else
+ {
+ used = true;
+ }
+ }
/**
* Writes remaining compressed data to the output stream and closes the underlying
stream.
@@ -150,5 +179,23 @@
def.end(); // This will release all resources used by zlib native code
}
}
+
+ static class DecomposableBufferedOutputStream extends BufferedOutputStream
+ {
+ DecomposableBufferedOutputStream(OutputStream out, int size)
+ {
+ super(out, size);
+ }
+
+ DecomposableBufferedOutputStream(OutputStream out)
+ {
+ super(out);
+ }
+
+ OutputStream getWrappedStream()
+ {
+ return out;
+ }
+ }
}
Show replies by date