Here you can find the source of decompress(byte[] in, int len)
Parameter | Description |
---|---|
in | The compressed input data. |
len | The length. |
public static String decompress(byte[] in, int len)
//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); } }