static int deflateCopy(ZStream dest, ZStream src){

    if(src.dstate == null){
      return Z_STREAM_ERROR;
    }

    if(src.next_in!=null){
      dest.next_in = new byte[src.next_in.length];
      System.arraycopy(src.next_in, 0, dest.next_in, 0, src.next_in.length);
    }
    dest.next_in_index = src.next_in_index;
    dest.avail_in = src.avail_in;
    dest.total_in = src.total_in;

    if(src.next_out!=null){
      dest.next_out = new byte[src.next_out.length];
      System.arraycopy(src.next_out, 0, dest.next_out ,0 , src.next_out.length);
    }

    dest.next_out_index = src.next_out_index;
    dest.avail_out = src.avail_out;
    dest.total_out = src.total_out;

    dest.msg = src.msg;
    dest.data_type = src.data_type;
    dest.adler = src.adler.copy();

    try{
      dest.dstate = (Deflate)src.dstate.clone();
      dest.dstate.strm = dest;
    }
    catch(CloneNotSupportedException e){
      //
    }
    return Z_OK;
  }