Out of memory exception ved unzip
Hej Eksperter.Jeg har lavet denne unzip metode men hvis filen jeg prøver at unzippe ikke er valid så får jeg en out of memory exception fordi den bliver ved med at loope. Koden kommer her.
public static byte[] unZipData(byte[] input) throws Exception {
//Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater();
decompressor.setInput(input);
// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos2 = new ByteArrayOutputStream(input.length);
// Decompress the data
byte[] buf2 = new byte[1024];
while (!decompressor.finished()) {
try {
int count = decompressor.inflate(buf2);
bos2.write(buf2, 0, count);
} catch (DataFormatException e) {
throw e;
}
}
try {
bos2.close();
} catch (IOException e) {
}
// Get the decompressed data
return bos2.toByteArray();
}