Convenience method for decoding data to a file. 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. @param dataToDecode Base64-encode
( String dataToDecode, String filename )
| 1426 | * @since 2.1 |
| 1427 | */ |
| 1428 | public static void decodeToFile( String dataToDecode, String filename ) |
| 1429 | throws java.io.IOException { |
| 1430 | |
| 1431 | Base64.OutputStream bos = null; |
| 1432 | try{ |
| 1433 | bos = new Base64.OutputStream( |
| 1434 | new java.io.FileOutputStream( filename ), Base64.DECODE ); |
| 1435 | bos.write( dataToDecode.getBytes( PREFERRED_ENCODING ) ); |
| 1436 | } // end try |
| 1437 | catch( java.io.IOException e ) { |
| 1438 | throw e; // Catch and throw to execute finally{} block |
| 1439 | } // end catch: java.io.IOException |
| 1440 | finally { |
| 1441 | try{ bos.close(); } catch( Exception e ){} |
| 1442 | } // end finally |
| 1443 | |
| 1444 | } // end decodeToFile |
| 1445 | |
| 1446 | |
| 1447 |