java.lang.Object
net.i2p.data.Base32
Encodes and decodes to and from Base32 notation. Ref: RFC 3548
Don't bother with '=' padding characters on encode or accept them on decode (i.e. don't require 5-character groups). No whitespace allowed.
Decode accepts upper or lower case.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char[]The 32 valid Base32 values.private static final byteValue marking an invalid encoding character.private static final byte[]Translates a Base32 value to either its 5-bit reconstruction value or a negative number indicating some other meaning.private static final byte[]Bit masks for reassembling bytes from groups.private static final byte[]Bit masks for pulling groups out of a byte.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static byte[]decode(byte[] source) Decodes Base32 content in byte array format and returns the decoded byte array.private static voiddecode(InputStream in, OutputStream out) Writes the base32 text decoded.static byte[]Case-insensitive.static StringDecodes data from Base32 notation and returns it as a string.static Stringencode(byte[] source) Returns lower case.private static voidencode(InputStream in, OutputStream out) Writes the stream base32-encoded.static StringReturns lower case.private static voidencodeBytes(byte[] source, StringBuilder out) Encodes a byte array into Base32 notation.private static voidhelp()Prints the command-line usage.static voidRun the Base32 command-line utility.private static byte[]read(InputStream in) Reads a stream fully.private static voidRuns the command-line encoder or decoder.
Field Details
ALPHABET
private static final char[] ALPHABETThe 32 valid Base32 values.DECODABET
private static final byte[] DECODABETTranslates a Base32 value to either its 5-bit reconstruction value or a negative number indicating some other meaning. Allow upper or lower case.BAD_ENCODING
private static final byte BAD_ENCODINGValue marking an invalid encoding character.- See Also:
emask
private static final byte[] emaskBit masks for pulling groups out of a byte.dmask
private static final byte[] dmaskBit masks for reassembling bytes from groups.
Constructor Details
Base32
private Base32()Defeats instantiation.
Method Details
main
Run the Base32 command-line utility.- Parameters:
args- the subcommand and its operands, as documented by the usage message printed when args is empty
runApp
Runs the command-line encoder or decoder.- Parameters:
args- the command-line arguments
read
Reads a stream fully.- Parameters:
in- the stream to read- Returns:
- the bytes read
- Throws:
IOException- if the stream cannot be read
encode
Writes the stream base32-encoded.- Parameters:
in- the bytes to encodeout- where the text is written- Throws:
IOException- if either stream fails
decode
Writes the base32 text decoded.- Parameters:
in- the text to decodeout- where the bytes are written- Throws:
IOException- if either stream fails
help
private static void help()Prints the command-line usage.encode
encode
Returns lower case. Does not add trailing '='.- Parameters:
source- The data to convert non-null- Returns:
- the Base32-encoded string
encodeBytes
Encodes a byte array into Base32 notation.- Parameters:
source- The data to convert non-nullout- the output buffer
decodeToString
decode
Case-insensitive. Does not allow trailing '='.- Parameters:
s- non-null- Returns:
- decoded data, null on error
decode
private static byte[] decode(byte[] source) Decodes Base32 content in byte array format and returns the decoded byte array.- Parameters:
source- The Base32 encoded data non-null- Returns:
- decoded data, null on error