Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
 
 package org.jboss.remoting.marshal.compress;
 
 import java.util.Map;
 
CompressingMarshaller and CompressingUnMarshaller are a general purpose compressing marshaller / decompressing unmarshaller pair based on Java's GZIP facilities.

CompressingUnMarshaller is subclassed from SerializableUnMarshaller, and by default it uses super.read() to deserialize an object, once the object has been uncompressed. Optionally, it can wrap any other unmarshaller and use that instead of SerializableUnMarshaller to unmarshall an uncompressed input stream. For example,

new CompressingUnMarshaller(new HTTPUnMarshaller())

will create an umarshaller that uses an HTTPUnMarshaller to restore an uncompressed input stream.

Author(s):
Ron Sigal
Version:
$Revision: 5338 $

Copyright (c) 2005

 
 
 {
    public final static String DATATYPE = "compressible";
 
    private static final long serialVersionUID = 3843451434770746776L;


   
Create a new CompressingUnMarshaller.
 
    public CompressingUnMarshaller()
    {
    }


   
Create a new CompressingUnMarshaller.

Parameters:
unMarshaller unmarshaller to be used to restore uncompressed byte stream to original object
 
    public CompressingUnMarshaller(UnMarshaller unMarshaller)
    {
        = unMarshaller;
    }
    
    public InputStream getMarshallingStream(InputStream inputStreamthrows IOException
    {
       SelfCleaningGZipInputStream gzis = new SelfCleaningGZipInputStream(inputStream);
       return bis;
    }

   
Restores a compressed, marshalled form of an object to its original state.

Parameters:
inputStream InputStream from which marshalled form is to be retrieved
metadata can be any transport specific metadata (such as headers from http transport). This can be null, depending on if transport supports metadata.
version wire format version
Returns:
restored object
Throws:
java.io.IOException if there is a problem reading from inputStream
java.lang.ClassNotFoundException if there is a problem finding a class needed for unmarshalling
   public Object read(InputStream inputStreamMap metadataint versionthrows IOExceptionClassNotFoundException
   {
      SelfCleaningGZipInputStream gzis = null;
      DecomposableBufferedInputStream bis = null;
      
      if (inputStream instanceof DecomposableBufferedInputStream)
      {
         bis = (DecomposableBufferedInputStreaminputStream;
         gzis = (SelfCleaningGZipInputStreambis.getWrappedStream();
      }
      else
      {
         gzis = new SelfCleaningGZipInputStream(inputStream);
         bis = new DecomposableBufferedInputStream(gzis);
      }
      SerializationManager manager = SerializationStreamFactory.getManagerInstance(getSerializationType());
      ObjectInputStream ois =  manager.createRegularInput(bis);
      try
      {
         if( != null)
         {
            // HACK for JBREM-927.
            if ( instanceof HTTPUnMarshaller)
            {
               Map map = new HashMap();
               if (metadata != null)
                  map.putAll(metadata);
               map.put("Content-Length", Integer.toString(.));
               metadata = map;
            }
            if ( instanceof VersionedUnMarshaller)
               return ((VersionedUnMarshaller)).read(oismetadataversion);
            else
               return .read(oismetadata);
         }
         else
         {
            return super.read(oismetadataversion);
         }
      }
      finally
      {
         gzis.end();
      }
   }


   
Returns a new CompressingUnMarshaller

Returns:
a new CompressingUnMarshaller
Throws:
java.lang.CloneNotSupportedException In practice no exceptions are thrown.
   {
   }


   

Author(s):
Doychin Bondzhev
   static class SelfCleaningGZipInputStream extends GZIPInputStream
   {
      {
         super(in);
      }
      
      void refreshInflater()
      {
          = new Inflater(true);
         .reset();
      }
      void end() throws IOException
      {
         while(available() > 0) { // This will force input stream to read gzip trailer from input stream
            read();
         }
         .end(); // TO release resources used by native code
      }
   }
   
   {
      DecomposableBufferedInputStream(InputStream inint size)
      {
         super(insize);
      }
      {
         super(in);
      }
      
      {
         return ;
      }
   }
New to GrepCode? Check out our FAQ X