public class Base64Encoder extends FilterOutputStream
This class can be used for encoding strings:
or for encoding streams:String unencoded = "webmaster:try2gueSS"; String encoded = Base64Encoder.encode(unencoded);
OutputStream out = new Base64Encoder(System.out);
Modifier and Type | Field and Description |
---|---|
private int |
carryOver |
private int |
charCount |
private static char[] |
chars |
out
Constructor and Description |
---|
Base64Encoder(OutputStream out)
Constructs a new Base64 encoder that writes output to the given
OutputStream.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the stream, this MUST be called to ensure proper padding is
written to the end of the output stream.
|
static String |
encode(byte[] bytes)
Returns the encoded form of the given unencoded string.
|
static String |
encode(String unencoded)
Returns the encoded form of the given unencoded string.
|
static void |
main(String[] args) |
void |
write(byte[] buf,
int off,
int len)
Writes the given byte array to the output stream in an
encoded form.
|
void |
write(int b)
Writes the given byte to the output stream in an encoded form.
|
flush, write
private static final char[] chars
private int charCount
private int carryOver
public Base64Encoder(OutputStream out)
out
- the output streampublic void write(int b) throws IOException
write
in class FilterOutputStream
IOException
- if an I/O error occurspublic void write(byte[] buf, int off, int len) throws IOException
write
in class FilterOutputStream
b
- the data to be writtenoff
- the start offset of the datalen
- the length of the dataIOException
- if an I/O error occurspublic void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterOutputStream
IOException
- if an I/O error occurspublic static String encode(String unencoded)
unencoded
- the string to encodepublic static String encode(byte[] bytes)
unencoded
- the string to encodeWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses