JessYanCoding / JessYanCoding/MVPArms

gzip解码中文字符出现乱码

Open
#354 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
10.2k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

Environment

- [x] MVPArms Version: 2.5.2
- [x] AndroidStudio Version: 3.5.3

### Bug Description:
ZipHelper#decompressForGzip
while ((bytesRead = gis.read(data)) != -1) {
string.append(new String(data, 0, bytesRead, charsetName));
}
拼接中文时会乱码

### Related Code:
```
if (compressed.length == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(compressed);
try {
GZIPInputStream ungzip = new GZIPInputStream(in);
byte[] buffer = new byte[256];
int n;
while ((n = ungzip.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
closeQuietly(ungzip);
return out.toString(charsetName);
} catch (IOException e) {
e.printStackTrace();
} finally {
closeQuietly(in);
closeQuietly(out);
}
return null;
```
替换为以下代码可修复
```
if (compressed.length == 0) {
return null;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayInputStream in = new ByteArrayInputStream(compressed);
try {
GZIPInputStream ungzip = new GZIPInputStream(in);
byte[] buffer = new byte[256];
int n;
while ((n = ungzip.read(buffer)) >= 0) {
out.write(buffer, 0, n);
}
closeQuietly(ungzip);
return out.toString(charsetName);
} catch (IOException e) {
e.printStackTrace();
} finally {
closeQuietly(in);
closeQuietly(out);
}
return null;

```

### Others:
![image](https://user-images.githubusercontent.com/29949867/73718791-6d059d00-4758-11ea-9545-f6231392da1a.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.