Java FileOutputStream Write saveZip(String fileName, Map dataMap)

Here you can find the source of saveZip(String fileName, Map dataMap)

Description

save Zip

License

Open Source License

Declaration

public static void saveZip(String fileName, Map<String, InputStream> dataMap) 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;

public class Main {
    public static void saveZip(String fileName, Map<String, InputStream> dataMap) {
        try {/*from www .j av  a 2 s.c o m*/
            FileOutputStream fos = new FileOutputStream(fileName);
            JarOutputStream jos = new JarOutputStream(fos);
            byte buf[] = new byte[256];
            if (dataMap != null) {
                Set<Entry<String, InputStream>> entrySet = dataMap.entrySet();
                int len = -1;
                for (Entry<String, InputStream> entry : entrySet) {
                    String name = entry.getKey();
                    InputStream inputStream = entry.getValue();
                    if (name != null && inputStream != null) {
                        BufferedInputStream bis = new BufferedInputStream(inputStream);
                        JarEntry jarEntry = new JarEntry(name);
                        jos.putNextEntry(jarEntry);

                        while ((len = bis.read(buf)) >= 0) {
                            jos.write(buf, 0, len);
                        }

                        bis.close();
                        jos.closeEntry();
                    }
                }
            }
            jos.flush();
            jos.close();
            fos.flush();
            fos.close();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. saveToFile(String data, File file)
  2. saveToFile(String fileName, String fileCode, File dir, String fileExtention)
  3. saveToFile(String filePath, InputStream in)
  4. saveToTextFile(String filename, byte[] text)
  5. SaveToZipSB(File file, String ZippedFile, StringBuilder sb)
  6. saveZipFile(String zipFileName, File toBeZipped)