[jboss-remoting-commits] JBoss Remoting SVN: r5338 - remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Fri Aug 14 21:17:04 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-08-14 21:17:04 -0400 (Fri, 14 Aug 2009)
New Revision: 5338

Modified:
   remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
Log:
JBREM-1077: Made changes suggested by Doychin Bondzhev; reuses GZIPInputStream and BufferedInputStream, just replacing the Inflater with each call.

Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java	2009-08-15 01:16:22 UTC (rev 5337)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java	2009-08-15 01:17:04 UTC (rev 5338)
@@ -22,20 +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.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.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.
@@ -82,6 +85,13 @@
    {
       wrappedUnMarshaller = unMarshaller;
    }
+   
+   public InputStream getMarshallingStream(InputStream inputStream) throws IOException
+   {
+      SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
+      DecomposableBufferedInputStream bis = new DecomposableBufferedInputStream(gzis);
+      return bis;
+   }
 
    /**
     * Restores a compressed, marshalled form of an object to its original state.
@@ -96,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.createRegularInput(bis);
 
@@ -105,6 +127,16 @@
       {
          if(wrappedUnMarshaller != null)
          {
+            // HACK for JBREM-927.
+            if (wrappedUnMarshaller instanceof HTTPUnMarshaller)
+            {
+               Map map = new HashMap();
+               if (metadata != null)
+                  map.putAll(metadata);
+               map.put("Content-Length", Integer.toString(Integer.MAX_VALUE));
+               metadata = map;
+            }
+
             if (wrappedUnMarshaller instanceof VersionedUnMarshaller)
                return ((VersionedUnMarshaller)wrappedUnMarshaller).read(ois, metadata, version);
             else
@@ -139,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();
@@ -153,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