Java Utililty Methods ZipOutputStream Write

List of utility methods to do ZipOutputStream Write

Description

The list of methods to do ZipOutputStream Write are organized into topic(s).

Method

voidarchiveFile(String relativePath, ZipOutputStream zos, File root)
archive File
byte[] buffer = new byte[1024];
File[] files = root.listFiles();
for (int i = 0; i < files.length; i++) {
    File f = files[i];
    String path = null;
    if (relativePath == null) {
        path = f.getName();
    } else {
...
voidwriteFolderEntry(ZipOutputStream zout, String relpath)
Writes a new folder entry to the ZIP file.
if (relpath.length() > 0 && !relpath.endsWith("/")) {
    relpath += "/";
ZipEntry entry = new ZipEntry(relpath);
zout.putNextEntry(entry);
zout.closeEntry();
voidzip(File current, String rootPath, ZipOutputStream zipStream, byte[] buffer)
zip
if (current.isDirectory()) {
    for (File file : current.listFiles()) {
        if (!".".equals(file.getName()) && !"..".equals(file.getName())) {
            zip(file, rootPath, zipStream, buffer);
} else if (current.isFile()) {
    zipStream.putNextEntry(new ZipEntry(current.getPath().replace(rootPath, "")));
...
voidzip(File[] files, String baseDir, ZipOutputStream zos)
zip
byte buffer[] = new byte[BUFFER_SIZE];
for (File f : files) {
    String name = f.getAbsolutePath();
    if (name.startsWith(baseDir)) {
        name = name.substring(baseDir.length());
    if (name.startsWith(System.getProperty("file.separator"))) {
        name = name.substring(1);
...
voidzip(final File directory, final File base, final ZipOutputStream zipOutputStream)
zip
File[] files = directory.listFiles();
byte[] buffer = new byte[ZIP_BUFFER_SIZE];
int read = 0;
for (int i = 0, n = files.length; i < n; i++) {
    if (files[i].isDirectory()) {
        zip(files[i], base, zipOutputStream);
    } else {
        FileInputStream fileInputStream = new FileInputStream(files[i]);
...
voidzipAutoBase(File f, File base, ZipOutputStream out)
zip Auto Base
if (f.isDirectory()) {
    for (File file : f.listFiles()) {
        zipAutoBase(file, base, out);
} else {
    String path = f.getPath().replace(base.getPath(), "");
    if (path.startsWith(System.getProperty("file.separator"))) {
        path = path.substring(1);
...
voidzipFile(ZipOutputStream out, File file, String dir)
zip File
if (file.isDirectory()) {
    out.putNextEntry(new ZipEntry(dir + "/"));
    dir = dir.length() == 0 ? "" : dir + "/";
    File[] files = file.listFiles();
    for (int i = 0; i < files.length; i++) {
        zipFile(out, files[i], dir + files[i].getName());
} else {
...
voidzipFile(ZipOutputStream out, File sourceFile)
zip File
System.out.println("Adding File: " + sourceFile.getAbsolutePath());
FileInputStream fi = new FileInputStream(sourceFile);
BufferedInputStream origin = new BufferedInputStream(fi, BUFFER);
String entryName = sourceFile.getAbsolutePath().substring(sourceFile.getAbsolutePath().indexOf(':') + 2,
        sourceFile.getAbsolutePath().length());
ZipEntry entry = new ZipEntry(entryName);
out.putNextEntry(entry);
int count;
...
voidzipFile(ZipOutputStream out, String stripPath, File file, char pathSeparator)
Uses code fragments from Jakarta-Ant, Copyright: Apache Software Foundation.
ZipEntry ze = new ZipEntry(processPath(file.getPath(), stripPath, pathSeparator));
ze.setTime(file.lastModified());
out.putNextEntry(ze);
byte[] buffer = new byte[8 * 1024];
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file), buffer.length);
try {
    int count = 0;
    while ((count = in.read(buffer, 0, buffer.length)) >= 0) {
...
voidzipFile(ZipOutputStream zipOut, String path, File file)
zip File
if (!file.canRead()) {
    System.out.println("Cannot read " + file.getCanonicalPath() + " (maybe because of permissions)");
    return;
System.out.println("Compressing " + file.getName());
zipOut.putNextEntry(new ZipEntry(file.getName()));
FileInputStream fis = new FileInputStream(file);
byte[] buffer = new byte[4092];
...