package org.voovan.tools;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

/**
 * 压缩算法
 * 
 * @author helyho
 *
 * Voovan Framework.
 * WebSite: https://github.com/helyho/Voovan
 * Licence: Apache v2 License
 */
public class TZip {
	/**
	 * GZip 解压缩
	 * @param encodeBytes 待解压字节
	 * @return 解压后的字节
	 * @throws IOException IO 异常
	 */
	public static byte[] decodeGZip(byte[] encodeBytes) throws IOException{
		GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(encodeBytes));
		return TStream.readAll(gzipInputStream);
	}
	
	/**
	 * GZIP 压缩
	 * @param sourceBytes 待压缩字节
	 * @return 压缩后的字节
	 * @throws IOException IO 异常
	 */
	public static byte[] encodeGZip(byte[] sourceBytes) throws IOException{
		ByteArrayOutputStream zipedBodyOutputStream = new ByteArrayOutputStream();
		GZIPOutputStream gzipOutputStream = new GZIPOutputStream(zipedBodyOutputStream);
		gzipOutputStream.write(sourceBytes);
		gzipOutputStream.finish();
		return zipedBodyOutputStream.toByteArray();
	}
	
	/**
	 * Zip 解压缩
	 * @param encodeBytes 待解压字节
	 * @return 解压后的字节
	 * @throws IOException IO 异常
	 */
	public static byte[] decodeZip(byte[] encodeBytes) throws IOException{
		ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(encodeBytes));
		return TStream.readAll(zipInputStream);
	}
	
	/**
	 * ZIP 压缩
	 * @param sourceBytes 待压缩字节
	 * @return 压缩后的字节
	 * @throws IOException IO 异常
	 */
	public static byte[] encodeZip(byte[] sourceBytes) throws IOException{
		ByteArrayOutputStream zipedBodyOutputStream = new ByteArrayOutputStream();
		ZipOutputStream zipOutputStream = new ZipOutputStream(zipedBodyOutputStream);
		zipOutputStream.write(sourceBytes);
		zipOutputStream.finish();
		return zipedBodyOutputStream.toByteArray();
	}
}

@@ -31,38 +31,38 @@
 ort 
-java.io.ByteArrayInputStream
+org.voovan.tools.log.Logger
 ;%0A
+%0A
 impo
@@ -73,35 +73,34 @@
 ava.io.ByteArray
-Out
+In
 putStream;%0Aimpor
@@ -113,133 +113,57 @@
 .io.
-IOException;%0Aimport java.util.zip.GZIPInputStream;%0Aimport java.util.zip.GZIPOutputStream;%0Aimport java.util.zip.ZipInputStream
+ByteArrayOutputStream;%0Aimport java.io.IOException
 ;%0Aim
@@ -181,31 +181,17 @@
 til.zip.
-ZipOutputStream
+*
 ;%0A%0A/**%0A 
@@ -1369,32 +1369,90 @@
 (encodeBytes));%0A
+%09%09Logger.simple(zipInputStream.getNextEntry().getName());%0A
 %09%09return TStream
@@ -1469,32 +1469,32 @@
 ipInputStream);%0A
-
 %09%7D%0A%09%0A%09/**%0A%09 * ZI
@@ -1645,32 +1645,87 @@
 ws IOException%7B%0A
+%09%09ZipEntry zipEntry = new ZipEntry(%22VoovanZipEntry%22);%0A%0A
 %09%09ByteArrayOutpu
@@ -1785,16 +1785,16 @@
 ream();%0A
-
 %09%09ZipOut
@@ -1865,16 +1865,58 @@
 tream);%0A
+%09%09zipOutputStream.putNextEntry(zipEntry);%0A
 %09%09zipOut

修复 TZip 中 Zip 压缩的错误