org.wildfly.common.archive.JDKSpecific Maven / Gradle / Ivy
Go to download
This artifact provides a single jar that contains all classes required to use remote EJB and JMS, including
all dependencies. It is intended for use by those not using maven, maven users should just import the EJB and
JMS BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up
with different versions on classes on the class path).
package org.wildfly.common.archive;
import static java.lang.Math.min;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
/**
*/
final class JDKSpecific {
private JDKSpecific() {}
static ByteBuffer inflate(final Inflater inflater, final ByteBuffer[] bufs, final long offset, final int compSize, final int uncompSize) throws DataFormatException, IOException {
int cnt = 0;
byte[] b = new byte[min(16384, compSize)];
byte[] out = new byte[uncompSize];
int op = 0;
while (cnt < compSize) {
int rem = compSize - cnt;
final int acnt = min(rem, b.length);
Archive.readBytes(bufs, offset, b, 0, acnt);
cnt += acnt;
inflater.setInput(b, 0, acnt);
do {
op += inflater.inflate(out, op, uncompSize - op);
} while (! inflater.needsInput());
}
if (! inflater.finished()) {
throw new IOException("Corrupted compression stream");
}
return ByteBuffer.wrap(out);
}
}