My requirement is I need to compress a Big String and send it from server to Client. At the client end I need to decompress it back to get the original String
The size of my compressed String is 30447
When I uncompress it. I get this error
java.util.zip.ZipException: invalid bit length repeat
The following below is the code used for Compressing and Uncompressing a String._
private static void decompressString(byte[] baFileContentCompressed) {
ByteArrayOutputStream baos;
ByteArrayInputStream bais = new ByteArrayInputStream(
baFileContentCompressed);
GZIPInputStream zis = null;
byte[] buffer = new byte[8192];
// the result
byte[] baFileContentDecompressed = null;
baos = new ByteArrayOutputStream();
try {
buffer = new byte[1024];
try {
zis = new GZIPInputStream(bais);
for (int len; (len = zis.read(buffer, 0, 1024)) != -1;) {
baos.write(buffer, 0, len);
}
zis.close();
bais.close();
baos.close();
baFileContentDecompressed = baos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(new String(baFileContentDecompressed));
} catch (Exception e) {
e.printStackTrace();
}
}
private static byte[] compressInputString(String testData) {
byte[] baFileContent = testData.getBytes();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream zos;
try {
zos = new GZIPOutputStream(baos);
zos.write(baFileContent);
zos.close();
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
byte[] baFileContentCompressed = baos.toByteArray();
return baFileContentCompressed;
}
The exception is thrown when len = zis.read(buffer, 0, 1024)
is invoked
Need some help here.
Regards,
Bob
Edited by: hemanthjava on Jul 2, 2008 6:21 AM