我想压缩我的字符串值。这些字符串值应与.net
压缩字符串相同。
我编写了Decompress方法,当我向它发送一个.net
压缩字符串时,它可以正常工作。但是Compress方法不能正常工作。
public static String Decompress(String zipText) throws IOException {
int size = 0;
byte[] gzipBuff = Base64.decode(zipText);
ByteArrayInputStream memstream = new ByteArrayInputStream(gzipBuff, 4,
gzipBuff.length - 4);
GZIPInputStream gzin = new GZIPInputStream(memstream);
final int buffSize = 8192;
byte[] tempBuffer = new byte[buffSize];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((size = gzin.read(tempBuffer, 0, buffSize)) != -1) {
baos.write(tempBuffer, 0, size);
}
byte[] buffer = baos.toByteArray();
baos.close();
return new String(buffer, "UTF-8");
}
public static String Compress(String text) throws IOException {
byte[] gzipBuff = EncodingUtils.getBytes(text, "UTF-8");
ByteArrayOutputStream bs = new ByteArrayOutputStream();
GZIPOutputStream gzin = new GZIPOutputStream(bs);
gzin.write(gzipBuff);
gzin.finish();
bs.close();
byte[] buffer = bs.toByteArray();
gzin.close();
return Base64.encode(buffer);
}
For example when I send "BQAAAB+LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee++997o7nU4n99//P1xmZAFs9s5K2smeIYCqyB8/fnwfPyLmeVlW/w+GphA2BQAAAA==" to Decompress method It returns the string "Hello", but when I send "Hello" to Compress method It returns "H4sIAAAAAAAAAMtIzcnJBwCGphA2BQAAAA= ="。
Compress方法有什么问题???