2
我有一個Object
作爲如何在Java中壓縮Object流?
private String name;
private int age;
private String country;
// getters and setters
我轉換這個對象爲使用JAXB
XML
如下
OutputStream stream = new ObjectOutputStream(new FileOutputStream(getOutputFilePath(document.getUniqueId())));
write(proposal, stream);
和
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);
}
}
我如何轉換這種stream
到磁盤Zip文件?
[ZipOutputStream(http://docs.oracle.com/javase/6/docs/api/的java/UTIL /拉鍊/ ZipOutputStream.html) –