Class BaseN


  • public final class BaseN
    extends Object
    Class that represents the base-n encodings.
    • Field Detail

      • BASE_16

        public static final BaseN BASE_16
      • BASE_32

        public static final BaseN BASE_32
      • BASE_32_HEX

        public static final BaseN BASE_32_HEX
      • BASE_32_CROCKFORD

        public static final BaseN BASE_32_CROCKFORD
      • BASE_36

        public static final BaseN BASE_36
      • BASE_58

        public static final BaseN BASE_58
      • BASE_58_BITCOIN

        public static final BaseN BASE_58_BITCOIN
      • BASE_58_FLICKR

        public static final BaseN BASE_58_FLICKR
      • BASE_62

        public static final BaseN BASE_62
      • BASE_64

        public static final BaseN BASE_64
      • BASE_64_URL

        public static final BaseN BASE_64_URL
    • Constructor Detail

      • BaseN

        public BaseN​(int radix)
        Public constructor for the base-n object. The radix is the alphabet size. The supported alphabet sizes are from 2 to 64. If there are mixed cases in the alphabet, the base-n is case SENSITIVE. The encoded string length is equal to `CEIL(128 / LOG2(n))`, where n is the radix. The encoded string is padded to fit the expected length. The padding character is the first character of the string. For example, the padding character for the alphabet "abcdef0123456" is 'a'. The example below shows how to create a BaseN for an hypothetical base-26 encoding that contains only letters. You only need to pass a number 40.
         String radix = 40;
         BaseN base = new BaseN(radix);
         
        If radix is greater than 36, the alphabet generated is a subset of the character sequence "0-9A-Za-z-_". Otherwise it is a subset of "0-9a-z". In the example above the resulting alphabet is "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd" (0-9A-Za-d).
        Parameters:
        radix - the radix to be used
      • BaseN

        public BaseN​(String alphabet)
        Public constructor for the base-n object. The radix is the alphabet size. The supported alphabet sizes are from 2 to 64. If there are mixed cases in the alphabet, the base-n is case SENSITIVE. The encoded string length is equal to `CEIL(128 / LOG2(n))`, where n is the radix. The encoded string is padded to fit the expected length. The padding character is the first character of the string. For example, the padding character for the alphabet "abcdef0123456" is 'a'. The example below shows how to create a BaseN for an hypothetical base-26 encoding that contains only letters. You only need to pass a string with 26 characters.
         String alphabet = "abcdefghijklmnopqrstuvwxyz";
         BaseN base = new BaseN(alphabet);
         
        Alphabet strings similar to "a-f0-9" are expanded to "abcdef0123456789". The same example using the string "a-z" instead of "abcdefghijklmnopqrstuvwxyz":
         String alphabet = "a-z";
         BaseN base = new BaseN(alphabet);
         
        Parameters:
        alphabet - the alphabet to be used
    • Method Detail

      • getRadix

        public int getRadix()
      • getLength

        public int getLength()
      • isSensitive

        public boolean isSensitive()
      • getPadding

        public char getPadding()
      • getAlphabet

        public CharArray getAlphabet()
      • validate

        public void validate​(char[] chars)
      • expand

        protected static String expand​(String string)
        Expands char sequences similar to 0-9, a-z and A-Z.
        Parameters:
        string - a string to be expanded
        Returns:
        a string