[jboss-remoting-commits] JBoss Remoting SVN: r5306 - 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
Mon Jul 27 22:13:08 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-07-27 22:13:08 -0400 (Mon, 27 Jul 2009)
New Revision: 5306

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/CompressingUnMarshaller.java
Log:
JBREM-1077: Made changes suggested by Doychin Bondzhev.

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-07-08 01:53:38 UTC (rev 5305)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java	2009-07-28 02:13:08 UTC (rev 5306)
@@ -95,8 +95,7 @@
    public void write(Object dataObject, OutputStream output, int version) throws IOException
    {
       output.flush();
-      ;
-      GZIPOutputStream gzos = new GZIPOutputStream(output);
+      GZIPOutputStream gzos = new SelfCleaningGZipOutputStream(output);
       BufferedOutputStream bos = new BufferedOutputStream(gzos);
       ObjectOutputStream oos = SerializationStreamFactory.getManagerInstance(getSerializationType()).createOutput(bos);
 
@@ -114,8 +113,8 @@
 
       oos.flush();
       bos.flush();
+      gzos.finish();
       gzos.flush();
-      gzos.finish();
 
    }
 
@@ -129,6 +128,27 @@
    {
       return new CompressingMarshaller(wrappedMarshaller);
    }
+   
+   
+   /**
+    * @author Doychin Bondzhev
+    */
+   static class SelfCleaningGZipOutputStream extends GZIPOutputStream
+   {
+      public SelfCleaningGZipOutputStream(OutputStream out) throws IOException
+      {
+         super(out);
+      }
 
+      /**
+       * Writes remaining compressed data to the output stream and closes the underlying stream.
+       * @exception IOException if an I/O error has occurred
+       */
+      public void finish() throws IOException
+      {
+         super.finish();
+         def.end(); // This will release all resources used by zlib native code
+      }
+   }
 }
 

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-07-08 01:53:38 UTC (rev 5305)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java	2009-07-28 02:13:08 UTC (rev 5306)
@@ -104,31 +104,38 @@
     */
    public Object read(InputStream inputStream, Map metadata, int version) throws IOException, ClassNotFoundException
    {
-      GZIPInputStream gzis = new GZIPInputStream(inputStream);
+      SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
       BufferedInputStream bis = new BufferedInputStream(gzis);
       SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
       ObjectInputStream ois =  manager.createInput(bis, getClassLoader());
 
-      if(wrappedUnMarshaller != null)
+      try
       {
-         // HACK for JBREM-927.
-         if (wrappedUnMarshaller instanceof HTTPUnMarshaller)
+         if(wrappedUnMarshaller != null)
          {
-            Map map = new HashMap();
-            if (metadata != null)
-               map.putAll(metadata);
-            map.put("Content-Length", Integer.toString(Integer.MAX_VALUE));
-            metadata = map;
+            // 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
+               return wrappedUnMarshaller.read(ois, metadata);
          }
-         
-         if (wrappedUnMarshaller instanceof VersionedUnMarshaller)
-            return ((VersionedUnMarshaller)wrappedUnMarshaller).read(ois, metadata, version);
          else
-            return wrappedUnMarshaller.read(ois, metadata);
+         {
+            return super.read(ois, metadata, version);
+         }
       }
-      else
+      finally
       {
-         return super.read(ois, metadata, version);
+         gzis.end();
       }
    }
 
@@ -144,5 +151,25 @@
       return new CompressingUnMarshaller(wrappedUnMarshaller);
    }
 
+
+   /**
+    * @author Doychin Bondzhev
+    */
+   static class SelfCleaningGZipInputStream extends GZIPInputStream
+   {
+      public SelfCleaningGZipInputStream(InputStream in) throws IOException
+      {
+         super(in);
+      }
+
+      public void end() throws IOException
+      {
+         while(available() > 0) { // This will force input stream to read gzip trailer from input stream
+            read();
+         }
+         inf.end(); // TO release resources used by native code
+      }
+   }
+   
 }
 



More information about the jboss-remoting-commits mailing list