Hi I am using GZIP for compression and decompression of strings.
Getting Some Exceptions ! Please Help me out !
protected byte[] CompressInputString(String input_string2)
throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream(
input_string2.length());
System.out.println("Byte Array OS : " + os);
GZIPOutputStream gos = new GZIPOutputStream(os);
System.out.println("GZIPOutputStream : " + gos);
gos.write(input_string2.getBytes());
System.out.println("GZIPOutputStream get bytes: "
+ input_string2.getBytes());
gos.close();
byte[] compressed = os.toByteArray();
os.close();
System.out.println("Compressed : " + compressed);
return compressed;
}
protected String DecompressInputString(byte[] input_to_decode_from_function)
throws IOException {
final int BUFFER_SIZE = 32;
ByteArrayInputStream is = new ByteArrayInputStream(input_to_decode_from_function);
GZIPInputStream gis = new GZIPInputStream(is, BUFFER_SIZE);
StringBuilder string = new StringBuilder();
byte[] data = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = gis.read(data)) != -1) {
string.append(new String(data, 0, bytesRead));
}
gis.close();
is.close();
return string.toString();
}
My input is : abcdefghijklmnop
The output is
GZIPOutputStream : java.util.zip.GZIPOutputStream@f38798
GZIPOutputStream get bytes: [B@4b222f
Compressed : [B@b169f8
Compressed File : [B@b169f8
To uncompress, what input do I give?
If I put [B@b169f8 as string input and convert it to byte array using input.getBytes() and pass it to my decompress function, an exception is raised

String.getBytes()without specifying an encoding... - Jon Skeet