How to initialize a ByteBuffer if you don't know how many bytes to allocate beforehand?

Viewed 38254

Is this:

ByteBuffer buf = ByteBuffer.allocate(1000);

...the only way to initialize a ByteBuffer?

What if I have no idea how many bytes I need to allocate..?

Edit: More details:

I'm converting one image file format to a TIFF file. The problem is the starting file format can be any size, but I need to write the data in the TIFF to little endian. So I'm reading the stuff I'm eventually going to print to the TIFF file into the ByteBuffer first so I can put everything in Little Endian, then I'm going to write it to the outfile. I guess since I know how long IFDs are, headers are, and I can probably figure out how many bytes in each image plane, I can just use multiple ByteBuffers during this whole process.

3 Answers
Related