public final class Base62 extends Object
Only positive numbers are supported. All methods in this class with throw an IllegalArgumentException
if a negative number is given. If you want to use negative numbers you'll have to handle prepending - to the Base62 string, that becomes a sort of Base62+1 string.
Here is sample code to handle negative numbers prepending - to them:
long number = -1234567890; String enc = ( Math.abs( number ) != number ? "-" : "" ) + Base62.encode( Math.abs( number ) ); long dec = enc.startsWith( "-" ) ? -Base62.decodeLong( enc.substring( 1 ) ) : Base62.decodeLong( enc );Note that this isn't true Base62 anymore.
Modifier and Type | Method and Description |
---|---|
static BigInteger |
decode(String base62String) |
static BigInteger |
decode(String base62String, Charset charset) |
static byte[] |
decodeBytes(String base62String) |
static byte[] |
decodeBytes(String base62String, Charset charset) |
static int |
decodeInt(String base62String) |
static int |
decodeInt(String base62String, Charset charset) |
static long |
decodeLong(String base62String) |
static long |
decodeLong(String base62String, Charset charset) |
static String |
encode(BigInteger number) |
static String |
encode(byte[] bytes) |
static String |
encode(Integer number) |
static String |
encode(Long number) |
public static BigInteger decode(String base62String)
public static BigInteger decode(String base62String, Charset charset)
public static int decodeInt(String base62String) throws ArithmeticException
ArithmeticException
public static int decodeInt(String base62String, Charset charset) throws ArithmeticException
ArithmeticException
public static long decodeLong(String base62String) throws ArithmeticException
ArithmeticException
public static long decodeLong(String base62String, Charset charset) throws ArithmeticException
ArithmeticException
public static byte[] decodeBytes(String base62String) throws ArithmeticException
ArithmeticException
public static byte[] decodeBytes(String base62String, Charset charset) throws ArithmeticException
ArithmeticException
public static String encode(byte[] bytes)
public static String encode(BigInteger number)