void write(byte[] foo, int s, int l) throws java.io.IOException {
    //if(eof_local)return;

    if(init){

      Session _session=null;
      try{
        _session=getSession();
      }
      catch(JSchException e){
        throw new java.io.IOException(e.toString());
      }

      foo=addCache(foo, s, l);
      s=0; 
      l=foo.length;

      if(l<9)
        return;

      int plen=(foo[s+6]&0xff)*256+(foo[s+7]&0xff);
      int dlen=(foo[s+8]&0xff)*256+(foo[s+9]&0xff);

      if((foo[s]&0xff)==0x42){
      }
      else if((foo[s]&0xff)==0x6c){
         plen=((plen>>>8)&0xff)|((plen<<8)&0xff00);
         dlen=((dlen>>>8)&0xff)|((dlen<<8)&0xff00);
      }
      else{
	  // ??
      }

      if(l<12+plen+((-plen)&3)+dlen)
        return;

      byte[] bar=new byte[dlen];
      System.arraycopy(foo, s+12+plen+((-plen)&3), bar, 0, dlen);
      byte[] faked_cookie=null;

      synchronized(faked_cookie_pool){
	faked_cookie=(byte[])faked_cookie_pool.get(_session);
      }

      /*
System.err.print("faked_cookie: ");
for(int i=0; i<faked_cookie.length; i++){
    System.err.print(Integer.toHexString(faked_cookie[i]&0xff)+":");
}
System.err.println("");
System.err.print("bar: ");
for(int i=0; i<bar.length; i++){
    System.err.print(Integer.toHexString(bar[i]&0xff)+":");
}
System.err.println("");
      */

      if(equals(bar, faked_cookie)){
        if(cookie!=null)
          System.arraycopy(cookie, 0, foo, s+12+plen+((-plen)&3), dlen);
      }
      else{
	  //System.err.println("wrong cookie");
          thread=null;
          eof();
          io.close();
          disconnect();
      }
      init=false;
      io.put(foo, s, l);
      cache=null;
      return;
    }
    io.put(foo, s, l);
  }