protected void readAndSaveFile(MultipartStreamHandler aStream, String aBoundary, String aFilename) throws IOException
   {
      File f = new File(fSaveDir + File.separator + aFilename);
      FileOutputStream fout = new FileOutputStream(f);
      BufferedOutputStream bout = new BufferedOutputStream(fout, 8196);
      byte[] bbuf = new byte[8196];
      int result;
      String line;

      // ServletInputStream adds /r/n to the last line -- we need to clip those
      boolean rnflag = false;
      while ((result = aStream.readLine(bbuf, 0, bbuf.length)) != -1)
      {
         if (result > 2 && bbuf[0] == '-' && bbuf[1] == '-')  // look for boundary
         {
            line = new String(bbuf, 0, result, "ISO-8859-1");
            if (line.startsWith(aBoundary)) break;
         }

         if (rnflag)   // pending deferred "\r\n" for all but last line
         {
            bout.write('\r');
            bout.write('\n');
            rnflag = false;
         }

         if (result >= 2 && bbuf[result-2] == '\r' && bbuf[result-1] == '\n')
         {
            bout.write(bbuf, 0, result-2);   // clip "\r\n"
            rnflag = true;  // indicate deferred write is pending
         }
         else
         {
            bout.write(bbuf, 0, result);
         }
      }

      bout.flush();
      bout.close();
      fout.close();
   }