public class Base64Encoder
extends java.io.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);
| Constructor and Description |
|---|
Base64Encoder(java.io.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 java.lang.String |
encode(byte[] bytes)
Returns the encoded form of the given unencoded string.
|
static java.lang.String |
encode(java.lang.String unencoded)
Returns the encoded form of the given unencoded string.
|
static void |
main(java.lang.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.
|
public Base64Encoder(java.io.OutputStream out)
out - the output streampublic void write(int b)
throws java.io.IOException
write in class java.io.FilterOutputStreamjava.io.IOException - if an I/O error occurspublic void write(byte[] buf,
int off,
int len)
throws java.io.IOException
write in class java.io.FilterOutputStreambuf - the data to be writtenoff - the start offset of the datalen - the length of the datajava.io.IOException - if an I/O error occurspublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.FilterOutputStreamjava.io.IOException - if an I/O error occurspublic static java.lang.String encode(java.lang.String unencoded)
unencoded - the string to encodepublic static java.lang.String encode(byte[] bytes)
bytes - the bytes to encodepublic static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception