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

static byte [] net::sf::linuxorg::pcal::common::Base64::decode ( String  s,
int  options 
) throws java.io.IOException [inline, static]

Decodes data from Base64 notation, automatically detecting gzip-compressed data and decompressing it.

Parameters:
sthe string to decode
optionsencode options such as URL_SAFE
Returns:
the decoded data
Exceptions:
java.io.IOExceptionif there is an error
NullPointerExceptionif s is null
Since:
1.4

Definition at line 1185 of file Base64.java.

References decode(), and PREFERRED_ENCODING.

                                                                                    {
        
        if( s == null ){
            throw new NullPointerException( "Input string was null." ); //$NON-NLS-1$
        }   // end if
        
        byte[] bytes;
        try {
            bytes = s.getBytes( PREFERRED_ENCODING );
        }   // end try
        catch( java.io.UnsupportedEncodingException uee ) {
            bytes = s.getBytes();
        }   // end catch
            //</change>
        
        // Decode
        bytes = decode( bytes, 0, bytes.length, options );
        
        
        // Check to see if it's gzip-compressed
        // GZIP Magic Two-Byte Number: 0x8b1f (35615)
        if( bytes != null && bytes.length >= 4 ) {
            
            int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00);       
            if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head )  {
                java.io.ByteArrayInputStream  bais = null;
                java.util.zip.GZIPInputStream gzis = null;
                java.io.ByteArrayOutputStream baos = null;
                byte[] buffer = new byte[2048];
                int    length = 0;

                try {
                    baos = new java.io.ByteArrayOutputStream();
                    bais = new java.io.ByteArrayInputStream( bytes );
                    gzis = new java.util.zip.GZIPInputStream( bais );

                    while( ( length = gzis.read( buffer ) ) >= 0 ) {
                        baos.write(buffer,0,length);
                    }   // end while: reading input

                    // No error? Get new bytes.
                    bytes = baos.toByteArray();

                }   // end try
                catch( java.io.IOException e ) {
                    // Just return originally-decoded bytes
                }   // end catch
                finally {
                    try{ baos.close(); } catch( Exception e ){}
                    try{ gzis.close(); } catch( Exception e ){}
                    try{ bais.close(); } catch( Exception e ){}
                }   // end finally

            }   // end if: gzipped
        }   // end if: bytes.length >= 2
        
        return bytes;
    }   // end decode

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index