BAEL-3188 How to compress requests using the Spring RestTemplate. Updated GzipUtils code following editor review. (#7746)

This commit is contained in:
hugogiordano 2019-09-08 15:08:40 +10:00 committed by maibin
parent f53e9e55eb
commit 4cf99eb77c

View File

@ -30,15 +30,11 @@ public class GzipUtils {
* @throws IOException * @throws IOException
*/ */
public static byte[] compress(byte[] body) throws IOException { public static byte[] compress(byte[] body) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
try { try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(baos)) {
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(output)) {
gzipOutputStream.write(body); gzipOutputStream.write(body);
} }
} finally { return baos.toByteArray();
output.close();
}
return output.toByteArray();
} }
/** /**