-1

In my Java code, I have data of type java.nio.ByteBuffer. I have to snappy compress this. Using Snappy.compress() by importing org.xerial.snappy.Snappy; throws an error.

Snappy.compress(DataUtility.parseValue(record.valueSchema(), record.value())))

Do I need to convert this to another type before compressing or do I have to use a different compression method?

Thank you!

NoName
  • 1,509
  • 2
  • 20
  • 36

1 Answers1

1

Cannot resolve method 'compress(java.nio.ByteBuffer)'

That's because there is no method which accepts a ByteBuffer for input and returns a byte[].

Your options:

.

byte[] inputBytes = new byte[inputBBuffer.remaining()];
inputBBuffer.get(inputBytes);

byte[] output = compress(inputBytes);
JimmyB
  • 12,101
  • 2
  • 28
  • 44
  • Thank you for your answer! I tried the second method and it threw me an IOException. The first method requires the second parameter `ByteBuffer` to have a fixed size while declaring it. Since I won't know the size of the compressed output, is there any other way to do it? – NoName Dec 11 '17 at 16:34
  • Not quite sure about how Snappy really works, but you could try and initialize the output buffer to at least the same size of the input. – JimmyB Dec 11 '17 at 16:51