Package com.itextpdf.commons.utils
Class ZipFileWriter
- java.lang.Object
-
- com.itextpdf.commons.utils.ZipFileWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ZipFileWriter extends java.lang.Object implements java.io.Closeable
Allows writing entries into a zip file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
ZipFileWriter.ZipWriter
-
Field Summary
Fields Modifier and Type Field Description private java.util.zip.ZipOutputStream
outputStream
-
Constructor Summary
Constructors Constructor Description ZipFileWriter(java.lang.String archivePath)
Creates an instance for zip file writing.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntry(java.lang.String fileName, java.io.File file)
Add file from disk into zip archive.void
addEntry(java.lang.String fileName, java.io.InputStream inputStream)
Add file into zip archive with data from stream.private void
addEntryToZip(java.lang.String fileName, ZipFileWriter.ZipWriter writer)
void
addJsonEntry(java.lang.String fileName, java.lang.Object objectToAdd)
Add file into zip archive with object serialized as JSON.void
close()
-
-
-
Method Detail
-
addEntry
public void addEntry(java.lang.String fileName, java.io.File file) throws java.io.IOException
Add file from disk into zip archive.- Parameters:
fileName
- the target name of the file inside zip after writingfile
- the path to the file on disk to archive- Throws:
java.io.IOException
- if some I/O exception occurs
-
addEntry
public void addEntry(java.lang.String fileName, java.io.InputStream inputStream) throws java.io.IOException
Add file into zip archive with data from stream.- Parameters:
fileName
- the target name of the file inside zip after writinginputStream
- the input stream to archive- Throws:
java.io.IOException
- if some I/O exception occurs
-
addJsonEntry
public void addJsonEntry(java.lang.String fileName, java.lang.Object objectToAdd) throws java.io.IOException
Add file into zip archive with object serialized as JSON.- Parameters:
fileName
- the target name of the file inside zip after writingobjectToAdd
- the object to serialize as JSON- Throws:
java.io.IOException
- if some I/O exception occurs
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Throws:
java.io.IOException
-
addEntryToZip
private void addEntryToZip(java.lang.String fileName, ZipFileWriter.ZipWriter writer) throws java.io.IOException
- Throws:
java.io.IOException
-
-