Guest User

Untitled

a guest
Jul 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. public static byte[] compress(byte[] datum) {
  2.  
  3. byte[] ret = datum, tmp = new byte[ret.length];
  4. System.arraycopy(ret, 0, tmp, 0, ret.length);
  5. int ctr = 1, i = 0, idx = 0;
  6.  
  7. for (i = 0; i + 1 < tmp.length && idx < tmp.length; i++) {
  8. tmp[idx++] = (byte) (tmp[i] << ctr | (tmp[i + 1] << 1 >>> (8 - ctr)));
  9. ctr++;
  10. if (ctr == 8) {
  11. ctr = 1;
  12. i++;
  13. }
  14. }
  15.  
  16. if (idx < tmp.length && i < tmp.length && ret.length > 9) {
  17. tmp[idx] = (byte) (tmp[i] << ctr);
  18. }
  19. else {
  20. tmp[idx] = (byte) (ret[idx] << ctr);
  21. }
  22.  
  23. ret = new byte[ret.length - ret.length / 8];
  24. System.arraycopy(tmp, 0, ret, 0, ret.length);
  25. return ret;
  26. }
Add Comment
Please, Sign In to add comment