从第三方应用查询回来的数据在做解压解码的时候发生中文乱码的情况。
/**
*
* <p>Description:使用gzip进行解压缩</p>
* @param compressedStr
* @return
*/
public static String gunzip(String compressedStr) {
if (compressedStr == null) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = null;
GZIPInputStream ginzip = null;
byte[] compressed = null;
String decompressed = null;
try {
compressed = new sun.misc.BASE64Decoder().decodeBuffer(compressedStr);
in = new ByteArrayInputStream(compressed);
ginzip = new GZIPInputStream(in);
byte[] buffer = new byte[1024];
int offset = -1;
while ((offset = ginzip.read(buffer)) != -1) {
out.write(buffer, 0, offset);
}
decompressed = out.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ginzip != null) {
try {
ginzip.close();
} catch (IOException e) {
}
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
return decompressed;
}
应用1 访问 应用2的接口
应用2 访问 第三方应用的接口 查询数据
在应用2中使用上述方法可以对查询回来的数据进行解码,中文未发现乱码情况
当应用2将查询结果原样返回给应用1时,在应用1中使用上述方法可以对查询回来的数据进行解码,发生中文乱码的情况,字符集都是UTF8的
请问这是为什么呢?该如何解决呢。