I have a Object as
private String name;
private int age;
private String country;
// getters and setters
I convert this object into XML using JAXB as following
OutputStream stream = new ObjectOutputStream(new FileOutputStream(getOutputFilePath(document.getUniqueId())));
write(proposal, stream);
and
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);
}
}
How can I convert this stream into Zip file on disk?
Java has a number of classes for dealing with compression in various ways. Here’s a useful link: Compressing and Decompressing Data Using Java APIs