{
if (expSize <= 0) {
return gzipUncompress(compData);
}
byte[] buffer = new byte[expSize];
OptimizedGZIPInputStream in = new OptimizedGZIPInputStream(new ByteArrayInputStream(compData));
int offset = 0;
int left = buffer.length;
int count;
while (left > 0 && (count = in.read(buffer, offset, left)) > 0) {
offset += count;
left -= count;
}
// should have gotten exactly expected amount
try {
if (offset < expSize) {
throw new IOException("Corrupt GZIP/Deflate data: expected "+expSize+" bytes, got "+offset);
}
// and no more
if (in.read() != -1) {
throw new IOException("Corrupt GZIP/Deflate data: expected "+expSize+" bytes, got at least one more");
}
} finally {
try { in.close(); } catch (IOException e) { }
}
return buffer;
}