我正在尝试编写一个compress utils类.
但是在测试期间,我发现结果大于原始缓冲区.
我的代码是对的吗?
请参阅代码:
/**
* This class provide compress ability
* <p>
* Support:
* <li>GZIP
* <li>Deflate
*/
public class CompressUtils {
final public static int DEFAULT_BUFFER_SIZE = 4096; // Compress/Decompress buffer is 4K
/**
* GZIP Compress
*
* @param data The data will be compressed
* @return The compressed data
* @throws IOException
*/
public static byte[] gzipCompress(byte[] data) throws IOException {
Validate.isTrue(ArrayUtils.isNotEmpty(data));
ByteArrayInputStream bis = new ByteArrayInputStream(data);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try { …Run Code Online (Sandbox Code Playgroud)