Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.zip.ZipException: invalid bit length repeat EXCEPTION.

807588Jul 2 2008 — edited Jan 21 2009
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2009
Added on Jul 2 2008
6 comments
9,308 views