fedora.server.journal.helpers
Class DecodingBase64OutputStream

java.lang.Object
  extended by fedora.server.journal.helpers.DecodingBase64OutputStream

public class DecodingBase64OutputStream
extends java.lang.Object

Title: DecodingBase64OutputStream.java

Description: Wraps an OutputStream with a Base64 decoder, so when you "write" to the stream, you write Strings of Base64-encoded characters, but the OutputStream receives decoded bytes.

Base64 encoding is defined in Internet RFC 3548, found at http://tools.ietf.org/html/rfc3548 (among other places).

Version:
$Id: DecodingBase64OutputStream.java 5025 2006-09-01 22:08:17 +0000 (Fri, 01 Sep 2006) cwilper $
Author:
jblake@cs.cornell.edu

Constructor Summary
DecodingBase64OutputStream(java.io.OutputStream stream)
           
 
Method Summary
 void close()
          Close the writer.
 void write(java.lang.String data)
          Add Base64-encoded characters to be decoded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DecodingBase64OutputStream

public DecodingBase64OutputStream(java.io.OutputStream stream)
Parameters:
stream - the destination for the decoded bytes.
Method Detail

write

public void write(java.lang.String data)
           throws java.io.IOException
Add Base64-encoded characters to be decoded. This is not a trivial operation for two reasons: any characters that are not valid for Base64-encoding must be ignored, and we can only decode groups of 4 characters. So, when data is received, we remove any invalid characters and then strip off any trailing characters that don't fit in the 4-character groups. Those trailing characters will be prefixed to the next set of data, and hopefully we will have none left over when the writer is closed.

Throws:
java.lang.IllegalStateException - if called after close().
java.io.IOException - from the inner OutputStream.

close

public void close()
           throws java.io.IOException
Close the writer. If there are any residual characters at this point, the data stream was not a valid Base64 encoding.

Throws:
java.io.IOException - from the inner OutputStream.