I have a Object
as
private String name;
private int age;
private String country;
// getters and setters
and functions are
protected void write(@Nonnull final Document document, @Nonnull final OutputStream stream) throws PersistenceException {
try {
jaxbContext.createMarshaller().marshal(document, stream);
} catch (final JAXBException e) {
LOGGER.error(e.getMessage(), e);
throw new PersistenceException("Failed to marshall document " + docment.getUniqueId() + ": " + e.getMessage(), e);
}
}
I convert this into zip
file as
ByteArrayOutputStream stream = new ByteArrayOutputStream();
write(document, stream);
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(new File(getOutputFilePath(document.getUniqueId()))));
gzipOutputStream.write(stream.toByteArray());
This creates the zip file, but when I try to open it up, it says
gzip: document.xml.gz: unexpected end of file
What is that I am not doing right here?
You need to make sure to call:
gzipOutputStream.flush();
and eventually
gzipOutputStream.close();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With