|
17 | 17 | import java.net.URL;
|
18 | 18 | import java.util.Collections;
|
19 | 19 | import java.util.Scanner;
|
| 20 | +import java.util.zip.GZIPInputStream; |
| 21 | +import java.util.zip.GZIPOutputStream; |
20 | 22 |
|
21 | 23 | /**
|
22 | 24 | * Retrieve and publish templates for Firebase Remote Config using the REST API.
|
@@ -51,10 +53,12 @@ private static String getAccessToken() throws IOException {
|
51 | 53 | private static void getTemplate() throws IOException {
|
52 | 54 | HttpURLConnection httpURLConnection = getCommonConnection();
|
53 | 55 | httpURLConnection.setRequestMethod("GET");
|
| 56 | + httpURLConnection.setRequestProperty("Accept-Encoding", "gzip"); |
54 | 57 |
|
55 | 58 | int code = httpURLConnection.getResponseCode();
|
56 | 59 | if (code == 200) {
|
57 |
| - String response = inputstreamToString(httpURLConnection.getInputStream()); |
| 60 | + InputStream inputStream = new GZIPInputStream(httpURLConnection.getInputStream()); |
| 61 | + String response = inputstreamToString(inputStream); |
58 | 62 |
|
59 | 63 | JsonParser jsonParser = new JsonParser();
|
60 | 64 | JsonElement jsonElement = jsonParser.parse(response);
|
@@ -100,10 +104,12 @@ private static void publishTemplate(String etag) throws IOException {
|
100 | 104 | httpURLConnection.setDoOutput(true);
|
101 | 105 | httpURLConnection.setRequestMethod("PUT");
|
102 | 106 | httpURLConnection.setRequestProperty("If-Match", etag);
|
| 107 | + httpURLConnection.setRequestProperty("Content-Encoding", "gzip"); |
103 | 108 |
|
104 | 109 | String configStr = readConfig();
|
105 | 110 |
|
106 |
| - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(httpURLConnection.getOutputStream()); |
| 111 | + GZIPOutputStream gzipOutputStream = new GZIPOutputStream(httpURLConnection.getOutputStream()); |
| 112 | + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(gzipOutputStream); |
107 | 113 | outputStreamWriter.write(configStr);
|
108 | 114 | outputStreamWriter.flush();
|
109 | 115 | outputStreamWriter.close();
|
|
0 commit comments