private void fill() throws IOException
   {
      if (eof) return;
    
      // as long as we are not just starting up
      if (count > 0)
      {
         // if the caller left the requisite amount spare in the buffer
         if (count - pos == 2) 
         {
            // copy it back to the start of the buffer
            System.arraycopy(buf, pos, buf, 0, count - pos);
            count -= pos;
            pos = 0;
         } 
         else throw new IllegalStateException("fill() detected illegal buffer state");
      }
    
      // try and fill the entire buffer, starting at count, line by line
      int read = 0;
      while (count < buf.length) 
      {
         // read a line
         read = ((ServletInputStream)in).readLine(buf, count, buf.length - count);
         // check for eof and boundary
         if (read == -1) 
         {
           throw new IOException("unexpected end of part");
         } 
         else 
         {
            if (read >= boundary.length()) 
            {
               eof = true;
               for (int i=0; i < boundary.length(); i++) 
               {
                  if (boundary.charAt(i) != buf[count + i]) 
                  {
                     // Not the boundary!
                     eof = false;
                     break;
                  }
               }
               if (eof) break;
            }
         }
         // success
         count += read;
      }
  }