Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Sep 10, 2023
1 parent 021d062 commit e9aed55
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String getString() throws IOException {
return getStringWithRetry(() -> {
HttpURLConnection con = createConnection();
con = resolveConnection(con);
return IOUtils.readFullyAsString(con.getInputStream());
return IOUtils.readFullyAsString("gzip".equals(con.getContentEncoding()) ? IOUtils.wrapFromGZip(con.getInputStream()) : con.getInputStream());
}, retryTimes);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.jackhuang.hmcl.util.io;

import java.io.*;
import java.util.zip.GZIPInputStream;

/**
* This utility class consists of some util methods operating on InputStream/OutputStream.
Expand Down Expand Up @@ -79,4 +80,8 @@ public static void copyTo(InputStream src, OutputStream dest, byte[] buf) throws
dest.write(buf, 0, len);
}
}

public static InputStream wrapFromGZip(InputStream inputStream) throws IOException {
return new GZIPInputStream(inputStream);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ public static String doPost(URL url, String post, String contentType) throws IOE
public static String readData(HttpURLConnection con) throws IOException {
try {
try (InputStream stdout = con.getInputStream()) {
return IOUtils.readFullyAsString(stdout);
return IOUtils.readFullyAsString("gzip".equals(con.getContentEncoding()) ? IOUtils.wrapFromGZip(stdout) : stdout);
}
} catch (IOException e) {
try (InputStream stderr = con.getErrorStream()) {
if (stderr == null)
throw e;
return IOUtils.readFullyAsString(stderr);
return IOUtils.readFullyAsString("gzip".equals(con.getContentEncoding()) ? IOUtils.wrapFromGZip(stderr) : stderr);
}
}
}
Expand Down

0 comments on commit e9aed55

Please sign in to comment.