SnappySerializer.java 828 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.sdyc.ndmp.protobuf.serializer;
  2. import org.xerial.snappy.Snappy;
  3. import java.io.IOException;
  4. /**
  5. * <pre>
  6. * Created with IntelliJ IDEA.
  7. * User: lwj
  8. * Date: 2015/2/27
  9. * Time: 10:48
  10. * To change this template use File | Settings | File Templates.
  11. * </pre>
  12. *
  13. * @author lwj
  14. */
  15. public class SnappySerializer extends CompressSerializer {
  16. public SnappySerializer() {
  17. }
  18. @Override
  19. public byte[] compress(byte[] bytes) {
  20. try {
  21. return Snappy.compress(bytes);
  22. } catch (IOException e) {
  23. throw new IllegalStateException(e);
  24. }
  25. }
  26. @Override
  27. public byte[] uncompress(byte[] bytes) {
  28. try {
  29. return Snappy.uncompress(bytes);
  30. } catch (IOException e) {
  31. throw new IllegalStateException(e);
  32. }
  33. }
  34. }