Java ZipOutputStream Write zipFile(ZipOutputStream out, File sourceFile)

Here you can find the source of zipFile(ZipOutputStream out, File sourceFile)

Description

zip File

License

Open Source License

Declaration

private static void zipFile(ZipOutputStream out, File sourceFile) throws IOException 

Method Source Code

//package com.java2s;
/**/*from  w w  w  .jav a2  s . c  o m*/
 * Copyright (c) 2015 SK holdings Co., Ltd. All rights reserved.
 * This software is the confidential and proprietary information of SK holdings.
 * You shall not disclose such confidential information and shall use it only in
 * accordance with the terms of the license agreement you entered into with SK holdings.
 * (http://www.eclipse.org/legal/epl-v10.html)
 */

import java.io.BufferedInputStream;

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    private static final int BUFFER = 2048;

    private static void zipFile(ZipOutputStream out, File sourceFile) throws IOException {
        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;
        byte data[] = new byte[BUFFER];
        while ((count = origin.read(data, 0, BUFFER)) != -1) {
            out.write(data, 0, count);
        }
        origin.close();
    }
}

Related

  1. zip(File current, String rootPath, ZipOutputStream zipStream, byte[] buffer)
  2. zip(File[] files, String baseDir, ZipOutputStream zos)
  3. zip(final File directory, final File base, final ZipOutputStream zipOutputStream)
  4. zipAutoBase(File f, File base, ZipOutputStream out)
  5. zipFile(ZipOutputStream out, File file, String dir)
  6. zipFile(ZipOutputStream out, String stripPath, File file, char pathSeparator)
  7. zipFile(ZipOutputStream zipOut, String path, File file)
  8. zipFile(ZipOutputStream zos, BufferedOutputStream out, File destPath, String originalPath)
  9. zipFile(ZipOutputStream zos, File file, String requestName, byte[] buf)