package com.vci.client.workflow.editor;
|
|
import java.io.BufferedInputStream;
|
import java.io.ByteArrayOutputStream;
|
import java.io.FileInputStream;
|
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 ZipUtil {
|
|
// 调用该方法生成zip文件
|
public static void saveZip(String fileName, Map<String, InputStream> dataMap) {
|
try {
|
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);
|
}
|
}
|
|
public static byte[] transformInputstream(FileInputStream input) throws Exception {
|
byte[] byt = null;
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
int b = 0;
|
b = input.read();
|
while (b != -1) {
|
baos.write(b);
|
b = input.read();
|
}
|
byt = baos.toByteArray();
|
return byt;
|
}
|
|
}
|