mam Object
jakJava plik zip utworzony, ale nie otwarcie mówi nieoczekiwany koniec pliku
private String name;
private int age;
private String country;
// getters and setters
i funkcje są
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);
}
}
przekonwertować to do zip
pliku jako
ByteArrayOutputStream stream = new ByteArrayOutputStream();
write(document, stream);
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(new File(getOutputFilePath(document.getUniqueId()))));
gzipOutputStream.write(stream.toByteArray());
Spowoduje to utworzenie pliku zip, ale gdy spróbuję go otworzyć, pojawi się komunikat:
gzip: document.xml.gz: unexpected end of file
Co ja tu nie robię?
Czy zamknąć otwarte strumienia wyjściowego gzip? – gkuzmin
to było to, zrobiłem 'flush()' i 'close()' i działało, dziękuję za wskazanie, że na zewnątrz – daydreamer