Author: ron.sigal(a)jboss.com
Date: 2009-07-27 22:18:42 -0400 (Mon, 27 Jul 2009)
New Revision: 5308
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
Log:
JBREM-1077: Made changes suggested by Doychin Bondzhev.
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java 2009-07-28
02:14:09 UTC (rev 5307)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingMarshaller.java 2009-07-28
02:18:42 UTC (rev 5308)
@@ -27,6 +27,7 @@
import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
import org.jboss.remoting.serialization.SerializationStreamFactory;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
@@ -89,9 +90,9 @@
public void write(Object dataObject, OutputStream output, int version) throws
IOException
{
output.flush();
- ;
- GZIPOutputStream gzos = new GZIPOutputStream(output);
- ObjectOutputStream oos =
SerializationStreamFactory.getManagerInstance(getSerializationType()).createOutput(gzos);
+ GZIPOutputStream gzos = new SelfCleaningGZipOutputStream(output);
+ BufferedOutputStream bos = new BufferedOutputStream(gzos);
+ ObjectOutputStream oos =
SerializationStreamFactory.getManagerInstance(getSerializationType()).createOutput(bos);
if(wrappedMarshaller != null)
{
@@ -105,8 +106,10 @@
super.write(dataObject, oos, version);
}
+ oos.flush();
+ bos.flush();
gzos.finish();
- oos.flush();
+ gzos.flush();
}
/**
@@ -119,6 +122,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.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java 2009-07-28
02:14:09 UTC (rev 5307)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/compress/CompressingUnMarshaller.java 2009-07-28
02:18:42 UTC (rev 5308)
@@ -25,8 +25,10 @@
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;
@@ -94,19 +96,28 @@
*/
public Object read(InputStream inputStream, Map metadata, int version) throws
IOException, ClassNotFoundException
{
- GZIPInputStream gzis = new GZIPInputStream(inputStream);
- ObjectInputStream ois =
SerializationStreamFactory.getManagerInstance(getSerializationType()).createRegularInput(gzis);
+ SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
+ BufferedInputStream bis = new BufferedInputStream(gzis);
+ SerializationManager manager =
SerializationStreamFactory.getManagerInstance(getSerializationType());
+ ObjectInputStream ois = manager.createRegularInput(bis);
- if(wrappedUnMarshaller != null)
+ try
{
- if (wrappedUnMarshaller instanceof VersionedUnMarshaller)
- return ((VersionedUnMarshaller)wrappedUnMarshaller).read(ois, metadata,
version);
+ if(wrappedUnMarshaller != null)
+ {
+ if (wrappedUnMarshaller instanceof VersionedUnMarshaller)
+ return ((VersionedUnMarshaller)wrappedUnMarshaller).read(ois, metadata,
version);
+ else
+ return wrappedUnMarshaller.read(ois, metadata);
+ }
else
- return wrappedUnMarshaller.read(ois, metadata);
+ {
+ return super.read(ois, metadata, version);
+ }
}
- else
+ finally
{
- return super.read(ois, metadata, version);
+ gzis.end();
}
}
@@ -122,5 +133,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
+ }
+ }
+
}
Show replies by date