public int appendBytes(InputStream in,int max) throws IOException {
  max=Math.min(max,buf.length - (pos + 2 + 1));
  int read=0, got;
  while (read < max && (got=in.read(buf,pos + 2 + read,max - read)) > -1) {
    read+=got;
  }
  if (read > 0) {
    appendInt(read);
    pos+=read;
    appendByte(0);
  }
  return read;
}

public int appendBytes ( InputStream in , int max ) throws IOException { max = Math . min ( max , buf . length - ( pos + 2 + 1 ) ) ; int read = 0 , got ; while ( read < max && ( got = in . read ( buf , pos + 2 + read , max - read ) ) > - 1 ) { read += got ; } if ( read > 0 ) { appendInt ( read ) ; pos += read ; appendByte ( 0 ) ; } return read ; }
utility method to read as many bytes as will fit into the buffer from an inputstream , using the ajpmessage buffer as the read destination . this eliminates an extra buffer , as well as a copy .
