I am using below code to compress my test string into gzip format
'private static final String TEST_STRING = "Test String";
public static void main(String[] args) throws IOException {
System.out.println("Original data: " + TEST_STRING);
String compressedString = compress(TEST_STRING);
System.out.println("Compressed data: " + compressedString);
}
private static String compress(String str){
byte[] byteArray = str.getBytes();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream)) {
gzipOutputStream.write(byteArray);
} catch (IOException e) {
System.out.println("Exception occurred during compressing" + e);
}
return new String(byteArrayOutputStream.toByteArray());
}'
Output I am getting is Compressed data: �I-..)��K ��w�
BUT when I try to compress the same test string using any online gzip converter its giving me: eJwLSS0uUQguKcrMSwcAGKAEOA==
I am not sure why this difference is coming?