I don't think you are properly closing both the fileOutputStream and the GZIPOutputStream.
GZIPOutputStream requires that you call close()
on it when you are done to finish writing out the zipped data. This will require you to hold onto a reference to the GZIPOutputStream.
Here is what I think the code should be
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
// File Header
out.write(MAGIC); // an 8 byte array (like new byte[] {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'}) to identify the file format
out.writeShort(VERSION); // a short (like 1)
// GZIP that stuff
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
GZIPOutputStream zippedStream =new GZIPOutputStream(bytes)
mapper.writeValue(zippedStream, /* my data */); // mapper is the Jackson ObjectMapper, my data is a Map<String, Object>
zippedStream.close();
byte[] data = bytes.toByteArray();
out.writeInt(data.length);
out.write(data);
out.close();