Java Byte Array Decompress decompress(byte[] in, int len)

Here you can find the source of decompress(byte[] in, int len)

Description

Uncompresses the compressed data ( in ) with the length ( len ) and returns the uncompressed String .

License

Open Source License

Parameter

Parameter Description
in The compressed input data.
len The length.

Return

The uncompressed .

Declaration

public static String decompress(byte[] in, int len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//  w w  w.  j  av a  2  s  .  c  o m
     * An array of characters ordered by frequency - the elements with lower indices (generally) appear more often in
     * chat messages.
     */
    public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd',
            'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4',
            '5', '6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@',
            '#', '+', '=', '\243', '$', '%', '"', '[', ']' };

    /**
     * Uncompresses the compressed data ({@code in}) with the length ({@code len}) and returns the uncompressed
     * {@link String}.
     *
     * @param in The compressed input data.
     * @param len The length.
     * @return The uncompressed {@link String}.
     */
    public static String decompress(byte[] in, int len) {
        byte[] out = new byte[4096];
        int outPos = 0;
        int carry = -1;

        for (int i = 0; i < len * 2; i++) {
            int tblPos = in[i / 2] >> 4 - 4 * (i % 2) & 0xF;
            if (carry == -1) {
                if (tblPos < 13) {
                    out[outPos++] = (byte) FREQUENCY_ORDERED_CHARS[tblPos];
                } else {
                    carry = tblPos;
                }
            } else {
                out[outPos++] = (byte) FREQUENCY_ORDERED_CHARS[(carry << 4) + tblPos - 195];
                carry = -1;
            }
        }
        return new String(out, 0, outPos);
    }
}

Related

  1. decompress(byte src[], int src_off, int src_len, byte dst[], int dst_off, int dst_len)
  2. decompress(byte[] compressed, int sequenceLen)
  3. decompress_action(byte[] source)
  4. decompressHuffman(byte[] message, int length)
  5. decompressRTF(byte[] src)