public final class Base64 extends Object
| Modifier and Type | Method and Description |
|---|---|
static char |
chr(@IntRange(from=0L,to=63L) int value)
Get the base 64 character for the value
Example:
Base64.chr(3); // 'd'
Base64.chr(Base64.ord('B')) == 'B';
|
static char |
chrMod(@NonNegative int value)
Get the base 64 character for the value,
but after applying a modulo on the value to ensure that the call will not fail
|
static int |
decode(String encoded)
Decode pseudo base64 value to int
Example:
Base64.decode("c"); // 2
Base64.decode("hk"); // 458
|
static @PolyLength String |
encode(@IntRange(from=0L,to=63L) byte[] data)
Encode a byte array to Base64 string
Example:
Base64.encode(new byte[] {2, 31}); // "cF"
|
static String |
encode(int value,
@IntRange(from=1L,to=6L) int length)
Encode an int value to pseudo base 64
Example:
Base64.encode(145, 2); // "cr"
Base64.encode(2, 3); // "aac"
|
static @IntRange(from=0L,to=63L) int |
ord(char c)
Get int value of base64 char
Example:
Base64.ord('d'); // 3
Base64.ord(Base64.chr(3)) == 3;
|
static byte[] |
toBytes(@PolyLength String encoded)
Decode a Base 64 string to a byte array
Each byte will represents the
ord(char) value of each characters
Example:
Base64.toBytes("cF"); // new byte[] {2, 31}
|
@Pure public static @IntRange(from=0L,to=63L) int ord(char c)
Base64.ord('d'); // 3
Base64.ord(Base64.chr(3)) == 3;
c - Char to convertIllegalArgumentException - When a character outside the charset is givenFor perform the opposite operation,
For decode an int string@Pure public static char chr(@IntRange(from=0L,to=63L) int value)
Base64.chr(3); // 'd'
Base64.chr(Base64.ord('B')) == 'B';
value - Value to encode. Must be in interval [0, 63]For perform the opposite operation,
For encode a 32 bits integer to a string@Pure public static char chrMod(@NonNegative int value)
value - Value to encode.@SideEffectFree public static String encode(int value, @IntRange(from=1L,to=6L) int length)
Base64.encode(145, 2); // "cr"
Base64.encode(2, 3); // "aac"
value - Value to encodelength - The expected result length. Must be between 1 and 6 includedIllegalArgumentException - When the length parameter is invalid@SideEffectFree public static @PolyLength String encode(@IntRange(from=0L,to=63L) byte[] data)
Base64.encode(new byte[] {2, 31}); // "cF"
data - Data to encodeFor the opposite operation@Pure public static int decode(String encoded)
Base64.decode("c"); // 2
Base64.decode("hk"); // 458
encoded - The encoded valueIllegalArgumentException - When an invalid string is given@SideEffectFree public static byte[] toBytes(@PolyLength String encoded)
ord(char) value of each characters
Example:
Base64.toBytes("cF"); // new byte[] {2, 31}
encoded - The encoded stringCopyright © 2022. All rights reserved.