0

Hi i am having an object in ruby which is of type Byte ByteBuffer

Object type: java.nio.HeapByteBuffer[pos=0 lim=437 cap=437]

I want to convert/decode this object into String in ruby

1 Answer 1

1

There's String.from_java_bytes extension however it does not take an (optional) offset and length thus first copy the buffer's content into a new byte[] array:

>> bytes = Java::byte[buffer.limit].new
=> byte[0, 0, 0]@3427b02d
>> buffer.get(bytes)
=> #<Java::JavaNio::HeapByteBuffer:0x3967e60c>
>> bytes
=> byte[102, 111, 111]@3427b02d
>> String.from_java_bytes bytes
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.