Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static byte[] compress(byte[] datum) {
- byte[] ret = datum, tmp = new byte[ret.length];
- System.arraycopy(ret, 0, tmp, 0, ret.length);
- int ctr = 1, i = 0, idx = 0;
- for (i = 0; i + 1 < tmp.length && idx < tmp.length; i++) {
- tmp[idx++] = (byte) (tmp[i] << ctr | (tmp[i + 1] << 1 >>> (8 - ctr)));
- ctr++;
- if (ctr == 8) {
- ctr = 1;
- i++;
- }
- }
- if (idx < tmp.length && i < tmp.length && ret.length > 9) {
- tmp[idx] = (byte) (tmp[i] << ctr);
- }
- else {
- tmp[idx] = (byte) (ret[idx] << ctr);
- }
- ret = new byte[ret.length - ret.length / 8];
- System.arraycopy(tmp, 0, ret, 0, ret.length);
- return ret;
- }
Add Comment
Please, Sign In to add comment