Java Utililty Methods Zip File

List of utility methods to do Zip File

Description

The list of methods to do Zip File are organized into topic(s).

Method

voidzip(InputStream is, String dataFileName, File zipFile)
Zip the given stream content into the given File
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zipout = new ZipOutputStream(fos);
ZipEntry zent = new ZipEntry(dataFileName);
zipout.putNextEntry(zent);
byte[] b = new byte[1024]; 
int bytesRead = 0; 
while ((bytesRead = is.read(b)) != -1) {
    zipout.write(b, 0, bytesRead);
...
voidzip(OutputStream outputStream, File targetFile)
zip
ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
try {
    addZipEntry(zipOutputStream, targetFile, "");
} finally {
    zipOutputStream.close();
byte[]zip(String data, String fileName)
Zips the specified Data String.
byte bytes[] = data.getBytes();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ZipOutputStream zipOut = new ZipOutputStream(byteStream);
ZipEntry entry = new ZipEntry(fileName);
zipOut.putNextEntry(entry);
zipOut.write(bytes, 0, bytes.length);
zipOut.closeEntry();
byte zipData[] = byteStream.toByteArray();
...
voidzip(String dir, String destFile)
zip
BufferedInputStream origin = null;
FileOutputStream dest = new FileOutputStream(destFile);
try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));) {
    int BUFFER = 2048;
    byte data[] = new byte[BUFFER];
    File f = new File(dir);
    String files[] = f.list();
    for (int i = 0; i < files.length; i++) {
...
voidzip(String filesDirToBeZipped, String destFileName, String manifest)
zip
try {
    BufferedInputStream origin = null;
    FileOutputStream dest = new FileOutputStream(destFileName);
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest));
    byte data[] = new byte[BUFFER];
    File f = new File(filesDirToBeZipped);
    String files[] = f.list();
    Vector v = new Vector();
...
byte[]zip(String inputStr)
zip
byte[] input = null;
try {
    input = inputStr.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
    return null;
byte[] output = new byte[64 * 1000];
Deflater compresser = new Deflater();
...
Booleanzip(String outputFileName, String inputFileName)
zip
ZipOutputStream out;
try {
    out = new ZipOutputStream(new FileOutputStream(outputFileName));
    File f = new File(inputFileName);
    if (f.exists()) {
        if (f.isDirectory()) {
            File[] fl = f.listFiles();
            for (File element : fl) {
...
StringZip(String path, File file)
Zip
if (file == null) {
    return null;
String zipFileName = "";
if (file.getName().indexOf(".") > -1) {
    zipFileName = file.getName().substring(0, file.getName().indexOf(".")) + ".zip";
} else {
    zipFileName = file.getName() + ".zip";
...
voidzip(String path, String zipFilePath)
zip
FileOutputStream fos = new FileOutputStream(zipFilePath);
ZipOutputStream zos = new ZipOutputStream(fos);
File file = new File(path);
putFileToZipEntry(zos, file, file.getName());
zos.close();
byte[]zip(String payload)
zip
byte[] data = payload.getBytes(CHARACTER_ENCODING_UTF_8);
ByteArrayOutputStream output = new ByteArrayOutputStream();
Deflater d = new Deflater();
try (DeflaterOutputStream dout = new DeflaterOutputStream(output, d)) {
    dout.write(data);
return output.toByteArray();