Byte array of unknown length in Java: Part 2

Similar to "byte array of unknown length in Java", I need to be able to write an unknown number of bytes from the data source to the byte [] array But I need to be able to read the compression algorithm from the previously stored bytes, so bytearrayoutputstream doesn't work for me

Now I have a scheme. I allocate bytebuffers of fixed size n and add a new one when I reach n, 2n, 3N bytes, etc When the data runs out, I dump all the buffers into an array of now known size

Is there a better way? The fixed size buffer reduces the flexibility of the compression algorithm

Solution

Why not subclass bytearrayoutputstream? In this way, your subclass can access the protected buf and count fields, and you can add methods to the class to manipulate them directly

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>