I have a piece of code like so…
FileInputStream fi = new FileInputStream(filein);
GZIPInputStream gzis = new GZIPInputStream(fi);
ByteBuffer bbuffer = ByteBuffer.allocate(115200);
The fi.available() is 84300, but the gzis.available() is only 1. The file(filein) is already compressed.
I want to read the file, uncompress it, and finally put it into my ByteBuffer bbufer.
How could I realize this operation?
gzis.available() = 1;doesn’t mean that there is a problem, it simply means that you can only read 1 byte of information from the Stream before you can continue. you can’t expect that the entire uncompressed file will be available in a single command.To read the entire file, you will need to have a loop that continues to read over the InputStream until you have all the data. For example…
Of course, if you aren’t sure of the final size of the uncompressed file, you’ll need to add in extra code to allow your
bbufferto be resized if you need more room.