1. #1
    U-Labs Plus-Mitglied

    Registriert seit
    06.11.2011
    Beiträge
    418
    Thanked 686 Times in 246 Posts

    Standard [Java] Huffman

    Huffman.java
    Code:
    /**
     *
     * @author Flav
     */
    public class Huffman {
    	private static HuffmanEncoder encoder;
    	private static HuffmanDecoder decoder;
    
    	static {
    		String tree = new String(new char[] { 8, 121, 239, 124, 47, 115, 101, 114, 118, 101, 114, 112, 112, 32, 34, 30, 116, 116, 9, 68, 33, 101, 97, 34, 117, 100, 15, 131, 17, 1079, 18, 218, 18, 222, 16, 8364, 15, 8254, 15, 133, 33, 252, 114, 12, 200, 53, 83, 116, 101, 53, 101, 99, 107, 31, 48, 54, 95, 77, 97, 102, 105, 97, 34, 54, 55, 34, 78, 73, 34, 108, 98, 34, 111, 117, 6, 35, 5, 10, 4, 176, 31, 115, 105, 52, 112, 108, 97, 31, 116, 105, 52, 102, 111, 114, 8, 12, 53, 98, 111, 121, 11, 13, 53, 109, 97, 110, 33, 75, 108, 34, 57, 55, 34, 117, 98, 53, 117, 114, 103, 53, 107, 116, 101, 32, 79, 75, 32, 117, 101, 8, 98, 32, 111, 112, 33, 101, 118, 33, 79, 98, 54, 112, 101, 114, 33, 75, 111, 32, 77, 111, 93, 95, 176, 62, 95, 104, 8, 109, 31, 100, 105, 31, 114, 97, 11, 106, 15, 130, 18, 970, 18, 217, 17, 198, 16, 353, 15, 185, 16, 9644, 17, 201, 17, 248, 34, 53, 51, 34, 108, 104, 14, 8226, 14, 96, 31, 112, 121, 30, 49, 51, 30, 110, 110, 7, 227, 32, 114, 99, 200, 95, 110, 105, 99, 107, 108, 105, 115, 116, 95, 32, 101, 102, 53, 98, 114, 97, 31, 101, 101, 53, 116, 101, 110, 32, 110, 99, 52, 63, 100, 61, 32, 87, 111, 34, 55, 55, 13, 250, 33, 57, 52, 52, 105, 110, 103, 11, 14, 32, 48, 50, 31, 68, 101, 31, 97, 117, 33, 82, 117, 34, 111, 121, 34, 107, 109, 53, 101, 105, 103, 32, 69, 115, 33, 107, 115, 33, 79, 108, 8, 53, 9, 69, 31, 105, 105, 11, 22, 34, 109, 102, 34, 70, 111, 34, 115, 107, 16, 178, 17, 9565, 17, 158, 18, 64380, 18, 65185, 18, 65190, 18, 8217, 17, 281, 18, 64398, 18, 65270, 14, 21, 32, 69, 114, 54, 117, 115, 101, 33, 79, 110, 32, 111, 108, 33, 56, 57, 34, 107, 246, 34, 90, 101, 52, 97, 114, 116, 31, 114, 105, 8, 119, 32, 99, 111, 14, 25, 14, 196, 34, 67, 116, 33, 118, 97, 31, 98, 105, 52, 108, 105, 110, 32, 104, 114, 32, 105, 100, 32, 100, 111, 32, 110, 107, 32, 120, 120, 34, 119, 98, 14, 24, 16, 1082, 16, 205, 15, 139, 34, 112, 104, 34, 102, 119, 53, 110, 111, 99, 32, 119, 101, 52, 121, 101, 114, 31, 102, 101, 32, 107, 111, 32, 104, 116, 31, 109, 105, 53, 49, 48, 48, 32, 51, 49, 7, 51, 7, 108, 10, 87, 31, 102, 99, 34, 107, 252, 15, 1074, 16, 249, 18, 1171, 18, 8482, 17, 1072, 14, 180, 33, 105, 122, 32, 48, 57, 31, 66, 78, 30, 105, 109, 9, 1, 50, 0, 112, 0, 33, 75, 114, 34, 79, 111, 34, 101, 103, 53, 80, 117, 110, 32, 121, 108, 32, 101, 104, 32, 82, 111, 32, 83, 117, 33, 120, 101, 54, 104, 101, 108, 53, 104, 108, 116, 31, 101, 116, 31, 115, 109, 10, 77, 32, 112, 97, 32, 51, 56, 9, 122, 33, 70, 108, 33, 52, 56, 32, 117, 102, 53, 75, 110, 117, 32, 78, 105, 32, 104, 105, 34, 108, 122, 13, 220, 54, 104, 101, 114, 32, 83, 111, 34, 83, 252, 34, 117, 104, 15, 8594, 15, 9617, 14, 1085, 34, 114, 252, 30, 70, 104, 52, 77, 105, 110, 31, 98, 97, 31, 112, 108, 94, 48, 44, 48, 44, 48, 30, 49, 55, 30, 32, 32, 53, 98, 105, 110, 33, 71, 108, 33, 78, 117, 115, 77, 97, 102, 105, 97, 50, 31, 100, 97, 33, 82, 104, 54, 107, 101, 110, 32, 83, 108, 10, 73, 137, 107, 110, 117, 100, 100, 101, 108, 32, 70, 98, 31, 66, 111, 33, 84, 111, 34, 122, 97, 16, 402, 17, 181, 17, 9619, 15, 134, 14, 1080, 33, 71, 111, 33, 53, 54, 53, 111, 105, 115, 32, 99, 101, 10, 78, 32, 48, 51, 33, 114, 98, 33, 104, 110, 53, 114, 105, 101, 33, 74, 101, 33, 68, 114, 8, 52, 53, 70, 117, 223, 33, 74, 117, 34, 110, 121, 34, 89, 111, 31, 51, 54, 53, 104, 101, 105, 34, 53, 56, 34, 111, 118, 12, 36, 31, 66, 66, 8, 38, 94, 66, 105, 110, 103, 111, 53, 108, 105, 101, 33, 98, 121, 33, 73, 103, 52, 115, 116, 101, 10, 17, 7, 50, 10, 71, 32, 105, 99, 54, 107, 108, 101, 18, 65275, 18, 1071, 17, 1106, 16, 224, 16, 1751, 18, 1077, 18, 193, 18, 213, 18, 9474, 17, 238, 17, 9556, 16, 127, 15, 214, 34, 54, 52, 31, 115, 101, 31, 50, 51, 31, 110, 103, 32, 119, 97, 33, 68, 252, 33, 102, 108, 31, 97, 114, 32, 114, 115, 32, 66, 105, 132, 0, 112, 0, 66, 0, 45, 0, 7, 245, 7, 44, 8, 194, 52, 117, 116, 101, 31, 118, 101, 10, 64, 33, 115, 108, 33, 97, 99, 32, 72, 101, 7, 66, 29, 50, 48, 32, 87, 105, 34, 99, 108, 34, 77, 246, 33, 100, 109, 31, 77, 97, 30, 108, 101, 7, 105, 32, 111, 116, 34, 115, 99, 34, 117, 117, 12, 9, 10, 83, 53, 103, 101, 98, 32, 77, 101, 255, 16, 11, 102, 101, 109, 97, 108, 101, 46, 98, 46, 109, 121, 95, 52, 46, 103, 105, 102, 32, 116, 108, 30, 49, 54, 52, 99, 104, 116, 34, 108, 228, 34, 112, 117, 34, 115, 98, 34, 53, 49, 53, 70, 105, 102, 32, 57, 48, 53, 101, 114, 104, 52, 50, 53, 53, 10, 75, 31, 105, 103, 8, 124, 30, 109, 97, 32, 50, 57, 34, 65, 109, 15, 9835, 16, 8250, 17, 157, 17, 160, 17, 254, 17, 8592, 17, 153, 17, 321, 15, 1084, 33, 75, 246, 53, 118, 111, 110, 32, 75, 105, 34, 228, 117, 34, 67, 101, 34, 55, 56, 34, 71, 105, 32, 110, 117, 52, 103, 101, 110, 32, 100, 117, 54, 77, 97, 114, 33, 114, 117, 33, 118, 111, 33, 106, 117, 13, 8467, 34, 98, 115, 54, 117, 104, 112, 219, 70, 111, 116, 111, 67, 111, 110, 116, 101, 115, 116, 32, 67, 112, 54, 116, 111, 114, 54, 114, 101, 97, 32, 122, 105, 74, 107, 97, 110, 110, 30, 108, 108, 9, 63, 8, 251, 8, 190, 32, 109, 112, 33, 108, 110, 54, 83, 112, 105, 31, 117, 115, 30, 115, 116, 33, 114, 102, 13, 6, 13, 143, 32, 102, 102, 32, 115, 104, 33, 52, 52, 33, 73, 99, 52, 104, 97, 116, 32, 106, 97, 54, 46, 119, 95, 12, 20, 8, 103, 32, 50, 55, 34, 65, 114, 13, 1108, 33, 252, 98, 31, 105, 101, 30, 49, 48, 54, 85, 110, 100, 54, 105, 101, 115, 33, 57, 49, 14, 182, 15, 233, 16, 216, 18, 331, 18, 9600, 17, 231, 34, 73, 73, 32, 103, 111, 33, 111, 98, 12, 39, 219, 107, 110, 117, 100, 100, 101, 108, 115, 46, 100, 101, 8, 120, 10, 91, 53, 110, 103, 101, 33, 108, 116, 34, 56, 56, 34, 90, 105, 32, 78, 97, 32, 70, 97, 10, 93, 8, 188, 10, 228, 53, 97, 117, 115, 74, 115, 105, 99, 104, 72, 105, 99, 111, 110, 9, 54, 12, 9608, 33, 71, 114, 32, 112, 111, 31, 51, 48, 7, 62, 52, 83, 99, 104, 54, 112, 97, 114, 33, 101, 121, 33, 71, 97, 54, 78, 111, 114, 93, 109, 97, 102, 105, 97, 30, 49, 50, 33, 74, 97, 33, 115, 252, 15, 184, 15, 138, 15, 27, 15, 135, 34, 246, 110, 54, 109, 97, 103, 52, 118, 101, 114, 32, 71, 101, 11, 164, 31, 50, 50, 33, 97, 103, 34, 55, 50, 14, 144, 15, 244, 15, 136, 53, 104, 97, 108, 31, 50, 49, 32, 114, 111, 33, 80, 115, 34, 53, 57, 34, 70, 117, 31, 108, 97, 32, 54, 48, 11, 80, 53, 83, 116, 117, 33, 109, 117, 34, 65, 97, 34, 54, 50, 7, 110, 7, 58, 32, 100, 116, 54, 79, 78, 76, 33, 57, 50, 94, 124, 47, 103, 111, 32, 136, 67, 104, 97, 110, 110, 101, 108, 53, 98, 101, 105, 32, 72, 105, 9, 2, 9, 56, 9, 102, 52, 50, 48, 48, 34, 102, 111, 34, 104, 109, 54, 114, 111, 115, 32, 103, 108, 8, 48, 33, 52, 57, 54, 101, 110, 115, 32, 51, 52, 54, 115, 119, 104, 33, 98, 116, 34, 72, 80, 18, 211, 18, 9618, 18, 199, 18, 209, 17, 8730, 17, 8595, 15, 226, 16, 177, 16, 926, 15, 132, 54, 66, 97, 100, 31, 101, 100, 12, 15, 54, 116, 100, 101, 74, 46, 112, 110, 103, 9, 100, 33, 109, 98, 33, 107, 110, 32, 68, 97, 32, 105, 114, 54, 71, 105, 114, 75, 50, 48, 48, 57, 29, 48, 48, 53, 80, 114, 105, 54, 66, 114, 101, 33, 84, 101, 34, 86, 101, 34, 53, 52, 33, 83, 104, 53, 87, 104, 111, 33, 102, 116, 33, 78, 101, 32, 88, 120, 94, 74, 97, 109, 101, 115, 32, 67, 108, 32, 109, 111, 54, 97, 110, 103, 12, 204, 33, 87, 117, 33, 48, 52, 9, 57, 74, 48, 48, 54, 53, 34, 67, 72, 34, 99, 105, 33, 103, 104, 31, 107, 101, 33, 117, 114, 33, 97, 107, 33, 105, 97, 33, 119, 117, 94, 112, 105, 99, 115, 47, 52, 100, 101, 110, 32, 76, 111, 53, 115, 116, 97, 34, 71, 66, 55, 115, 98, 117, 34, 111, 104, 34, 113, 117, 32, 83, 97, 31, 108, 105, 9, 97, 10, 79, 33, 70, 101, 34, 120, 121, 18, 163, 18, 1086, 17, 154, 16, 169, 17, 247, 17, 9559, 18, 9472, 18, 8220, 18, 173, 18, 189, 15, 171, 17, 9562, 18, 203, 18, 242, 17, 165, 17, 243, 74, 110, 105, 99, 104, 54, 98, 101, 115, 33, 116, 99, 12, 172, 12, 9829, 53, 109, 101, 110, 32, 83, 116, 52, 98, 117, 114, 31, 114, 116, 33, 57, 51, 33, 87, 97, 33, 84, 105, 33, 48, 55, 32, 103, 97, 33, 100, 115, 34, 57, 57, 34, 77, 117, 51, 115, 99, 104, 33, 74, 111, 54, 72, 101, 114, 34, 103, 103, 34, 118, 98, 33, 105, 98, 53, 101, 110, 116, 34, 56, 55, 34, 121, 97, 33, 108, 102, 32, 111, 114, 33, 101, 98, 33, 97, 119, 11, 18, 32, 116, 122, 29, 99, 104, 33, 114, 108, 159, 46, 115, 104, 97, 100, 111, 119, 95, 32, 115, 112, 33, 116, 111, 33, 111, 111, 11, 42, 30, 49, 53, 9, 111, 34, 110, 102, 34, 56, 54, 33, 57, 53, 54, 73, 78, 69, 33, 83, 105, 74, 70, 111, 116, 111, 33, 121, 115, 34, 57, 54, 15, 26, 15, 31, 15, 152, 16, 225, 17, 212, 18, 1111, 18, 236, 7, 114, 52, 105, 115, 116, 54, 76, 97, 100, 54, 77, 111, 109, 33, 84, 104, 54, 80, 114, 111, 32, 107, 97, 32, 67, 104, 31, 110, 105, 30, 115, 115, 73, 46, 109, 121, 95, 32, 118, 105, 54, 77, 111, 110, 33, 112, 105, 33, 81, 102, 34, 111, 99, 34, 115, 103, 34, 84, 97, 34, 116, 119, 34, 105, 102, 34, 122, 122, 31, 110, 97, 33, 65, 117, 33, 97, 105, 158, 75, 110, 117, 100, 100, 101, 108, 115, 10, 88, 71, 176, 62, 95, 104, 35, 117, 103, 35, 77, 121, 34, 80, 101, 34, 101, 120, 34, 78, 111, 32, 75, 97, 32, 110, 111, 34, 120, 116, 34, 104, 112, 34, 107, 114, 34, 80, 117, 30, 49, 56, 9, 82, 53, 83, 105, 110, 32, 65, 110, 34, 82, 105, 55, 115, 101, 108, 54, 98, 101, 97, 33, 86, 111, 34, 97, 104, 34, 81, 117, 7, 43, 10, 99, 33, 116, 115, 33, 84, 114, 32, 87, 101, 10, 76, 241, 105, 99, 111, 110, 95, 103, 101, 110, 100, 101, 114, 95, 31, 109, 101, 53, 46, 104, 95, 54, 119, 119, 119, 34, 121, 111, 34, 104, 117, 255, 12, 10, 124, 47, 102, 111, 116, 111, 119, 104, 111, 105, 115, 32, 34, 53, 109, 105, 116, 32, 115, 111, 8, 11, 52, 70, 114, 101, 54, 109, 97, 120, 54, 114, 101, 103, 33, 86, 97, 54, 119, 101, 114, 10, 117, 54, 119, 105, 101, 117, 105, 99, 111, 110, 115, 47, 33, 69, 110, 15, 9552, 16, 149, 16, 215, 14, 159, 34, 106, 111, 7, 37, 220, 50, 53, 53, 44, 50, 53, 53, 44, 50, 53, 53, 32, 101, 105, 33, 100, 114, 33, 105, 112, 32, 68, 117, 34, 107, 102, 34, 53, 55, 33, 80, 108, 31, 108, 111, 53, 83, 116, 97, 14, 945, 15, 29, 17, 964, 17, 210, 16, 145, 34, 69, 82, 33, 107, 117, 32, 108, 115, 54, 97, 99, 116, 33, 70, 114, 10, 92, 255, 19, 11, 102, 111, 116, 111, 115, 47, 107, 110, 117, 100, 100, 101, 108, 115, 46, 100, 101, 63, 110, 61, 11, 72, 50, 32, 32, 32, 33, 76, 117, 54, 100, 101, 109, 53, 101, 110, 100, 35, 66, 252, 35, 97, 112, 34, 55, 52, 54, 99, 104, 108, 53, 103, 108, 101, 30, 52, 48, 9, 33, 30, 51, 50, 52, 101, 105, 110, 53, 115, 101, 105, 33, 75, 101, 12, 223, 32, 102, 103, 53, 98, 97, 108, 31, 116, 97, 30, 49, 57, 52, 110, 100, 101, 54, 77, 101, 110, 54, 76, 105, 101, 32, 97, 100, 31, 83, 102, 10, 167, 30, 105, 110, 35, 101, 99, 15, 30, 16, 8249, 17, 221, 18, 166, 18, 234, 14, 953, 35, 72, 252, 33, 111, 115, 32, 114, 110, 74, 46, 109, 120, 95, 53, 119, 101, 105, 30, 46, 46, 54, 108, 101, 114, 33, 114, 107, 11, 113, 34, 116, 102, 34, 85, 110, 33, 80, 111, 53, 86, 101, 114, 9, 112, 7, 47, 12, 125, 35, 100, 119, 15, 1109, 16, 146, 16, 235, 34, 97, 122, 33, 108, 117, 33, 70, 105, 33, 107, 108, 33, 119, 111, 32, 56, 48, 255, 32, 9, 0, 112, 0, 66, 0, 112, 105, 99, 115, 47, 105, 99, 111, 110, 95, 102, 117, 108, 108, 67, 104, 97, 110, 110, 101, 108, 46, 103, 105, 102, 0, 45, 0, 30, 101, 108, 31, 116, 121, 54, 78, 101, 117, 34, 53, 50, 34, 108, 109, 32, 48, 49, 113, 124, 47, 119, 32, 34, 60, 180, 46, 113, 117, 97, 100, 99, 117, 116, 95, 35, 54, 57, 35, 100, 228, 34, 116, 117, 54, 102, 114, 101, 34, 105, 104, 35, 101, 122, 35, 57, 56, 31, 116, 101, 53, 103, 105, 114, 53, 99, 110, 116, 158, 46, 98, 111, 114, 100, 101, 114, 95, 32, 105, 116, 11, 89, 255, 14, 11, 102, 117, 108, 108, 67, 104, 97, 110, 110, 101, 108, 46, 103, 105, 102, 34, 122, 111, 34, 107, 99, 34, 65, 98, 15, 965, 18, 9642, 19, 9577, 19, 8494, 17, 202, 16, 141, 35, 56, 50, 32, 51, 51, 31, 110, 100, 10, 70, 32, 83, 112, 11, 94, 54, 97, 99, 104, 33, 117, 99, 32, 107, 105, 52, 105, 99, 104, 55, 102, 101, 108, 35, 56, 51, 15, 191, 15, 219, 33, 98, 114, 54, 70, 114, 105, 54, 100, 111, 114, 31, 100, 101, 31, 53, 48, 33, 97, 97, 34, 103, 98, 34, 108, 99, 54, 102, 252, 114, 33, 55, 53, 32, 116, 104, 53, 66, 101, 114, 54, 66, 97, 108, 33, 55, 48, 33, 52, 53, 34, 83, 119, 34, 52, 49, 32, 105, 108, 54, 104, 102, 108, 34, 73, 104, 13, 126, 255, 14, 10, 112, 105, 99, 115, 47, 102, 101, 109, 97, 108, 101, 46, 103, 105, 102, 53, 104, 116, 116, 16, 9834, 18, 161, 18, 232, 18, 305, 19, 8212, 62, 92, 92, 92, 20, 1241, 15, 183, 35, 65, 116, 35, 76, 69, 35, 83, 107, 75, 50, 48, 49, 48, 71, 46, 103, 105, 102, 74, 102, 111, 116, 111, 54, 76, 97, 110, 13, 19, 34, 105, 107, 199, 176, 62, 103, 116, 46, 103, 105, 102, 60, 176, 32, 72, 111, 34, 100, 121, 34, 80, 105, 54, 97, 108, 116, 32, 50, 56, 74, 46, 106, 112, 103, 7, 101, 8, 115, 32, 69, 108, 54, 109, 101, 114, 255, 14, 12, 109, 97, 108, 101, 46, 98, 46, 109, 121, 95, 51, 46, 103, 105, 102, 136, 0, 70, 108, 105, 114, 116, 32, 14, 1103, 35, 55, 54, 34, 110, 98, 33, 76, 97, 32, 110, 115, 33, 114, 103, 33, 48, 56, 32, 66, 101, 11, 118, 34, 109, 108, 35, 99, 100, 35, 55, 51, 33, 66, 117, 32, 116, 114, 32, 119, 105, 31, 109, 109, 33, 115, 102, 54, 68, 105, 101, 32, 110, 116, 32, 108, 121, 33, 101, 109, 54, 116, 109, 117, 34, 111, 100, 34, 115, 100, 54, 75, 105, 115, 34, 68, 68, 16, 151, 17, 168, 17, 206, 15, 951, 35, 54, 56, 12, 81, 31, 103, 101, 35, 56, 52, 35, 70, 67, 34, 103, 115, 33, 82, 97, 33, 115, 117, 34, 105, 118, 35, 104, 104, 35, 80, 114, 7, 60, 31, 104, 97, 31, 111, 110, 10, 84, 52, 99, 104, 101, 8, 104, 7, 34, 255, 13, 12, 99, 108, 111, 117, 100, 115, 98, 108, 117, 101, 46, 103, 105, 102, 34, 67, 105, 13, 3, 55, 108, 105, 103, 14, 23, 16, 142, 16, 150, 18, 241, 18, 253, 18, 174, 18, 1091, 19, 942, 19, 304, 19, 322, 19, 324, 17, 961, 33, 98, 98, 53, 98, 101, 114, 32, 76, 105, 33, 68, 105, 13, 175, 34, 108, 103, 33, 65, 108, 54, 79, 117, 116, 32, 50, 52, 32, 117, 110, 32, 51, 57, 55, 117, 114, 116, 35, 73, 115, 35, 82, 102, 33, 55, 49, 33, 104, 108, 33, 66, 108, 32, 66, 97, 53, 101, 97, 114, 54, 101, 99, 104, 34, 85, 115, 34, 52, 55, 54, 105, 112, 105, 12, 59, 32, 122, 101, 7, 46, 9, 55, 31, 97, 116, 34, 119, 228, 35, 72, 117, 15, 8706, 16, 186, 17, 240, 17, 65273, 33, 223, 101, 33, 117, 116, 33, 102, 117, 73, 62, 45, 45, 60, 31, 97, 110, 32, 76, 101, 32, 115, 97, 13, 4, 34, 103, 116, 33, 106, 101, 53, 112, 119, 100, 32, 82, 101, 32, 104, 101, 32, 104, 111, 34, 111, 109, 34, 111, 107, 33, 53, 53, 52, 119, 97, 114, 53, 104, 101, 110, 34, 112, 101, 35, 101, 107, 35, 76, 76, 33, 98, 117, 31, 114, 101, 34, 119, 252, 34, 54, 54, 33, 83, 101, 11, 90, 33, 252, 99, 34, 67, 114, 34, 103, 117, 32, 122, 117, 12, 74, 34, 109, 228, 34, 52, 50, 33, 98, 111, 33, 67, 97, 31, 101, 115, 54, 84, 97, 103, 35, 82, 82, 35, 114, 121, 13, 5, 32, 50, 54, 34, 114, 114, 34, 111, 102, 54, 68, 111, 114, 53, 114, 101, 115, 53, 99, 103, 105, 33, 100, 100, 255, 57, 12, 124, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 51, 46, 107, 110, 117, 100, 100, 101, 108, 115, 46, 100, 101, 58, 56, 48, 56, 48, 47, 116, 120, 116, 108, 47, 99, 108, 105, 99, 107, 63, 100, 61, 107, 110, 117, 100, 100, 101, 108, 115, 46, 100, 101, 38, 105, 100, 61, 33, 83, 109, 34, 52, 51, 34, 97, 102, 53, 105, 110, 101, 33, 67, 111, 18, 170, 18, 179, 17, 931, 16, 137, 15, 187, 35, 67, 69, 34, 108, 107, 32, 97, 109, 32, 112, 112, 33, 115, 119, 35, 54, 51, 35, 109, 121, 35, 112, 102, 17, 156, 17, 230, 16, 140, 15, 28, 54, 102, 104, 101, 13, 8, 34, 86, 105, 53, 116, 101, 114, 10, 255, 31, 49, 49, 33, 102, 97, 35, 115, 114, 35, 77, 102, 13, 16, 96, 176, 62, 115, 109, 95, 54, 65, 110, 122, 10, 65, 32, 97, 115, 35, 78, 82, 35, 108, 114, 35, 78, 84, 35, 54, 49, 33, 110, 122, 33, 97, 98, 33, 103, 105, 54, 100, 112, 103, 33, 103, 114, 9, 40, 255, 12, 10, 112, 105, 99, 115, 47, 109, 97, 108, 101, 46, 103, 105, 102, 32, 112, 103, 35, 67, 117, 19, 948, 19, 962, 19, 1754, 19, 8596, 18, 1110, 18, 9658, 17, 1750, 19, 273, 19, 295, 19, 423, 19, 1753, 18, 957, 18, 1089, 17, 207, 17, 237, 18, 9679, 18, 8221, 34, 79, 115, 33, 111, 119, 31, 99, 107, 11, 229, 32, 72, 97, 35, 103, 100, 35, 73, 116, 34, 107, 116, 54, 108, 101, 110, 33, 69, 105, 13, 7, 34, 102, 114, 10, 67, 9, 41, 54, 109, 105, 110, 54, 83, 105, 101, 12, 123, 34, 54, 53, 34, 77, 252, 11, 246, 35, 78, 252, 35, 68, 111, 34, 105, 111, 33, 80, 102, 54, 100, 97, 115, 12, 86, 95, 70, 108, 105, 114, 116, 11, 252, 34, 114, 122, 35, 71, 117, 35, 102, 109, 54, 72, 97, 109, 8, 116, 29, 101, 110, 29, 101, 114, 4, 0, 52, 100, 101, 114, 33, 67, 99, 54, 65, 108, 116, 53, 77, 105, 120, 35, 65, 115, 35, 116, 112, 55, 110, 101, 110, 33, 108, 100, 32, 48, 53, 31, 105, 115, 11, 195, 34, 76, 252, 15, 1752, 15, 1761, 15, 1762, 15, 162, 54, 71, 101, 115, 54, 97, 117, 102, 54, 97, 110, 100, 54, 98, 108, 103, 33, 112, 114, 52, 117, 110, 100, 31, 97, 108, 34, 73, 110, 34, 87, 252, 54, 104, 105, 101, 54, 103, 101, 115, 34, 246, 223, 34, 112, 115, 31, 98, 101, 32, 50, 53, 54, 49, 52, 48, 35, 104, 115, 16, 969, 16, 239, 16, 147, 16, 963, 34, 52, 54, 10, 128, 31, 49, 52, 32, 51, 53, 33, 69, 109, 54, 103, 101, 114, 31, 99, 103, 10, 107, 6, 45, 34, 119, 104, 35, 114, 112, 17, 148, 18, 923, 18, 155, 16, 9553, 16, 129, 17, 208, 19, 287, 19, 399, 19, 9632, 19, 9668, 33, 80, 97, 11, 85, 32, 98, 108, 33, 99, 97, 54, 118, 97, 116, 33, 51, 55, 34, 101, 117, 34, 109, 115, 33, 77, 105, 33, 99, 115, 53, 100, 105, 101, 33, 97, 121, 33, 102, 105, 10, 192, 32, 117, 109, 53, 115, 101, 110, 9, 61, 33, 66, 114, 34, 117, 108, 34, 102, 121, 53, 118, 111, 114, 33, 87, 108, 54, 116, 115, 99, 32, 114, 100, 31, 110, 101, 34, 75, 117, 15, 949, 15, 1090, 35, 82, 252, 54, 80, 97, 114, 35, 56, 53, 35, 119, 99, 34, 99, 114, 33, 114, 109, 8, 49, 6, 95, 4, 32 });
    		encoder = new HuffmanEncoder(tree);
    		decoder = new HuffmanDecoder(tree);
    	}
    
    	public static HuffmanEncoder getEncoder() {
    		return encoder;
    	}
    
    	public static HuffmanDecoder getDecoder() {
    		return decoder;
    	}
    }
    HuffmanEncoder.java
    Code:
    import java.util.Hashtable;
    
    /**
     *
     * @author Knuddels GmbH & Co. KG
     */
    public class HuffmanEncoder {
    	private int a;
    	private int b;
    	private Hashtable c;
    	private long d;
    	private long e;
    	private byte f[];
    	private int g;
    	private int h;
    	private Character i[];
    	private Short j[];
    
    	public HuffmanEncoder(String tree) {
    		f = new byte[65535];
    		g = 0;
    		h = 0;
    		d = 0L;
    		e = 0L;
    		c = new Hashtable(1, 1.0F);
    		a();
    		a(tree);
    	}
    
    	private final void a(int k) {
    		int l = k >> 24;
    		int i1 = k - (l << 24);
    
    		if (g != 0 && l > 0) {
    			l += g - 8;
    			i1 <<= g;
    			f[h++] += (byte) i1;
    			i1 >>= 8;
    			g = 0;
    		}
    
    		for (; l > 0; l -= 8) {
    			f[h++] = (byte) i1;
    			i1 >>= 8;
    		}
    
    		if (l < 0) {
    			h--;
    			g = l + 8;
    		}
    	}
    
    	private final int a(int k, int l) {
    		int i1 = 0;
    		int j1 = 1;
    		int k1 = 1 << l - 1;
    
    		for (; l > 0; l--) {
    			if ((k & j1) != 0) {
    				i1 += k1;
    			}
    
    			j1 <<= 1;
    			k1 >>= 1;
    		}
    
    		return i1;
    	}
    
    	public synchronized byte[] encode(String str, int size) {
    		byte abyte0[] = null;
    
    		if (size > 0) {
    			abyte0 = f;
    			f = new byte[size];
    		}
    
    		g = 0;
    		h = 0;
    		int l = str.length();
    		e += l;
    
    		for (int j1 = 0; j1 < l;) {
    			Integer integer = null;
    			int i1 = j1 + 1;
    			Hashtable hashtable = c;
    
    			do {
    				if (j1 >= l) {
    					break;
    				}
    
    				char c1 = str.charAt(j1);
    				Integer integer1 = (Integer) hashtable.get(b(c1));
    
    				if (integer1 != null) {
    					i1 = j1 + 1;
    					integer = integer1;
    				}
    
    				hashtable = (Hashtable) hashtable.get(c(c1));
    
    				if (hashtable == null) {
    					break;
    				}
    
    				j1++;
    			} while (true);
    
    			j1 = i1;
    
    			if (integer == null) {
    				a(a);
    				a(0x10000000 + str.charAt(j1 - 1));
    			} else {
    				a(integer.intValue());
    			}
    		}
    
    		b();
    		byte abyte1[] = new byte[h];
    		System.arraycopy(f, 0, abyte1, 0, h);
    		d += h;
    
    		if (size > 0) {
    			f = abyte0;
    		}
    
    		return abyte1;
    	}
    
    	private final void a(String s) {
    		int k = 0;
    		int l = s.length();
    		int i1 = 1;
    		int j1 = -33;
    		boolean flag = false;
    		boolean flag1 = false;
    		int l1;
    
    		for (; k < l; k += l1 + 1) {
    			char c1 = s.charAt(k);
    			int k1;
    
    			if (c1 == '\377') {
    				l1 = s.charAt(k + 1) + 1;
    				k1 = s.charAt(k + 2);
    				k += 2;
    			} else {
    				l1 = c1 / 21 + 1;
    				k1 = c1 % 21;
    			}
    
    			if ((i1 & 1) == 0) {
    				i1++;
    
    				for (; j1 < k1; j1++) {
    					i1 <<= 1;
    				}
    			} else {
    				while ((i1 & 1) == 1)  {
    					i1 >>= 1;
    					j1--;
    				}
    
    				i1++;
    
    				for (; j1 < k1; j1++) {
    					i1 <<= 1;
    				}
    			}
    
    			Integer integer = new Integer(a(i1, k1) + (k1 << 24));
    			String s1 = s.substring(k + 1, k + l1 + 1);
    
    			if (b == 0 && k1 > 8) {
    				b = a(i1 >> k1 - 8, 8) + 0x8000000;
    			}
    
    			if (l1 == 3 && s1.equals("\\\\\\")) {
    				a = integer.intValue();
    			} else {
    				a(s1, integer);
    			}
    		}
    	}
    
    	private final void a() {
    		i = new Character[256];
    		j = new Short[256];
    
    		for (int k = 0; k < i.length; k++) {
    			i[k] = new Character((char) k);
    			j[k] = new Short((short) k);
    		}
    
    	}
    
    	private final void a(String s, Object obj) {
    		a(c, s, 0, obj);
    	}
    
    	private final void a(Hashtable hashtable, String s, int k, Object obj) {
    		char c1 = s.charAt(k);
    
    		if (k + 1 >= s.length()) {
    			if (hashtable.get(b(c1)) != null) {
    				throw new RuntimeException((new StringBuilder()).append("ERROR while constructing tree ").append(s).toString());
    			}
    
    			hashtable.put(b(c1), obj);
    		} else {
    			Hashtable hashtable1 = (Hashtable) hashtable.get(c(c1));
    
    			if (hashtable1 == null) {
    				hashtable1 = new Hashtable(1, 1.0F);
    				hashtable.put(c(c1), hashtable1);
    			}
    
    			a(hashtable1, s, k + 1, obj);
    		}
    	}
    
    	private final Character b(int k) {
    		k &= 0xffff;
    		return k >= 256 ? new Character((char) k) : i[k];
    	}
    
    	private final Short c(int k) {
    		k &= 0xffff;
    		return k >= 256 ? new Short((short) k) : j[k];
    	}
    
    	private final void b() {
    		int k = h;
    
    		if (g != 0) {
    			while (k == h) {
    				a(b);
    			}
    		}
    	}
    }
    HuffmanDecoder.java
    Code:
    import java.util.Hashtable;
    
    /**
     *
     * @author Knuddels GmbH & Co. KG
     */
    public class HuffmanDecoder {
    	private Object a;
    	private Object b[];
    	private long c;
    	private long d;
    	private boolean e;
    	private byte f[];
    	private int g;
    	private int h;
    
    	public HuffmanDecoder(String tree) {
    		g = 0;
    		h = 0;
    		c = 0L;
    		d = 0L;
    		b = new Object[2];
    		a(b, tree);
    	}
    
    	private final void a(Object aobj[], String s) {
    		int i = 0;
    		int j = s.length();
    		int k = 1;
    		int l = -33;
    		boolean flag = false;
    		boolean flag1 = false;
    		int j1;
    
    		for (; i < j; i += j1 + 1) {
    			char c1 = s.charAt(i);
    			int i1;
    
    			if (c1 == '\377') {
    				j1 = s.charAt(i + 1) + 1;
    				i1 = s.charAt(i + 2);
    				i += 2;
    			} else {
    				j1 = c1 / 21 + 1;
    				i1 = c1 % 21;
    			}
    
    			if ((k & 1) == 0) {
    				k++;
    
    				for (; l < i1; l++) {
    					k <<= 1;
    				}
    			} else {
    				while ((k & 1) == 1) {
    					k >>= 1;
    					l--;
    				}
    
    				k++;
    
    				for (; l < i1; l++) {
    					k <<= 1;
    				}
    			}
    
    			int k1 = a(k, i1);
    			String s1 = s.substring(i + 1, i + j1 + 1);
    
    			if (j1 == 3 && s1.equals("\\\\\\")) {
    				a = s1;
    			}
    
    			a(aobj, s1, k1, i1);
    		}
    	}
    
    	public synchronized String decode(byte[] buffer) {
    		if (buffer == null) {
    			return null;
    		}
    
    		StringBuffer stringbuffer = new StringBuffer((buffer.length * 100) / 60);
    		f = buffer;
    		g = 0;
    		h = 0;
    		e = false;
    		Object aobj[] = b;
    
    		do {
    			if (e) {
    				break;
    			}
    
    			aobj = (Object[]) aobj[a()];
    
    			if (aobj[0] == null) {
    				if (aobj[1] == a) {
    					int i = 0;
    
    					for (int j = 0; j < 16; j++) {
    						i += a() << j;
    					}
    
    					stringbuffer.append((char) i);
    				} else {
    					stringbuffer.append((String) aobj[1]);
    				}
    
    				aobj = b;
    			}
    		} while (true);
    
    		String s = stringbuffer.toString();
    		d += s.length();
    		c += buffer.length;
    
    		return s;
    	}
    
    	private final boolean a(Object aobj[], String s, int i, int j) {
    		if (j == 0) {
    			aobj[1] = s;
    			return aobj[0] == null;
    		}
    
    		if (aobj[0] == null) {
    			if (aobj[1] != null) {
    				return false;
    			}
    
    			aobj[0] = ((Object) (new Object[2]));
    			aobj[1] = ((Object) (new Object[2]));
    		}
    
    		return a((Object[]) aobj[i & 1], s, i >> 1, j - 1);
    	}
    
    	private final int a() {
    		int i = 0;
    
    		if ((f[h] & 1 << g) != 0) {
    			i = 1;
    		}
    
    		g++;
    
    		if (g > 7) {
    			g = 0;
    			h++;
    			e = h == f.length;
    		}
    
    		return i;
    	}
    
    	private final int a(int i, int j) {
    		int k = 0;
    		int l = 1;
    		int i1 = 1 << j - 1;
    
    		for (; j > 0; j--) {
    			if ((i & l) != 0) {
    				k += i1;
    			}
    
    			l <<= 1;
    			i1 >>= 1;
    		}
    
    		return k;
    	}
    }
    Beispiel
    Code:
    String str = "Sample";
    byte[] encoded = Huffman.getEncoder().encode(str, 0); // Den zweiten Parameter setzen wir einfach immer 0, hat soweit ich das verstanden habe was mit der Länge des zu enkodierenden Strings zu tun.
    String decoded = Huffman.getDecoder().decode(encoded);
    System.out.println(decoded); // "Sample"
    Geändert von Flav (09.04.2012 um 03:10 Uhr)

  2. The Following 2 Users Say Thank You to Flav For This Useful Post:

    Mentos (09.04.2012), Nachto (09.04.2012)

  3. #2
    Mitglied
    Avatar von Gnome
    Registriert seit
    14.04.2012
    Beiträge
    75
    Thanked 34 Times in 24 Posts

    Standard AW: [Java] Huffman

    Was soll man noch sagen, ausser danke?

    Wäre es machbar dass du den Funktionen auch mal richtige Namen gibst, damit man den Quellcode besser verstehen kann?

  4. #3
    U-Labs Plus-Mitglied

    Registriert seit
    06.11.2011
    Beiträge
    418
    Thanked 686 Times in 246 Posts

    Standard AW: [Java] Huffman

    Mach ich wenn ich Zeit und Lust habe, momentan hab ich viel anderes um die Ohren.


Ähnliche Themen

  1. Antworten: 8
    Letzter Beitrag: 02.12.2013, 23:41
  2. [Release] Huffman (Java Library)
    Von Flav im Forum Protokoll
    Antworten: 2
    Letzter Beitrag: 05.07.2013, 15:17
  3. Java EE 32 Bit?
    Von Pwned im Forum Java
    Antworten: 2
    Letzter Beitrag: 04.08.2012, 23:08
  4. Ubuntu Sun Java
    Von hYpercrites im Forum Linux
    Antworten: 3
    Letzter Beitrag: 20.06.2012, 15:17
  5. [Java] Timer
    Von rVs14 im Forum Java
    Antworten: 1
    Letzter Beitrag: 16.06.2012, 12:13
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191