private void closeCurrentStream() throws IOException { currentWriter.flush(); WGLOG.info("I04002", resourceName, processName, currentPath, currentStream.getCount()); bytesCount += currentStream.getCount(); try { currentStream.close(); } catch (IOException e) { WGLOG.error(e, "E04002", resourceName, processName, currentPath); throw e; } currentPath = null; currentStream = null; currentWriter = null; }
@Override public void put(T object) throws IOException { if (currentWriter == null || currentStream.getCount() >= eachStreamSize) { if (currentWriter != null) { closeCurrentStream(); } prepareNextStream(); } currentWriter.write(object); }
/** * Writes the local file header for the ZIP entry and positions the stream to the start of the * entry data. * * @param e the ZIP entry for which to write the local file header * @throws ZipException if a ZIP file error has occurred * @throws IOException if an I/O exception has occurred */ private void startEntry(ZipFileEntry e) throws IOException { if (e.getTime() == -1) { throw new IllegalArgumentException("Zip entry last modified time must be set"); } if (e.getCrc() == -1) { throw new IllegalArgumentException("Zip entry CRC-32 must be set"); } if (e.getSize() == -1) { throw new IllegalArgumentException("Zip entry uncompressed size must be set"); } if (e.getCompressedSize() == -1) { throw new IllegalArgumentException("Zip entry compressed size must be set"); } bytesWritten = 0; entry = e; entry.setFlag(Flag.DATA_DESCRIPTOR, false); entry.setLocalHeaderOffset(stream.getCount()); stream.write(LocalFileHeader.create(entry, zipData, allowZip64)); }
/** * Writes the ZIP file's central directory. * * @throws ZipException if a ZIP file error has occurred * @throws IOException if an I/O exception has occurred */ private void writeCentralDirectory() throws IOException { zipData.setCentralDirectoryOffset(stream.getCount()); CentralDirectory.write(zipData, allowZip64, stream); }