Zip
Overview
Module
- package:
org.eclipse.dirigible.sdk.io - source: io/Zip.java
ZIP archive creation and extraction. Two styles are supported:
- The folder-level shortcuts
importZip(String, String)(extract everything under a directory) andexportZip(String, String)(zip a folder onto disk). - The streaming form via
ZipInputStream/ZipOutputStreamwhen you want entry-by-entry control — useful for producing a download on the fly, scanning archives without writing intermediate files, or filtering entries during extraction.
For end-to-end "zip this folder, send it" workflows the shortcuts are enough; reach for the streaming overloads only when you need entry-level control.
Key Features:
- One-shot folder import/export: Extract or create archives in a single call.
- Streaming form: Wrap any
InputStream/OutputStreamwithZipInputStream/ZipOutputStreamfor entry-by-entry processing. - Read/write helpers: Read or write the current entry as text or bytes.
Example Usage:
import java.io.OutputStream;
import java.util.zip.ZipOutputStream;
import org.eclipse.dirigible.sdk.io.Zip;
// folder-level export
Zip.exportZip("/var/data/project", "/var/tmp/project.zip");
// streaming export with two entries
try (OutputStream out = /* HTTP response stream, file stream, ... */ null) {
ZipOutputStream zos = Zip.createZipOutputStream(out);
zos.putNextEntry(Zip.createZipEntry("hello.txt"));
Zip.writeText(zos, "Hello, world!");
zos.closeEntry();
}Methods
importZip()
Extracts the ZIP archive at zipPath into targetPath.
javapublic static void importZip(String zipPath, String targetPath);
Parameter Type Description zipPathStringPath to the ZIP archive. targetPathStringDirectory to extract into. Returns
- Type:
void
exportZip()
Compresses the contents of folderPath into a ZIP archive written to zipPath.
javapublic static void exportZip(String folderPath, String zipPath);
Parameter Type Description folderPathStringDirectory to compress. zipPathStringOutput path for the ZIP archive. Returns
- Type:
void
createZipInputStream()
Wraps an existing InputStream as a ZipInputStream for entry-by-entry reading.
javapublic static ZipInputStream createZipInputStream(InputStream in) throws IOException;
Parameter Type Description inInputStreamThe underlying input stream. Returns
- Type:
ZipInputStream- Description: A ZIP-aware input stream over the same bytes.
createZipOutputStream()
Wraps an existing OutputStream as a ZipOutputStream so you can write ZIP entries to it.
javapublic static ZipOutputStream createZipOutputStream(OutputStream out) throws IOException;
Parameter Type Description outOutputStreamThe underlying output stream. Returns
- Type:
ZipOutputStream- Description: A ZIP-aware output stream over the same sink.
createZipEntry()
Creates a new ZipEntry with the given name. Pass to ZipOutputStream.putNextEntry(...).
javapublic static ZipEntry createZipEntry(String name) throws IOException;
Parameter Type Description nameStringEntry name (path inside the archive). Returns
- Type:
ZipEntry- Description: A new ZIP entry with the given name.
write()
Writes raw bytes or a string-encoded payload to the current entry of the given ZipOutputStream.
javapublic static void write(ZipOutputStream output, byte[] bytes) throws IOException; public static void write(ZipOutputStream output, String data) throws IOException;
Parameter Type Description outputZipOutputStreamThe ZIP output stream. bytesbyte[]Raw bytes to write. dataStringString-encoded bytes to write. Returns
- Type:
void
writeNative()
Writes a native Java byte array to the current entry of the given ZipOutputStream.
javapublic static void writeNative(ZipOutputStream output, byte[] data) throws IOException;
Parameter Type Description outputZipOutputStreamThe ZIP output stream. databyte[]The byte array to write. Returns
- Type:
void
writeText()
Writes text to the current entry of the given ZipOutputStream using the platform default encoding.
javapublic static void writeText(ZipOutputStream output, String text) throws IOException;
Parameter Type Description outputZipOutputStreamThe ZIP output stream. textStringThe text to write. Returns
- Type:
void
read()
Reads the current entry of the given ZipInputStream and returns its contents as a string-encoded byte payload.
javapublic static String read(ZipInputStream input) throws IOException;
Parameter Type Description inputZipInputStreamThe ZIP input stream. Returns
- Type:
String- Description: The string-encoded byte content of the current entry.
readNative()
Reads the current entry of the given ZipInputStream into a native Java byte array.
javapublic static byte[] readNative(ZipInputStream input) throws IOException;
Parameter Type Description inputZipInputStreamThe ZIP input stream. Returns
- Type:
byte[]- Description: The bytes of the current entry.
readText()
Reads the current entry of the given ZipInputStream and decodes it as text using the platform default encoding.
javapublic static String readText(ZipInputStream input) throws IOException;
Parameter Type Description inputZipInputStreamThe ZIP input stream. Returns
- Type:
String- Description: The decoded text content of the current entry.