org.fcrepo.server.journal.helpers
Class DecodingBase64OutputStream

java.lang.Object
  extended by org.fcrepo.server.journal.helpers.DecodingBase64OutputStream

public class DecodingBase64OutputStream
extends Object

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).

Author:
Jim Blake

Constructor Summary
DecodingBase64OutputStream(OutputStream stream)
           
 
Method Summary
 void close()
          Close the writer.
 void write(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(OutputStream stream)
Parameters:
stream - the destination for the decoded bytes.
Method Detail

write

public void write(String data)
           throws 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:
IllegalStateException - if called after close().
IOException - from the inner OutputStream.

close

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

Throws:
IOException - from the inner OutputStream.


Copyright © 2012 DuraSpace. All Rights Reserved.