Java Zip Files makeZipBinary(Map instance, String fileNameSeperator)

Here you can find the source of makeZipBinary(Map instance, String fileNameSeperator)

Description

make Zip Binary

License

Open Source License

Declaration

public static byte[] makeZipBinary(Map<String, byte[]> instance, String fileNameSeperator) throws IOException 

Method Source Code

//package com.java2s;
/*/*  w w  w. j a va 2 s. co m*/
 * $Id: ZipUtil.java 7907 2008-04-21 09:50:49Z kamiya $
 * 
 * This is a program for Language Grid Core Node. This combines multiple language resources and
 * provides composite language services. Copyright (C) 2005-2008 NICT Language Grid Project.
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation, either version
 * 2.1 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.Map;
import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    public static byte[] makeZipBinary(Map<String, byte[]> instance, String fileNameSeperator) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(baos);
        try {
            for (String fileNameKey : instance.keySet()) {
                String fileName = fileNameKey.split(fileNameSeperator)[0];
                ZipEntry ze = new ZipEntry(fileName);
                zos.putNextEntry(ze);
                zos.write(instance.get(fileNameKey));
                zos.closeEntry();
            }
            return baos.toByteArray();
        } finally {
            zos.close();
        }
    }
}

Related

  1. addToZipFile(String fileName, ZipOutputStream zos)
  2. fileToZip(File file, File zipFile)
  3. fileToZipFile(File toZip, File output)
  4. makeZip(File dir, File zipFile)
  5. makeZip(String[] inFilePaths, String zipFilePath)