Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Decompression using java.util.zip

  Asked By: Gerritt    Date: Nov 24    Category: Java    Views: 829
  

i am trying to test simple compression and
decompression. i have taken example from java doc
iteslf.
// Encode a String into bytes
String inputString = "blahblahblah??";
byte[] input = inputString.getBytes("UTF-8");

// Compress the bytes
byte[] output = new byte[100];
Deflater compresser = new Deflater();
compresser.setInput(input);
compresser.finish();
int compressedDataLength =
compresser.deflate(output);

// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(output, 0,
compressedDataLength);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();

// Decode the bytes into a String
String outputString = new String(result, 0,
resultLength, "UTF-8");


In this example am able to compress but using the
compressed data am unable to decompress.

output is like
compressed length is 2
uncompressed length is 0

when i see java docs it says inflate()
returns actual number of bytes uncompressed. A return
value of 0 indicates that needsInput() or
needsDictionary() should be called in order to
determine if more input data or a preset dictionary is
required. In the later case, getAdler() can be used to
get the Adler-32 value of the dictionary required.

but if i print
decompresser.needsInput() -- false
decompresser.needsDictionary() -- false

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Decompression using java.util.zip Or get search suggestion and latest updates.




Tagged: