Class HuffmanEncoder


  • public class HuffmanEncoder
    extends java.lang.Object

    Used to encode strings Huffman encoding.

    Characters are encoded with ISO-8859-1, if any multi-byte characters or control characters are present the encoder will throw EncodingException.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private HuffmanEncoder()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static void encode​(int[][] table, java.nio.ByteBuffer buffer, java.lang.String s)  
      static void encode​(java.nio.ByteBuffer buffer, java.lang.String s)  
      static void encodeLowerCase​(java.nio.ByteBuffer buffer, java.lang.String s)  
      static int octetsNeeded​(byte[] b)  
      private static int octetsNeeded​(int[][] table, java.lang.String s)  
      static int octetsNeeded​(java.lang.String s)  
      static int octetsNeededLowerCase​(java.lang.String s)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HuffmanEncoder

        private HuffmanEncoder()
    • Method Detail

      • octetsNeeded

        public static int octetsNeeded​(java.lang.String s)
        Parameters:
        s - the string to encode.
        Returns:
        the number of octets needed to encode the string, or -1 if it cannot be encoded.
      • octetsNeeded

        public static int octetsNeeded​(byte[] b)
        Parameters:
        b - the byte array to encode.
        Returns:
        the number of octets needed to encode the bytes, or -1 if it cannot be encoded.
      • encode

        public static void encode​(java.nio.ByteBuffer buffer,
                                  java.lang.String s)
        Parameters:
        buffer - the buffer to encode into.
        s - the string to encode.
      • octetsNeededLowerCase

        public static int octetsNeededLowerCase​(java.lang.String s)
        Parameters:
        s - the string to encode in lowercase.
        Returns:
        the number of octets needed to encode the string, or -1 if it cannot be encoded.
      • encodeLowerCase

        public static void encodeLowerCase​(java.nio.ByteBuffer buffer,
                                           java.lang.String s)
        Parameters:
        buffer - the buffer to encode into in lowercase.
        s - the string to encode.
      • octetsNeeded

        private static int octetsNeeded​(int[][] table,
                                        java.lang.String s)
      • encode

        private static void encode​(int[][] table,
                                   java.nio.ByteBuffer buffer,
                                   java.lang.String s)
        Parameters:
        table - The table to encode by
        buffer - The buffer to encode to
        s - The string to encode