@Optional("1") int encodingMode)
{
TempBuffer tempBuf = TempBuffer.allocate();
byte[] buffer = tempBuf.getBuffer();
TempStream ts = new TempStream();
StreamImplOutputStream out = new StreamImplOutputStream(ts);
ZlibOutputStream gzOut = null;
try {
gzOut = new ZlibOutputStream(out, level,
Deflater.DEFAULT_STRATEGY,
encodingMode);
int len;
while ((len = is.read(buffer, 0, buffer.length)) > 0) {
gzOut.write(buffer, 0, len);
}
gzOut.close();
StringValue sb = env.createBinaryBuilder();
for (TempBuffer ptr = ts.getHead(); ptr != null; ptr = ptr.getNext())
sb.append(ptr.getBuffer(), 0, ptr.getLength());
return sb;
} catch(IOException e) {
throw QuercusModuleException.create(e);
} finally {
TempBuffer.free(tempBuf);
ts.destroy();
if (gzOut != null)
gzOut.close();
}
}