Class Base64OutputStream
java.lang.Object
java.io.OutputStream
org.simpleframework.common.encode.Base64OutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
The
Base64OutputStream
is used to write base64 text
in the form of a string through a conventional output stream. This
is provided for convenience so that it is possible to encode and
decode binary data as base64 for implementations that would
normally use a binary format.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for theBase64OutputStream
object.Base64OutputStream
(int capacity) Constructor for theBase64OutputStream
object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
This is used to close the stream and encode the buffered bytes to base64.private void
expand
(int capacity) This will expand the size of the internal buffer.toString()
This returns the base64 text encoded from the bytes written to the stream.void
write
(byte[] array, int offset, int length) This method is used to write data as base64 to an internal buffer.void
write
(int octet) This method is used to write data as base64 to an internal buffer.Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
encoded
private char[] encoded -
buffer
private byte[] buffer -
temp
private byte[] temp -
count
private int count
-
-
Constructor Details
-
Base64OutputStream
public Base64OutputStream()Constructor for theBase64OutputStream
object. A stream created with this constructor uses an initial capacity of one kilobyte, the capacity is increased as bytes are written. -
Base64OutputStream
public Base64OutputStream(int capacity) Constructor for theBase64OutputStream
object. A stream created with this constructor can have an initial capacity specified. Typically it is a good rule of thumb to use a capacity that is just over an additional third of the source binary data.- Parameters:
capacity
- this is the initial capacity of the buffer
-
-
Method Details
-
write
This method is used to write data as base64 to an internal buffer. ThetoString
method can be used to acquire the text encoded from the written binary data.- Specified by:
write
in classOutputStream
- Parameters:
octet
- the octet to encode in to the internal buffer- Throws:
IOException
-
write
This method is used to write data as base64 to an internal buffer. ThetoString
method can be used to acquire the text encoded from the written binary data.- Overrides:
write
in classOutputStream
- Parameters:
array
- the octets to encode to the internal bufferoffset
- this is the offset in the array to encode fromlength
- this is the number of bytes to be encoded- Throws:
IOException
-
expand
This will expand the size of the internal buffer. To allow for a variable length number of bytes to be written the internal buffer can grow as demand exceeds space available.- Parameters:
capacity
- this is the minimum capacity required- Throws:
IOException
-
close
This is used to close the stream and encode the buffered bytes to base64. Once this method is invoked no further data can be encoded with the stream. ThetoString
method can be used to acquire the base64 encoded text.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
toString
This returns the base64 text encoded from the bytes written to the stream. This is the primary means for acquiring the base64 encoded text once the stream has been closed.
-