Base64.OutputStream b64os = new Base64.OutputStream(baos, ENCODE | options); java.util.zip.GZIPOutputStream gzos = null;
/** * Convenience method for decoding data to a file. * * @param dataToDecode Base64-encoded data as a string * @param filename Filename for saving decoded data * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @throws IOException if there is a problem writing to the file */ public static boolean decodeToFile( String dataToDecode, String filename ) throws IOException { boolean error = false; Base64.OutputStream bos = new Base64.OutputStream(new FileOutputStream(filename), Base64.DECODE); try { bos.write(dataToDecode.getBytes(PREFERRED_ENCODING)); return true; } catch (IOException e) { error = true; throw e; } finally { try { bos.close(); } catch (IOException e) { if (!error) throw e; } } }
/** * Flushes and closes (I think, in the superclass) the stream. * * @throws IOException * @since 1.3 */ @Override public void close() throws IOException { try { // 1. Ensure that pending characters are written flushBase64(); } finally { // 2. Actually close the stream // Base class both flushes and closes. super.close(); buffer = null; out = null; } }
java.io.OutputStream b64os = new Base64.OutputStream(baos, ENCODE | options); java.io.ObjectOutputStream oos = null; java.util.zip.GZIPOutputStream gzos = null;
CheckArg.isNotNull(source, "source"); java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); Base64.OutputStream b64os = new Base64.OutputStream(baos, ENCODE | options); BufferedInputStream input = new BufferedInputStream(source); java.io.OutputStream output = b64os;
/** * Convenience method for encoding data to a file. * * @param dataToEncode byte array of data to encode in base64 form * @param filename Filename for saving encoded data * @return <tt>true</tt> if successful, <tt>false</tt> otherwise * @throws IOException if there is a problem writing to the file */ public static boolean encodeToFile( byte[] dataToEncode, String filename ) throws IOException { boolean error = false; Base64.OutputStream bos = new Base64.OutputStream(new java.io.FileOutputStream(filename), Base64.ENCODE); try { bos.write(dataToEncode); return true; } catch (IOException e) { error = true; throw e; } finally { try { bos.close(); } catch (IOException e) { if (!error) throw e; } } }
/** * Calls {@link #write(int)} repeatedly until <var>len</var> bytes are written. * * @param theBytes array from which to read bytes * @param off offset for array * @param len max number of bytes to read into array * @throws IOException * @since 1.3 */ @Override public void write( byte[] theBytes, int off, int len ) throws IOException { // Encoding suspended? if (suspendEncoding) { super.out.write(theBytes, off, len); return; } for (int i = 0; i < len; i++) { write(theBytes[off + i]); } }
/** * Suspends encoding of the stream. May be helpful if you need to embed a piece of base640-encoded data in a stream. * * @throws IOException * @since 1.5.1 */ public void suspendEncoding() throws IOException { flushBase64(); this.suspendEncoding = true; }