Logo Search packages:      
Sourcecode: pcalendar version File versions  Download package

static String net::sf::linuxorg::pcal::common::Base64::encodeObject ( java.io.Serializable  serializableObject,
int  options 
) throws java.io.IOException [inline, static]

Serializes an object and returns the Base64-encoded version of that serialized object.

As of v 2.3, if the object cannot be serialized or there is another error, the method will throw an java.io.IOException. This is new to v2.3! In earlier versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it.

The object is not GZip-compressed before being encoded.

Example options:

   GZIP: gzip-compresses object before encoding it.
   DO_BREAK_LINES: break lines at 76 characters
 

Example: encodeObject( myObj, Base64.GZIP ) or

Example: encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES )

Parameters:
serializableObjectThe object to encode
optionsSpecified options
Returns:
The Base64-encoded object
See also:
Base64::GZIP
Base64::DO_BREAK_LINES
Exceptions:
java.io.IOExceptionif there is an error
Since:
2.0

Definition at line 625 of file Base64.java.

References ENCODE, and PREFERRED_ENCODING.

                               {

        if( serializableObject == null ){
            throw new NullPointerException( "Cannot serialize a null object." ); //$NON-NLS-1$
        }   // end if: null
        
        // Streams
        java.io.ByteArrayOutputStream  baos  = null; 
        java.io.OutputStream           b64os = null; 
        java.io.ObjectOutputStream     oos   = null; 
        
        
        try {
            // ObjectOutputStream -> (GZIP) -> Base64 -> ByteArrayOutputStream
            // Note that the optional GZIPping is handled by Base64.OutputStream.
            baos  = new java.io.ByteArrayOutputStream();
            b64os = new Base64.OutputStream( baos, ENCODE | options );
            oos   = new java.io.ObjectOutputStream( b64os );
            oos.writeObject( serializableObject );
        }   // end try
        catch( java.io.IOException e ) {
            // Catch it and then throw it immediately so that
            // the finally{} block is called for cleanup.
            throw e;
        }   // end catch
        finally {
            try{ oos.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){
            // Fall back to some Java default
            return new String( baos.toByteArray() );
        }   // end catch
        
    }   // end encode

Generated by  Doxygen 1.6.0   Back to index