类 Base62
- java.lang.Object
-
- net.qimooc.commons.utils.Base62
-
public class Base62 extends java.lang.ObjectBase62 numbers/strings encoding/decoding utility methods.Only positive numbers are supported. All methods in this class with throw an
IllegalArgumentExceptionif 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.
-
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static java.math.BigIntegerdecode(java.lang.String base62String)static java.math.BigIntegerdecode(java.lang.String base62String, java.nio.charset.Charset charset)static byte[]decodeBytes(java.lang.String base62String)static byte[]decodeBytes(java.lang.String base62String, java.nio.charset.Charset charset)static intdecodeInt(java.lang.String base62String)static intdecodeInt(java.lang.String base62String, java.nio.charset.Charset charset)static longdecodeLong(java.lang.String base62String)static longdecodeLong(java.lang.String base62String, java.nio.charset.Charset charset)static java.lang.Stringencode(byte[] bytes)static java.lang.Stringencode(java.lang.Integer number)static java.lang.Stringencode(java.lang.Long number)static java.lang.Stringencode(java.math.BigInteger number)
-
-
-
方法详细资料
-
decode
public static java.math.BigInteger decode(java.lang.String base62String)
-
decode
public static java.math.BigInteger decode(java.lang.String base62String, java.nio.charset.Charset charset)
-
decodeInt
public static int decodeInt(java.lang.String base62String) throws java.lang.ArithmeticException- 抛出:
java.lang.ArithmeticException
-
decodeInt
public static int decodeInt(java.lang.String base62String, java.nio.charset.Charset charset) throws java.lang.ArithmeticException- 抛出:
java.lang.ArithmeticException
-
decodeLong
public static long decodeLong(java.lang.String base62String) throws java.lang.ArithmeticException- 抛出:
java.lang.ArithmeticException
-
decodeLong
public static long decodeLong(java.lang.String base62String, java.nio.charset.Charset charset) throws java.lang.ArithmeticException- 抛出:
java.lang.ArithmeticException
-
decodeBytes
public static byte[] decodeBytes(java.lang.String base62String) throws java.lang.ArithmeticException- 抛出:
java.lang.ArithmeticException
-
decodeBytes
public static byte[] decodeBytes(java.lang.String base62String, java.nio.charset.Charset charset) throws java.lang.ArithmeticException- 抛出:
java.lang.ArithmeticException
-
encode
public static java.lang.String encode(java.lang.Integer number)
-
encode
public static java.lang.String encode(java.lang.Long number)
-
encode
public static java.lang.String encode(byte[] bytes)
-
encode
public static java.lang.String encode(java.math.BigInteger number)
-
-