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

static byte [] net::sf::linuxorg::pcal::common::Base64::decodeFromFile ( String  filename ) throws java.io.IOException [inline, static]

Convenience method for reading a base64-encoded file and decoding it.

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

Parameters:
filenameFilename for reading encoded data
Returns:
decoded byte array
Exceptions:
java.io.IOExceptionif there is an error
Since:
2.1

Definition at line 1375 of file Base64.java.

References DECODE.

Referenced by decodeFileToFile().

                               {
        
        byte[] decodedData = null;
        Base64.InputStream bis = null;
        try
        {
            // Set up some useful variables
            java.io.File file = new java.io.File( filename );
            byte[] buffer = null;
            int length   = 0;
            int numBytes = 0;
            
            // Check for size of file
            if( file.length() > Integer.MAX_VALUE )
            {
                throw new java.io.IOException( "File is too big for this convenience method (" + file.length() + " bytes)." ); //$NON-NLS-1$ //$NON-NLS-2$
            }   // end if: file too big for int index
            buffer = new byte[ (int)file.length() ];
            
            // Open a stream
            bis = new Base64.InputStream( 
                      new java.io.BufferedInputStream( 
                      new java.io.FileInputStream( file ) ), Base64.DECODE );
            
            // Read until done
            while( ( numBytes = bis.read( buffer, length, 4096 ) ) >= 0 ) {
                length += numBytes;
            }   // end while
            
            // Save in a variable to return
            decodedData = new byte[ length ];
            System.arraycopy( buffer, 0, decodedData, 0, length );
            
        }   // end try
        catch( java.io.IOException e ) {
            throw e; // Catch and release to execute finally{}
        }   // end catch: java.io.IOException
        finally {
            try{ bis.close(); } catch( Exception e) {}
        }   // end finally
        
        return decodedData;
    }   // end decodeFromFile

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index