org.fcrepo.server.journal.helpers
Class EncodingBase64InputStream

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

public class EncodingBase64InputStream
extends Object

Wraps an InputStream with a Base64 encoder, so when you "read" from the stream, you don't get bytes from the InputStream, you get Strings of Base64-encoded characters.

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

Author:
Jim Blake

Field Summary
static int DEFAULT_BUFFER_SIZE
           
 
Constructor Summary
EncodingBase64InputStream(InputStream stream)
           
EncodingBase64InputStream(InputStream stream, int bufferSize)
           
 
Method Summary
 void close()
          Close the InputStream, and prevent any further reads.
 String read(int maxStringLength)
          Read encoded data from the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

EncodingBase64InputStream

public EncodingBase64InputStream(InputStream stream)
Parameters:
stream - the source of data bytes to be encoded.

EncodingBase64InputStream

public EncodingBase64InputStream(InputStream stream,
                                 int bufferSize)
Parameters:
stream - the source of data bytes to be encoded.
bufferSize - the maximum number of bytes to read at one time.
Throws:
IllegalArgumentException - if bufferSize is not between 10 and 1,000,000.
Method Detail

read

public String read(int maxStringLength)
            throws IOException
Read encoded data from the stream. Data is read in 3-byte multiples and encoded into 4-character sequences, per the Base64 specification. As many bytes as possible will be read, limited by the amount of data available and by the limitation of maxStringLength on the size of the resulting encoded String. Since the smallest unit of encoded data is 4 characters, maxStringLength must not be less than 4.

Parameters:
maxStringLength - the resulting String will be no longer than this.
Returns:
a String that is no longer than maxStringLength, or null if no data remains to be read.
Throws:
IllegalArgumentException - if maxStringLength is less than 4.
IllegalStateException - if called after the stream is closed.
IOException - from inner InputStream.

close

public void close()
           throws IOException
Close the InputStream, and prevent any further reads.

Throws:
IOException - from the inner InputStream


Copyright © 2011 DuraSpace. All Rights Reserved.