Tengo una Object
comoarchivo zip de Java creado pero no la apertura, dice final inesperado de archivo
private String name;
private int age;
private String country;
// getters and setters
y funciones son
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);
}
}
que convertir esto en zip
archivo como
ByteArrayOutputStream stream = new ByteArrayOutputStream();
write(document, stream);
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(new File(getOutputFilePath(document.getUniqueId()))));
gzipOutputStream.write(stream.toByteArray());
Esto crea el archivo zip, pero cuando intento abrirlo, dice
gzip: document.xml.gz: unexpected end of file
¿Qué es lo que no estoy haciendo aquí?
¿Cierras abierto? – gkuzmin
eso fue, hice 'flush()' y 'close()' y funcionó, gracias por señalar que – daydreamer