Browse Source

decompress after decrypt if necessary

skip any decompress error
pull/1507/head
Chris Lu 4 years ago
parent
commit
0ed1f43d29
  1. 8
      other/java/client/src/main/java/seaweedfs/client/Gzip.java
  2. 4
      other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java

8
other/java/client/src/main/java/seaweedfs/client/Gzip.java

@ -18,14 +18,18 @@ public class Gzip {
return compressed;
}
public static byte[] decompress(byte[] compressed) throws IOException {
public static byte[] decompress(byte[] compressed) {
try {
ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
GZIPInputStream gis = new GZIPInputStream(bis);
return readAll(gis);
} catch (Exception e) {
return compressed;
}
}
private static byte[] readAll(InputStream input) throws IOException {
try( ByteArrayOutputStream output = new ByteArrayOutputStream()){
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
byte[] buffer = new byte[4096];
int n;
while (-1 != (n = input.read(buffer))) {

4
other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java

@ -119,6 +119,10 @@ public class SeaweedRead {
}
}
if (chunkView.isCompressed) {
data = Gzip.decompress(data);
}
LOG.debug("doFetchFullChunkData fid:{} chunkData.length:{}", chunkView.fileId, data.length);
return data;

Loading…
Cancel
Save