Deflater deflater = new Deflater(level); byte[] input = data.getBytes(); deflater.setInput(input); deflater.finish();
TempBuffer buf = TempBuffer.allocate(); byte []buffer = buf.getBuffer(); boolean isFinished = false; TempStream out = new TempStream();
  public Value gzcompress(String data,                          @Optional("-1") int level)    throws DataFormatException, IOException  {    if (level == -1)      level = Deflater.DEFAULT_COMPRESSION;    Deflater deflater = new Deflater(level);    byte[] input = data.getBytes();    deflater.setInput(input);    deflater.finish();    byte[] output = new byte[input.length];    ByteBuffer buf = new ByteBuffer();    int compressedDataLength;    int fullCompressedDataLength = 0;    while (!deflater.finished()) {      compressedDataLength = deflater.deflate(output);      fullCompressedDataLength += compressedDataLength;      buf.append(output,0,compressedDataLength);    }    ByteArrayInputStream result = new ByteArrayInputStream(buf.getBuffer(),0,fullCompressedDataLength);    ReadStream readStream = new ReadStream(new VfsStream(result,null));    return new TempBufferStringValue(TempBuffer.copyFromStream(readStream));  }