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
*/
public static byte[] compress(byte[] body) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(output)) {
gzipOutputStream.write(body);
}
} finally {
output.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(baos)) {
gzipOutputStream.write(body);
}
return output.toByteArray();
return baos.toByteArray();
}
/**