I’m trying to send GZipped map data over the network. For some reason, this code only reads 37747 bytes rather than the needed amount (5 * 512 * 512 in this case).
int width = bb.getInt();
int height = bb.getInt();
byte[] arr = mapCache.array(); //This is an array of GZIPped data
ByteArrayInputStream bIn = new ByteArrayInputStream(arr);
GZIPInputStream gzIn = new GZIPInputStream(bIn);
byte[] levelBytes = new byte[5 * (width * height)];
System.err.println(gzIn.read(levelBytes, 0, 5 * (width * height))); //37747
gzIn.close();
bIn.close();
I tried redirecting mapCache to a file and opening it with 7Zip, and got the complete level.
Thanks for any help.
EDIT: Answered my own, question, read() isn’t supposed to read fully the first time.