com.planet_ink.coffee_mud.core
Class B64Encoder
java.lang.Object
com.planet_ink.coffee_mud.core.B64Encoder
public class B64Encoder
- extends java.lang.Object
Encodes and decodes to and from Base64 notation.
Change Log:
- v2.0.2 - Now specifies UTF-8 encoding in places where the code fails on systems
with other encodings (like EBCDIC).
- v2.0.1 - Fixed an error when decoding a single byte, that is, when the
encoded data was a single byte.
- v2.0 - I got rid of methods that used booleans to set options.
Now everything is more consolidated and cleaner. The code now detects
when data that's being decoded is gzip-compressed and will decompress it
automatically. Generally things are cleaner. You'll probably have to
change some method calls that you were making to support the new
options format (ints that you "OR" together).
- v1.5.1 - Fixed bug when decompressing and decoding to a
byte[] using decode( String s, boolean gzipCompressed ).
Added the ability to "suspend" encoding in the Output Stream so
you can turn on and off the encoding if you need to embed base64
data in an otherwise "normal" stream (like an XML file).
- v1.5 - Output stream pases on flush() command but doesn't do anything itself.
This helps when using GZIP streams.
Added the ability to GZip-compress objects before encoding them.
- v1.4 - Added helper methods to read/write files.
- v1.3.6 - Fixed OutputStream.flush() so that 'position' is reset.
- v1.3.5 - Added flag to turn on and off line breaks. Fixed bug in input stream
where last buffer being read, if not completely full, was not returned.
- v1.3.4 - Fixed when "improperly padded stream" error was thrown at the wrong time.
- v1.3.3 - Fixed I/O streams which were totally messed up.
I am placing this code in the Public Domain. Do with it as you will.
This software comes with no guarantees or warranties but with
plenty of well-wishing instead!
Please visit http://iharder.net/base64
periodically to check for updates or to contribute improvements.
|
Method Summary |
static byte[] |
B64decode(byte[] source,
int off,
int len)
|
static byte[] |
B64decode(java.lang.String s)
|
static byte[] |
B64decodeFromFile(java.lang.String filename)
|
static boolean |
B64decodeToFile(java.lang.String dataToDecode,
java.lang.String filename)
|
static java.lang.Object |
B64decodeToObject(java.lang.String encodedObject)
|
static java.lang.String |
B64encodeBytes(byte[] source)
|
static java.lang.String |
B64encodeBytes(byte[] source,
int options)
|
static java.lang.String |
B64encodeBytes(byte[] source,
int off,
int len)
|
static java.lang.String |
B64encodeBytes(byte[] source,
int off,
int len,
int options)
|
static java.lang.String |
B64encodeFromFile(java.lang.String filename)
|
static java.lang.String |
B64encodeObject(java.io.Serializable serializableObject)
|
static java.lang.String |
B64encodeObject(java.io.Serializable serializableObject,
int options)
|
static boolean |
B64encodeToFile(byte[] dataToEncode,
java.lang.String filename)
|
protected static int |
decode4to3(byte[] source,
int srcOffset,
byte[] destination,
int destOffset)
|
protected static byte[] |
encode3to4(byte[] b4,
byte[] threeBytes,
int numSigBytes)
|
protected static byte[] |
encode3to4(byte[] source,
int srcOffset,
int numSigBytes,
byte[] destination,
int destOffset)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NO_OPTIONS
public static final int NO_OPTIONS
- See Also:
- Constant Field Values
ENCODE
public static final int ENCODE
- See Also:
- Constant Field Values
DECODE
public static final int DECODE
- See Also:
- Constant Field Values
GZIP
public static final int GZIP
- See Also:
- Constant Field Values
DONT_BREAK_LINES
public static final int DONT_BREAK_LINES
- See Also:
- Constant Field Values
MAX_LINE_LENGTH
public static final int MAX_LINE_LENGTH
- See Also:
- Constant Field Values
EQUALS_SIGN
public static final byte EQUALS_SIGN
- See Also:
- Constant Field Values
NEW_LINE
public static final byte NEW_LINE
- See Also:
- Constant Field Values
PREFERRED_ENCODING
public static final java.lang.String PREFERRED_ENCODING
- See Also:
- Constant Field Values
_NATIVE_ALPHABET
public static final byte[] _NATIVE_ALPHABET
DECODABET
public static final byte[] DECODABET
WHITE_SPACE_ENC
public static final byte WHITE_SPACE_ENC
- See Also:
- Constant Field Values
EQUALS_SIGN_ENC
public static final byte EQUALS_SIGN_ENC
- See Also:
- Constant Field Values
encode3to4
protected static byte[] encode3to4(byte[] b4,
byte[] threeBytes,
int numSigBytes)
encode3to4
protected static byte[] encode3to4(byte[] source,
int srcOffset,
int numSigBytes,
byte[] destination,
int destOffset)
B64encodeObject
public static java.lang.String B64encodeObject(java.io.Serializable serializableObject)
B64encodeObject
public static java.lang.String B64encodeObject(java.io.Serializable serializableObject,
int options)
B64encodeBytes
public static java.lang.String B64encodeBytes(byte[] source)
B64encodeBytes
public static java.lang.String B64encodeBytes(byte[] source,
int options)
B64encodeBytes
public static java.lang.String B64encodeBytes(byte[] source,
int off,
int len)
B64encodeBytes
public static java.lang.String B64encodeBytes(byte[] source,
int off,
int len,
int options)
decode4to3
protected static int decode4to3(byte[] source,
int srcOffset,
byte[] destination,
int destOffset)
B64decode
public static byte[] B64decode(byte[] source,
int off,
int len)
B64decode
public static byte[] B64decode(java.lang.String s)
B64decodeToObject
public static java.lang.Object B64decodeToObject(java.lang.String encodedObject)
B64encodeToFile
public static boolean B64encodeToFile(byte[] dataToEncode,
java.lang.String filename)
B64decodeToFile
public static boolean B64decodeToFile(java.lang.String dataToDecode,
java.lang.String filename)
B64decodeFromFile
public static byte[] B64decodeFromFile(java.lang.String filename)
B64encodeFromFile
public static java.lang.String B64encodeFromFile(java.lang.String filename)