Class Base64OutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.simpleframework.common.encode.Base64OutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class Base64OutputStream extends java.io.OutputStream
TheBase64OutputStream
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.- Author:
- Niall Gallagher
- See Also:
Base64Encoder
-
-
Constructor Summary
Constructors Constructor Description Base64OutputStream()
Constructor for theBase64OutputStream
object.Base64OutputStream(int capacity)
Constructor for theBase64OutputStream
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
This is used to close the stream and encode the buffered bytes to base64.java.lang.String
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.
-
-
-
Constructor Detail
-
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 Detail
-
write
public void write(int octet) throws java.io.IOException
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 classjava.io.OutputStream
- Parameters:
octet
- the octet to encode in to the internal buffer- Throws:
java.io.IOException
-
write
public void write(byte[] array, int offset, int length) throws java.io.IOException
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 classjava.io.OutputStream
- 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:
java.io.IOException
-
close
public void close() throws java.io.IOException
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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.OutputStream
- Throws:
java.io.IOException
-
toString
public java.lang.String 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.- Overrides:
toString
in classjava.lang.Object
- Returns:
- this returns the base64 text encoded
-
-