Here you can find the source of addToZipFile(InputStream source, String entryName, ZipOutputStream zos)
public static void addToZipFile(InputStream source, String entryName, ZipOutputStream zos) throws FileNotFoundException, IOException
//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(); } }