3

I'm creating packets, and I need to encode bytes into an array for output. I have not been able to find any convenient classes to buffer the bytes in a variable length array, and then output them as an array of bytes.

Any ideas?

1 Answer 1

6

Use ByteArrayOutputStream write bytes into it, and then call toBytes() to get the bytes.

Sign up to request clarification or add additional context in comments.

1 Comment

And you can subclass 'ByteArrayOutputStream' to expose the underlying protected array reference and current length and to avoid having to uselessly duplicating the array just to get it out of the BAOS.

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.