[jboss-remoting-commits] JBoss Remoting SVN: r5323 - remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Wed Aug 5 11:50:38 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-08-05 11:50:38 -0400 (Wed, 05 Aug 2009)
New Revision: 5323

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
Log:
JBREM-1077: Reuses GZIPInputStream and BufferedInputStream, just replacing the Inflater with each call.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java	2009-08-05 15:48:06 UTC (rev 5322)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java	2009-08-05 15:50:38 UTC (rev 5323)
@@ -22,23 +22,23 @@
 
 package org.jboss.remoting.marshal.compress;
 
-import org.jboss.remoting.marshal.UnMarshaller;
-import org.jboss.remoting.marshal.VersionedUnMarshaller;
-import org.jboss.remoting.marshal.http.HTTPUnMarshaller;
-import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
-import org.jboss.remoting.serialization.SerializationManager;
-import org.jboss.remoting.serialization.SerializationStreamFactory;
-
 import java.io.BufferedInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.ObjectInputStream;
-import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.zip.GZIPInputStream;
+import java.util.zip.Inflater;
 
+import org.jboss.remoting.marshal.UnMarshaller;
+import org.jboss.remoting.marshal.VersionedUnMarshaller;
+import org.jboss.remoting.marshal.http.HTTPUnMarshaller;
+import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
+import org.jboss.remoting.serialization.SerializationManager;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
 
+
 /**
  * <code>CompressingMarshaller</code> and <code>CompressingUnMarshaller</code> are a general
  * purpose compressing marshaller / decompressing unmarshaller pair based on Java's GZIP facilities.
@@ -88,7 +88,9 @@
    
    public InputStream getMarshallingStream(InputStream inputStream) throws IOException
    {
-      return inputStream;
+      SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
+      DecomposableBufferedInputStream bis = new DecomposableBufferedInputStream(gzis);
+      return bis;
    }
 
    /**
@@ -104,8 +106,20 @@
     */
    public Object read(InputStream inputStream, Map metadata, int version) throws IOException, ClassNotFoundException
    {
-      SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
-      BufferedInputStream bis = new BufferedInputStream(gzis);
+      SelfCleaningGZipInputStream gzis = null;
+      DecomposableBufferedInputStream bis = null;
+      
+      if (inputStream instanceof DecomposableBufferedInputStream)
+      {
+         bis = (DecomposableBufferedInputStream) inputStream;
+         gzis = (SelfCleaningGZipInputStream) bis.getWrappedStream();
+      }
+      else
+      {
+         gzis = new SelfCleaningGZipInputStream(inputStream);
+         bis = new DecomposableBufferedInputStream(gzis);
+      }
+
       SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
       ObjectInputStream ois =  manager.createInput(bis, getClassLoader());
 
@@ -157,12 +171,18 @@
     */
    static class SelfCleaningGZipInputStream extends GZIPInputStream
    {
-      public SelfCleaningGZipInputStream(InputStream in) throws IOException
+      SelfCleaningGZipInputStream(InputStream in) throws IOException
       {
          super(in);
       }
+      
+      void refreshInflater()
+      {
+         inf = new Inflater(true);
+         crc.reset();
+      }
 
-      public void end() throws IOException
+      void end() throws IOException
       {
          while(available() > 0) { // This will force input stream to read gzip trailer from input stream
             read();
@@ -171,5 +191,22 @@
       }
    }
    
+   static class DecomposableBufferedInputStream extends BufferedInputStream
+   {
+      DecomposableBufferedInputStream(InputStream in, int size)
+      {
+         super(in, size);
+      }
+
+      DecomposableBufferedInputStream(InputStream in)
+      {
+         super(in);
+      }
+      
+      InputStream getWrappedStream()
+      {
+         return in;
+      }
+   }
 }
 



More information about the jboss-remoting-commits mailing list