config-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/encodequery/Base64.java
public static String encodeObject(final java.io.Serializable serializableObject, final int options)
   {
      // Streams
      java.io.ByteArrayOutputStream baos = null;
      java.io.OutputStream b64os = null;
      java.io.ObjectOutputStream oos = null;
      java.util.zip.GZIPOutputStream gzos = null;

      // Isolate options
      int gzip = (options & GZIP);
      int dontBreakLines = (options & DONT_BREAK_LINES);

      try
      {
         // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
         baos = new java.io.ByteArrayOutputStream();
         b64os = new Base64.OutputStream(baos, ENCODE | dontBreakLines);

         // GZip?
         if (gzip == GZIP)
         {
            gzos = new java.util.zip.GZIPOutputStream(b64os);
            oos = new java.io.ObjectOutputStream(gzos);
         } // end if: gzip
         else
            oos = new java.io.ObjectOutputStream(b64os);

         oos.writeObject(serializableObject);
      } // end try
      catch (java.io.IOException e)
      {
         e.printStackTrace();
         return null;
      } // end catch
      finally
      {
         try
         {
            oos.close();
         }
         catch (Exception e)
         {}
         try
         {
            gzos.close();
         }
         catch (Exception e)
         {}
         try
         {
            b64os.close();
         }
         catch (Exception e)
         {}
         try
         {
            baos.close();
         }
         catch (Exception e)
         {}
      } // end finally

      // Return value according to relevant encoding.
      try
      {
         return new String(baos.toByteArray(), PREFERRED_ENCODING);
      } // end try
      catch (java.io.UnsupportedEncodingException uue)
      {
         return new String(baos.toByteArray());
      } // end catch

   }
public static String encodeObject(final java.io.Serializable serializableObject, final int options)
   {
      // Streams
      java.io.ByteArrayOutputStream baos = null;
      java.io.OutputStream b64os = null;
      java.io.ObjectOutputStream oos = null;
      java.util.zip.GZIPOutputStream gzos = null;

      // Isolate options
      int gzip = (options & GZIP);
      int dontBreakLines = (options & DONT_BREAK_LINES);

      try
      {
         // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
         baos = new java.io.ByteArrayOutputStream();
         b64os = new Base64.OutputStream(baos, ENCODE | dontBreakLines);

         // GZip?
         if (gzip == GZIP)
         {
            gzos = new java.util.zip.GZIPOutputStream(b64os);
            oos = new java.io.ObjectOutputStream(gzos);
         } // end if: gzip
         else
            oos = new java.io.ObjectOutputStream(b64os);

         oos.writeObject(serializableObject);
      } // end try
      catch (java.io.IOException e)
      {
         e.printStackTrace();
         return null;
      } // end catch
      finally
      {
         try
         {
            oos.close();
         }
         catch (Exception e)
         {}
         try
         {
            gzos.close();
         }
         catch (Exception e)
         {}
         try
         {
            b64os.close();
         }
         catch (Exception e)
         {}
         try
         {
            baos.close();
         }
         catch (Exception e)
         {}
      } // end finally

      // Return value according to relevant encoding.
      try
      {
         return new String(baos.toByteArray(), PREFERRED_ENCODING);
      } // end try
      catch (java.io.UnsupportedEncodingException uue)
      {
         return new String(baos.toByteArray());
      } // end catch

   }
Serializes an object and returns the Base64-encoded version of that serialized object. If the object cannot be
serialized or there is another error, the method will return <tt>null</tt>.
<p>
Valid options:

<pre>
GZIP: gzip-compresses object before encoding it.
DONT_BREAK_LINES: don't break lines at 76 characters
<i>Note: Technically, this makes your encoding non-compliant.</i>
</pre>
<p>
Example: <code>encodeObject( myObj, Base64.GZIP )</code> or
<p>
Example: <code>encodeObject( myObj, Base64.GZIP | Base64.DONT_BREAK_LINES )</code>

@param serializableObject The object to encode
@param options Specified options
@return The Base64-encoded object
@see Base64#GZIP
@see Base64#DONT_BREAK_LINES
@since 2.0