Java Zip Files addToZipFile(InputStream source, String entryName, ZipOutputStream zos)

Here you can find the source of addToZipFile(InputStream source, String entryName, ZipOutputStream zos)

Description

add To Zip File

License

Open Source License

Declaration

public static void addToZipFile(InputStream source, String entryName,
            ZipOutputStream zos) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2016 Red Hat, Inc./*from   w  ww. j a va  2  s. c  o  m*/
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributor:
 *     Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

import java.io.FileNotFoundException;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    public static void addToZipFile(InputStream source, String entryName,
            ZipOutputStream zos) throws FileNotFoundException, IOException {
        ZipEntry zipEntry = new ZipEntry(entryName);
        zos.putNextEntry(zipEntry);

        byte[] bytes = new byte[1024];
        int length;
        while ((length = source.read(bytes)) >= 0) {
            zos.write(bytes, 0, length);
        }

        zos.closeEntry();
        source.close();
    }
}

Related

  1. addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden, Set excludeEntries)
  2. addToZip(String path, String srcFile, ZipOutputStream zip)
  3. addToZip(String path, String srcFile, ZipOutputStream zip)
  4. addToZip(String[] sourceFiles, ZipOutputStream output)
  5. addToZip(ZipOutputStream zos, String rootDirectoryName, String fileName)
  6. addToZipFile(String fileName, ZipOutputStream zos)
  7. fileToZip(File file, File zipFile)
  8. fileToZipFile(File toZip, File output)
  9. makeZip(File dir, File zipFile)