R
Robert Mischke
I'm curious: Is there a common "best practice" to store binary data in
memory, when the amount of data is not known in advance? For example,
think of retrieving data from an URL, and there is nothing like a http
"content-length" field, and you don't want to use a temporary file.
My current idea is providing a container class (let's call it
DynamicMemBuffer) that uses a linked list of fixed-size byte[] buffers
internally. So a new DynamicMemBuffer starts with a single internal
buffer of size n. When n bytes have been added/written to the
DynamicMemBuffer, a new internal buffer is created, added to the
linked list, and writing of new bytes is directed into this buffer.
From the outside, the DynamicMemBuffer looks like a continuous byte
stream held in memory. As an interface, standard getInputStream() and
getOutputStream() methods could be provided.
While all of this is quite simple to implement, I'm reluctant to do so
because I can't imagine this problem hasn't been solved a thousand
times before.
So are there better approaches and/or ready-to-use classes out there?
Thanks,
Robert
memory, when the amount of data is not known in advance? For example,
think of retrieving data from an URL, and there is nothing like a http
"content-length" field, and you don't want to use a temporary file.
My current idea is providing a container class (let's call it
DynamicMemBuffer) that uses a linked list of fixed-size byte[] buffers
internally. So a new DynamicMemBuffer starts with a single internal
buffer of size n. When n bytes have been added/written to the
DynamicMemBuffer, a new internal buffer is created, added to the
linked list, and writing of new bytes is directed into this buffer.
From the outside, the DynamicMemBuffer looks like a continuous byte
stream held in memory. As an interface, standard getInputStream() and
getOutputStream() methods could be provided.
While all of this is quite simple to implement, I'm reluctant to do so
because I can't imagine this problem hasn't been solved a thousand
times before.
So are there better approaches and/or ready-to-use classes out there?
Thanks,
Robert