Hi Daniel,

That seems reasonable, allowing control over the timing of resizes.
Making it public is sensible too.

From a higher point of view, are you sure you want to be working with ByteArrayOutputStream and not ByteBuffer or Memory Segments? There are more performance possibilities with those APIs.

Regards, Roger


On 1/5/26 7:15 AM, Daniel Gredler wrote:
Hi,

I was recently looking at subclassing `ByteArrayOutputStream` in an application so that I could add a fast VarHandle-based `writeLong(long)` method (writing 8 bytes to the byte array in one go). The internal `ByteArrayOutputStream` buffer is protected, so no issue there, but `ensureCapacity(int)` is private rather than protected, and uses the internal `ArraysSupport` class, so it's not even easy to copy/paste as duplicate code in the subclass. Similar `ensureCapacity` methods in `ArrayList` and `StringBuilder` are public. Would a PR adjusting the visibility of this method from private to protected be accepted?

Take care,

Daniel



Reply via email to