Java ZipEntry Add addZipEntryFromStream(InputStream is, ZipOutputStream os, String filename)

Here you can find the source of addZipEntryFromStream(InputStream is, ZipOutputStream os, String filename)

Description

add Zip Entry From Stream

License

Apache License

Declaration

private static void addZipEntryFromStream(InputStream is,
            ZipOutputStream os, String filename) throws IOException 

Method Source Code

//package com.java2s;
/*//from   ww  w  .  j a  v a 2  s  . c om
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.IOException;
import java.io.InputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    public static final int INT = 512;

    private static void addZipEntryFromStream(InputStream is,
            ZipOutputStream os, String filename) throws IOException {
        byte[] buf = new byte[INT];
        os.putNextEntry(new ZipEntry(filename));

        int len;
        while ((len = is.read(buf)) > 0) {
            os.write(buf, 0, len);
        }

        // Complete the entry
        os.closeEntry();
    }
}

Related

  1. addZipEntry(String pathName, byte[] contents, ZipOutputStream zos)
  2. addZipEntry(ZipOutputStream zipOut, File file, String prefix)
  3. addZipEntry(ZipOutputStream zipOutputStream, File entryFile, String parentPath)
  4. addZipEntry(ZipOutputStream zos, File fileToZip, File baseFolder)
  5. addZipEntryRecursive(ZipOutputStream zipOut, File file, String prefix)