Good Morning Friends
I have a compress data with type byte[]. Whenever i tried to write compress data into buffer it goes into infinite loop in some case. For example in 1000 file 2 or 3 files goes into infinite loop. That means those byte[] can not reach at its end of file.
MY Java Code is :
public static byte[] deCompressDoc(b yte[] compressedData) {
//Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater(true);
decompressor.se tInput(compress edData);
// Create an expandable byte array to hold the decompressed data
ByteArrayOutput Stream byteInputStream = new
ByteArrayOutput Stream(compress edData.length);
// Decompress the data
byte[] buf = new byte[1024];
while (!decompressor. finished()) {
try {
int count = decompressor.in flate(buf);
byteInputStream .write(buf, 0, count);
} catch (DataFormatExce ption e) {
throw new SDFException(" Error on Decompression of a
Document ", e);
}
}
try {
byteInputStream .close();
} catch (IOException e) {
throw new SDFException("E rror on Decompression of a
Document ", e);
}
// Get the decompressed data
byte[] decompressedDat a = byteInputStream .toByteArray();
return decompressedDat a;
}
The real problem is in some cases my while loop goes into infinite loop eventhoegh my byte[] is perfect.
Please give me a positive solution as early as possible.
Thanks
I have a compress data with type byte[]. Whenever i tried to write compress data into buffer it goes into infinite loop in some case. For example in 1000 file 2 or 3 files goes into infinite loop. That means those byte[] can not reach at its end of file.
MY Java Code is :
public static byte[] deCompressDoc(b yte[] compressedData) {
//Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater(true);
decompressor.se tInput(compress edData);
// Create an expandable byte array to hold the decompressed data
ByteArrayOutput Stream byteInputStream = new
ByteArrayOutput Stream(compress edData.length);
// Decompress the data
byte[] buf = new byte[1024];
while (!decompressor. finished()) {
try {
int count = decompressor.in flate(buf);
byteInputStream .write(buf, 0, count);
} catch (DataFormatExce ption e) {
throw new SDFException(" Error on Decompression of a
Document ", e);
}
}
try {
byteInputStream .close();
} catch (IOException e) {
throw new SDFException("E rror on Decompression of a
Document ", e);
}
// Get the decompressed data
byte[] decompressedDat a = byteInputStream .toByteArray();
return decompressedDat a;
}
The real problem is in some cases my while loop goes into infinite loop eventhoegh my byte[] is perfect.
Please give me a positive solution as early as possible.
Thanks
Comment