Ejemplo n.º 1
1
  /**
   * Updates the element info to a change of the file content and sends out appropriate
   * notifications.
   *
   * @param fileEditorInput the input of an text editor
   */
  protected void handleElementContentChanged(IEditorInput fileEditorInput) {
    FileInfo info = (FileInfo) getElementInfo(fileEditorInput);
    if (info == null) {
      return;
    }

    IStorage storage = EditorUtils.getStorageFromInput(fileEditorInput);
    if (storage instanceof IFile) {
      IFile file = (IFile) storage;
      IDocument document = createEmptyDocument();
      IStatus status = null;

      try {

        try {
          refreshFile(file);
        } catch (CoreException x) {
          log.error("handleElementContentChanged", x);
        }

        setDocumentContent(document, file);
      } catch (CoreException x) {
        status = x.getStatus();
      }

      String newContent = document.get();

      if (!newContent.equals(info.fDocument.get())) {

        // set the new content and fire content related events
        fireElementContentAboutToBeReplaced(fileEditorInput);

        removeUnchangedElementListeners(fileEditorInput, info);

        info.fDocument.removeDocumentListener(info);
        info.fDocument.set(newContent);
        info.fCanBeSaved = false;
        info.modificationStamp = computeModificationStamp(file);
        info.fStatus = status;

        addUnchangedElementListeners(fileEditorInput, info);

        fireElementContentReplaced(fileEditorInput);

      } else {

        removeUnchangedElementListeners(fileEditorInput, info);

        // fires only the dirty state related event
        info.fCanBeSaved = false;
        info.modificationStamp = computeModificationStamp(file);
        info.fStatus = status;

        addUnchangedElementListeners(fileEditorInput, info);

        fireElementDirtyStateChanged(fileEditorInput, false);
      }
    }
  }
Ejemplo n.º 2
0
  public static FileInfo getFileInfo(File f, FilenameFilter filter, boolean showHidden) {
    FileInfo lFileInfo = new FileInfo();
    String filePath = f.getPath();
    File lFile = new File(filePath);
    lFileInfo.canRead = lFile.canRead();
    lFileInfo.canWrite = lFile.canWrite();
    lFileInfo.isHidden = lFile.isHidden();
    lFileInfo.fileName = f.getName();
    lFileInfo.modifiedDate = lFile.lastModified();
    lFileInfo.isDir = lFile.isDirectory();
    lFileInfo.filePath = filePath;
    if (lFileInfo.isDir) {
      int lCount = 0;
      File[] files = lFile.listFiles(filter);

      // null means we cannot access this dir
      if (files == null) {
        return null;
      }

      for (File child : files) {
        if ((!child.isHidden() || showHidden) && isNormalFile(child.getAbsolutePath())) {
          lCount++;
        }
      }
      lFileInfo.count = lCount;

    } else {

      lFileInfo.fileSize = lFile.length();
    }
    return lFileInfo;
  }
Ejemplo n.º 3
0
  /**
   * Returns true iff all the files listed in this tracker's dependency list exist and are at the
   * same version as when they were recorded.
   *
   * @return a boolean
   */
  boolean isUpToDate(Properties properties) {
    Iterator e;

    // fixes bug 962
    {
      if (mProperties.size() != properties.size()) {
        mLogger.debug(
            /* (non-Javadoc)
             * @i18n.test
             * @org-mes="my size " + p[0]
             */
            org.openlaszlo.i18n.LaszloMessages.getMessage(
                DependencyTracker.class.getName(),
                "051018-181",
                new Object[] {new Integer(mProperties.size())}));
        mLogger.debug(
            /* (non-Javadoc)
             * @i18n.test
             * @org-mes="new size " + p[0]
             */
            org.openlaszlo.i18n.LaszloMessages.getMessage(
                DependencyTracker.class.getName(),
                "051018-189",
                new Object[] {new Integer(properties.size())}));
        return false;
      }

      for (e = mProperties.keySet().iterator(); e.hasNext(); ) {
        String key = (String) e.next();
        String val0 = mProperties.getProperty(key);
        String val1 = properties.getProperty(key);

        // val0 can't be null; properties don't allow that
        if (val1 == null || !val0.equals(val1)) {
          mLogger.debug(
              /* (non-Javadoc)
               * @i18n.test
               * @org-mes="Missing or changed property: " + p[0]
               */
              org.openlaszlo.i18n.LaszloMessages.getMessage(
                  DependencyTracker.class.getName(), "051018-207", new Object[] {val0}));
          return false;
        }
      }
    }

    for (e = mDependencies.iterator(); e.hasNext(); ) {
      FileInfo saved = (FileInfo) e.next();
      FileInfo current = new FileInfo(saved.mPathname);
      if (!saved.isUpToDate(current)) {
        mLogger.debug(saved.mPathname + " has changed");
        mLogger.debug("was " + saved.mLastMod);
        mLogger.debug(" is " + current.mLastMod);
        return false;
      }
    }
    return true;
  }
Ejemplo n.º 4
0
 /**
  * Add the specified file to the list of file dependencies.
  *
  * @param file a file
  */
 void addFile(File file) {
   mLogger.debug("addFile Path is " + file.getPath());
   FileInfo fi = new FileInfo(file.getPath());
   try {
     fi.mPathname = file.getCanonicalPath();
   } catch (java.io.IOException e) {
     throw new ChainedException(e);
   }
   mDependencies.add(fi);
 }
Ejemplo n.º 5
0
  public static FileInfo getFileInfo(File lFile) {

    FileInfo lFileInfo = new FileInfo();
    lFileInfo.canRead = lFile.canRead();
    lFileInfo.canWrite = lFile.canWrite();
    lFileInfo.isHidden = lFile.isHidden();
    lFileInfo.fileName = getNameFromFilepath(lFile.getAbsolutePath());
    lFileInfo.modifiedDate = lFile.lastModified();
    lFileInfo.isDir = lFile.isDirectory();
    lFileInfo.filePath = lFile.getAbsolutePath();
    lFileInfo.fileSize = lFile.length();
    return lFileInfo;
  }
Ejemplo n.º 6
0
 byte[] uncompress(byte[] input) {
   if (fi.compression == FileInfo.PACK_BITS)
     return packBitsUncompress(input, fi.rowsPerStrip * fi.width * fi.getBytesPerPixel());
   else if (fi.compression == FileInfo.LZW || fi.compression == FileInfo.LZW_WITH_DIFFERENCING)
     return lzwUncompress(input);
   else if (fi.compression == FileInfo.ZIP) return zipUncompress(input);
   else return input;
 }
Ejemplo n.º 7
0
  @Override
  protected ElementInfo createElementInfo(Object element) throws CoreException {
    if (element instanceof IEditorInput) {

      IEditorInput input = (IEditorInput) element;
      IStorage storage = EditorUtils.getStorageFromInput(input);
      if (storage instanceof IFile) {
        IFile file = (IFile) storage;
        try {
          refreshFile(file);
        } catch (CoreException x) {
          log.warn("Can't refresh file", x);
        }

        IDocument d;
        IStatus s = null;

        try {
          d = createDocument(element);
        } catch (CoreException x) {
          log.warn("Can't create document", x);
          s = x.getStatus();
          d = createEmptyDocument();
        }

        // Set the initial line delimiter
        String initialLineDelimiter = GeneralUtils.getDefaultLineSeparator();
        if (initialLineDelimiter != null) {
          ((IDocumentExtension4) d).setInitialLineDelimiter(initialLineDelimiter);
        }

        IAnnotationModel m = createAnnotationModel(element);
        FileSynchronizer f = new FileSynchronizer(input);
        f.install();

        FileInfo info = new FileInfo(d, m, f);
        info.modificationStamp = computeModificationStamp(file);
        info.fStatus = s;

        return info;
      }
    }

    return super.createElementInfo(element);
  }
Ejemplo n.º 8
0
 /** Returns an InputStream for the image described by this FileInfo. */
 public InputStream createInputStream(FileInfo fi) throws IOException, MalformedURLException {
   InputStream is = null;
   boolean gzip =
       fi.fileName != null && (fi.fileName.endsWith(".gz") || fi.fileName.endsWith(".GZ"));
   if (fi.inputStream != null) is = fi.inputStream;
   else if (fi.url != null && !fi.url.equals("")) is = new URL(fi.url + fi.fileName).openStream();
   else {
     if (fi.directory.length() > 0 && !fi.directory.endsWith(Prefs.separator))
       fi.directory += Prefs.separator;
     File f = new File(fi.directory + fi.fileName);
     if (gzip) fi.compression = FileInfo.COMPRESSION_UNKNOWN;
     if (f == null || f.isDirectory() || !validateFileInfo(f, fi)) is = null;
     else is = new FileInputStream(f);
   }
   if (is != null) {
     if (fi.compression >= FileInfo.LZW) is = new RandomAccessStream(is);
     else if (gzip) is = new GZIPInputStream(is, 50000);
   }
   return is;
 }
Ejemplo n.º 9
0
  private static FileInfo parseFile(Node parent) throws XmlParserException {
    String label = "";
    String name = "";
    String location = "";
    Vector<Annotation> annotations = null;

    NodeList nodes = parent.getChildNodes();
    for (int nodeid = 0; nodeid < nodes.getLength(); ++nodeid) {
      Node node = nodes.item(nodeid);
      if (node.getNodeType() != Node.ELEMENT_NODE) continue;

      Element element = (Element) node;
      if (element.getTagName().equals("label")) label = element.getTextContent();
      else if (element.getTagName().equals("name")) name = element.getTextContent();
      else if (element.getTagName().equals("location")) location = element.getTextContent();
      else if (element.getTagName().equals("annotations")) annotations = parseAnnotations(node);
    }

    FileInfo file = new FileInfo(label, name, location);
    if (annotations != null) file.addAnnotations(annotations);
    return file;
  }
Ejemplo n.º 10
0
 /**
  * This will update the FileInfo object chain to use the (possibly new) webappPath once the
  * DependencyTracker object has been reconstitutded from ondisk cache.
  */
 void updateWebappPath() {
   String webappPath = LPS.HOME(); // get it from global
   if (webappPath.equals(mWebappPath)) return;
   mLogger.debug(
       /* (non-Javadoc)
        * @i18n.test
        * @org-mes="updating webappPath from: " + p[0]
        */
       org.openlaszlo.i18n.LaszloMessages.getMessage(
           DependencyTracker.class.getName(), "051018-128", new Object[] {mWebappPath}));
   mLogger.debug(
       /* (non-Javadoc)
        * @i18n.test
        * @org-mes="updating webappPath to:   " + p[0]
        */
       org.openlaszlo.i18n.LaszloMessages.getMessage(
           DependencyTracker.class.getName(), "051018-136", new Object[] {webappPath}));
   for (Iterator e = mDependencies.iterator(); e.hasNext(); ) {
     FileInfo saved = (FileInfo) e.next();
     if (saved.mPathname.startsWith(mWebappPath)) {
       mLogger.debug(
           /* (non-Javadoc)
            * @i18n.test
            * @org-mes="updating dependencies from: " + p[0]
            */
           org.openlaszlo.i18n.LaszloMessages.getMessage(
               DependencyTracker.class.getName(), "051018-147", new Object[] {saved.mPathname}));
       saved.mPathname = webappPath + saved.mPathname.substring(mWebappPath.length());
       mLogger.debug(
           /* (non-Javadoc)
            * @i18n.test
            * @org-mes="updating dependencies to  : " + p[0]
            */
           org.openlaszlo.i18n.LaszloMessages.getMessage(
               DependencyTracker.class.getName(), "051018-157", new Object[] {saved.mPathname}));
     }
   }
   mWebappPath = webappPath;
 }
Ejemplo n.º 11
0
 static boolean validateFileInfo(File f, FileInfo fi) {
   long offset = fi.getOffset();
   long length = 0;
   if (fi.width <= 0 || fi.height < 0) {
     error("Width or height <= 0.", fi, offset, length);
     return false;
   }
   if (offset >= 0 && offset < 1000L) return true;
   if (offset < 0L) {
     error("Offset is negative.", fi, offset, length);
     return false;
   }
   if (fi.fileType == FileInfo.BITMAP || fi.compression != FileInfo.COMPRESSION_NONE) return true;
   length = f.length();
   long size = fi.width * fi.height * fi.getBytesPerPixel();
   size = fi.nImages > 1 ? size : size / 4;
   if (fi.height == 1) size = 0; // allows plugins to read info of unknown length at end of file
   if (offset + size > length) {
     error("Offset + image size > file length.", fi, offset, length);
     return false;
   }
   return true;
 }
Ejemplo n.º 12
0
 /** Opens a stack of images. */
 ImagePlus openStack(ColorModel cm, boolean show) {
   ImageStack stack = new ImageStack(fi.width, fi.height, cm);
   long skip = fi.getOffset();
   Object pixels;
   try {
     ImageReader reader = new ImageReader(fi);
     InputStream is = createInputStream(fi);
     if (is == null) return null;
     IJ.resetEscape();
     for (int i = 1; i <= fi.nImages; i++) {
       if (!silentMode) IJ.showStatus("Reading: " + i + "/" + fi.nImages);
       if (IJ.escapePressed()) {
         IJ.beep();
         IJ.showProgress(1.0);
         silentMode = false;
         return null;
       }
       pixels = reader.readPixels(is, skip);
       if (pixels == null) break;
       stack.addSlice(null, pixels);
       skip = fi.gapBetweenImages;
       if (!silentMode) IJ.showProgress(i, fi.nImages);
     }
     is.close();
   } catch (Exception e) {
     IJ.log("" + e);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory(fi.fileName);
     stack.trim();
   }
   if (!silentMode) IJ.showProgress(1.0);
   if (stack.getSize() == 0) return null;
   if (fi.sliceLabels != null && fi.sliceLabels.length <= stack.getSize()) {
     for (int i = 0; i < fi.sliceLabels.length; i++) stack.setSliceLabel(fi.sliceLabels[i], i + 1);
   }
   ImagePlus imp = new ImagePlus(fi.fileName, stack);
   if (fi.info != null) imp.setProperty("Info", fi.info);
   if (show) imp.show();
   imp.setFileInfo(fi);
   setCalibration(imp);
   ImageProcessor ip = imp.getProcessor();
   if (ip.getMin() == ip.getMax()) // find stack min and max if first slice is blank
   setStackDisplayRange(imp);
   if (!silentMode) IJ.showProgress(1.0);
   silentMode = false;
   return imp;
 }
Ejemplo n.º 13
0
 Object readRGB48(InputStream in) throws IOException {
   if (fi.compression > FileInfo.COMPRESSION_NONE) return readCompressedRGB48(in);
   int channels = fi.samplesPerPixel;
   short[][] stack = new short[channels][nPixels];
   DataInputStream dis = new DataInputStream(in);
   int pixel = 0;
   int min = 65535, max = 0;
   if (fi.stripLengths == null) {
     fi.stripLengths = new int[fi.stripOffsets.length];
     fi.stripLengths[0] = width * height * bytesPerPixel;
   }
   for (int i = 0; i < fi.stripOffsets.length; i++) {
     if (i > 0) {
       long skip =
           (fi.stripOffsets[i] & 0xffffffffL)
               - (fi.stripOffsets[i - 1] & 0xffffffffL)
               - fi.stripLengths[i - 1];
       if (skip > 0L) dis.skip(skip);
     }
     int len = fi.stripLengths[i];
     int bytesToGo = (nPixels - pixel) * channels * 2;
     if (len > bytesToGo) len = bytesToGo;
     byte[] buffer = new byte[len];
     dis.readFully(buffer);
     int value;
     int channel = 0;
     boolean intel = fi.intelByteOrder;
     for (int base = 0; base < len; base += 2) {
       if (intel) value = ((buffer[base + 1] & 0xff) << 8) | (buffer[base] & 0xff);
       else value = ((buffer[base] & 0xff) << 8) | (buffer[base + 1] & 0xff);
       if (value < min) min = value;
       if (value > max) max = value;
       stack[channel][pixel] = (short) (value);
       channel++;
       if (channel == channels) {
         channel = 0;
         pixel++;
       }
     }
     showProgress(i + 1, fi.stripOffsets.length);
   }
   this.min = min;
   this.max = max;
   return stack;
 }
Ejemplo n.º 14
0
 static void error(String msg, FileInfo fi, long offset, long length) {
   IJ.error(
       "FileOpener",
       "FileInfo parameter error. \n"
           + msg
           + "\n \n"
           + "  Width: "
           + fi.width
           + "\n"
           + "  Height: "
           + fi.height
           + "\n"
           + "  Offset: "
           + offset
           + "\n"
           + "  Bytes/pixel: "
           + fi.getBytesPerPixel()
           + "\n"
           + (length > 0 ? "  File length: " + length + "\n" : ""));
 }
Ejemplo n.º 15
0
 /**
  * Writes the image to the specified OutputStream. The OutputStream is not closed. The fi.pixels
  * field must contain the image data. If fi.nImages>1 then fi.pixels must be a 2D array, for
  * example an array of images returned by ImageStack.getImageArray()). The fi.offset field is
  * ignored.
  */
 public void write(OutputStream out) throws IOException {
   if (fi.pixels == null && fi.virtualStack == null)
     throw new IOException("ImageWriter: fi.pixels==null");
   if (fi.nImages > 1 && fi.virtualStack == null && !(fi.pixels instanceof Object[]))
     throw new IOException("ImageWriter: fi.pixels not a stack");
   if (fi.width * fi.height * fi.getBytesPerPixel() < 26214400)
     showProgressBar = false; // don't show progress bar if image<25MB
   switch (fi.fileType) {
     case FileInfo.GRAY8:
     case FileInfo.COLOR8:
       if (fi.nImages > 1 && fi.virtualStack != null) write8BitVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) write8BitStack(out, (Object[]) fi.pixels);
       else write8BitImage(out, (byte[]) fi.pixels);
       break;
     case FileInfo.GRAY16_SIGNED:
     case FileInfo.GRAY16_UNSIGNED:
       if (fi.nImages > 1 && fi.virtualStack != null) write16BitVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) write16BitStack(out, (Object[]) fi.pixels);
       else write16BitImage(out, (short[]) fi.pixels);
       break;
     case FileInfo.RGB48:
       writeRGB48Image(out, (Object[]) fi.pixels);
       break;
     case FileInfo.GRAY32_FLOAT:
       if (fi.nImages > 1 && fi.virtualStack != null) writeFloatVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) writeFloatStack(out, (Object[]) fi.pixels);
       else writeFloatImage(out, (float[]) fi.pixels);
       break;
     case FileInfo.RGB:
       if (fi.nImages > 1 && fi.virtualStack != null) writeRGBVirtualStack(out, fi.virtualStack);
       else if (fi.nImages > 1) writeRGBStack(out, (Object[]) fi.pixels);
       else writeRGBImage(out, (int[]) fi.pixels);
       break;
     default:
   }
 }
Ejemplo n.º 16
0
 public Properties decodeDescriptionString(FileInfo fi) {
   if (fi.description == null || fi.description.length() < 7) return null;
   if (IJ.debugMode) IJ.log("Image Description: " + new String(fi.description).replace('\n', ' '));
   if (!fi.description.startsWith("ImageJ")) return null;
   Properties props = new Properties();
   InputStream is = new ByteArrayInputStream(fi.description.getBytes());
   try {
     props.load(is);
     is.close();
   } catch (IOException e) {
     return null;
   }
   fi.unit = props.getProperty("unit", "");
   Double n = getNumber(props, "cf");
   if (n != null) fi.calibrationFunction = n.intValue();
   double c[] = new double[5];
   int count = 0;
   for (int i = 0; i < 5; i++) {
     n = getNumber(props, "c" + i);
     if (n == null) break;
     c[i] = n.doubleValue();
     count++;
   }
   if (count >= 2) {
     fi.coefficients = new double[count];
     for (int i = 0; i < count; i++) fi.coefficients[i] = c[i];
   }
   fi.valueUnit = props.getProperty("vunit");
   n = getNumber(props, "images");
   if (n != null && n.doubleValue() > 1.0) fi.nImages = (int) n.doubleValue();
   if (fi.nImages > 1) {
     double spacing = getDouble(props, "spacing");
     if (spacing != 0.0) {
       if (spacing < 0) spacing = -spacing;
       fi.pixelDepth = spacing;
     }
   }
   return props;
 }
Ejemplo n.º 17
0
 /**
  * Reads the image from the InputStream and returns the pixel array (byte, short, int or float).
  * Returns null if there was an IO exception. Does not close the InputStream.
  */
 public Object readPixels(InputStream in) {
   Object pixels;
   startTime = System.currentTimeMillis();
   try {
     switch (fi.fileType) {
       case FileInfo.GRAY8:
       case FileInfo.COLOR8:
         bytesPerPixel = 1;
         skip(in);
         pixels = (Object) read8bitImage(in);
         break;
       case FileInfo.GRAY16_SIGNED:
       case FileInfo.GRAY16_UNSIGNED:
         bytesPerPixel = 2;
         skip(in);
         pixels = (Object) read16bitImage(in);
         break;
       case FileInfo.GRAY32_INT:
       case FileInfo.GRAY32_UNSIGNED:
       case FileInfo.GRAY32_FLOAT:
         bytesPerPixel = 4;
         skip(in);
         pixels = (Object) read32bitImage(in);
         break;
       case FileInfo.GRAY64_FLOAT:
         bytesPerPixel = 8;
         skip(in);
         pixels = (Object) read64bitImage(in);
         break;
       case FileInfo.RGB:
       case FileInfo.BGR:
       case FileInfo.ARGB:
       case FileInfo.ABGR:
       case FileInfo.BARG:
       case FileInfo.CMYK:
         bytesPerPixel = fi.getBytesPerPixel();
         skip(in);
         pixels = (Object) readChunkyRGB(in);
         break;
       case FileInfo.RGB_PLANAR:
         bytesPerPixel = 3;
         skip(in);
         pixels = (Object) readPlanarRGB(in);
         break;
       case FileInfo.BITMAP:
         bytesPerPixel = 1;
         skip(in);
         pixels = (Object) read1bitImage(in);
         break;
       case FileInfo.RGB48:
         bytesPerPixel = 6;
         skip(in);
         pixels = (Object) readRGB48(in);
         break;
       case FileInfo.RGB48_PLANAR:
         bytesPerPixel = 2;
         skip(in);
         pixels = (Object) readRGB48Planar(in);
         break;
       case FileInfo.GRAY12_UNSIGNED:
         skip(in);
         short[] data = read12bitImage(in);
         pixels = (Object) data;
         break;
       case FileInfo.GRAY24_UNSIGNED:
         skip(in);
         pixels = (Object) read24bitImage(in);
         break;
       default:
         pixels = null;
     }
     showProgress(1, 1);
     return pixels;
   } catch (IOException e) {
     IJ.log("" + e);
     return null;
   }
 }
Ejemplo n.º 18
0
 /**
  * Constructs a new ImageReader using a FileInfo object to describe the file to be read.
  *
  * @see ij.io.FileInfo
  */
 public ImageReader(FileInfo fi) {
   this.fi = fi;
   width = fi.width;
   height = fi.height;
   skipCount = fi.getOffset();
 }
Ejemplo n.º 19
0
 public Hashtable processData(
     ServletInputStream is, String boundary, String saveInDir, int clength)
     throws IllegalArgumentException, IOException {
   if (is == null) throw new IllegalArgumentException("InputStream");
   if (boundary == null || boundary.trim().length() < 1)
     throw new IllegalArgumentException("\"" + boundary + "\" is an illegal boundary indicator");
   boundary = "--" + boundary;
   StringTokenizer stLine = null, stFields = null;
   FileInfo fileInfo = null;
   Hashtable dataTable = new Hashtable(5);
   String line = null, field = null, paramName = null;
   boolean saveFiles = (saveInDir != null && saveInDir.trim().length() > 0);
   boolean isFile = false;
   if (saveFiles) { // Create the required directory (including parent dirs)
     File f = new File(saveInDir);
     f.mkdirs();
   }
   line = getLine(is);
   if (line == null || !line.startsWith(boundary))
     throw new IOException("Boundary not found; boundary = " + boundary + ", line = " + line);
   while (line != null) {
     if (line == null || !line.startsWith(boundary)) return dataTable;
     line = getLine(is);
     if (line == null) return dataTable;
     stLine = new StringTokenizer(line, ";\r\n");
     if (stLine.countTokens() < 2) throw new IllegalArgumentException("Bad data in second line");
     line = stLine.nextToken().toLowerCase();
     if (line.indexOf("form-data") < 0)
       throw new IllegalArgumentException("Bad data in second line");
     stFields = new StringTokenizer(stLine.nextToken(), "=\"");
     if (stFields.countTokens() < 2)
       throw new IllegalArgumentException("Bad data in second line");
     fileInfo = new FileInfo();
     stFields.nextToken();
     paramName = stFields.nextToken();
     isFile = false;
     if (stLine.hasMoreTokens()) {
       field = stLine.nextToken();
       stFields = new StringTokenizer(field, "=\"");
       if (stFields.countTokens() > 1) {
         if (stFields.nextToken().trim().equalsIgnoreCase("filename")) {
           fileInfo.name = paramName;
           String value = stFields.nextToken();
           if (value != null && value.trim().length() > 0) {
             fileInfo.clientFileName = value;
             isFile = true;
           } else {
             line = getLine(is); // Skip "Content-Type:" line
             line = getLine(is); // Skip blank line
             line = getLine(is); // Skip blank line
             line = getLine(is); // Position to boundary line
             continue;
           }
         }
       } else if (field.toLowerCase().indexOf("filename") >= 0) {
         line = getLine(is); // Skip "Content-Type:" line
         line = getLine(is); // Skip blank line
         line = getLine(is); // Skip blank line
         line = getLine(is); // Position to boundary line
         continue;
       }
     }
     boolean skipBlankLine = true;
     if (isFile) {
       line = getLine(is);
       if (line == null) return dataTable;
       if (line.trim().length() < 1) skipBlankLine = false;
       else {
         stLine = new StringTokenizer(line, ": ");
         if (stLine.countTokens() < 2)
           throw new IllegalArgumentException("Bad data in third line");
         stLine.nextToken(); // Content-Type
         fileInfo.fileContentType = stLine.nextToken();
       }
     }
     if (skipBlankLine) {
       line = getLine(is);
       if (line == null) return dataTable;
     }
     if (!isFile) {
       line = getLine(is);
       if (line == null) return dataTable;
       dataTable.put(paramName, line);
       // If parameter is dir, change saveInDir to dir
       if (paramName.equals("dir")) saveInDir = line;
       line = getLine(is);
       continue;
     }
     try {
       UplInfo uplInfo = new UplInfo(clength);
       UploadMonitor.set(fileInfo.clientFileName, uplInfo);
       OutputStream os = null;
       String path = null;
       if (saveFiles)
         os = new FileOutputStream(path = getFileName(saveInDir, fileInfo.clientFileName));
       else os = new ByteArrayOutputStream(ONE_MB);
       boolean readingContent = true;
       byte previousLine[] = new byte[2 * ONE_MB];
       byte temp[] = null;
       byte currentLine[] = new byte[2 * ONE_MB];
       int read, read3;
       if ((read = is.readLine(previousLine, 0, previousLine.length)) == -1) {
         line = null;
         break;
       }
       while (readingContent) {
         if ((read3 = is.readLine(currentLine, 0, currentLine.length)) == -1) {
           line = null;
           uplInfo.aborted = true;
           break;
         }
         if (compareBoundary(boundary, currentLine)) {
           os.write(previousLine, 0, read - 2);
           line = new String(currentLine, 0, read3);
           break;
         } else {
           os.write(previousLine, 0, read);
           uplInfo.currSize += read;
           temp = currentLine;
           currentLine = previousLine;
           previousLine = temp;
           read = read3;
         } // end else
       } // end while
       os.flush();
       os.close();
       if (!saveFiles) {
         ByteArrayOutputStream baos = (ByteArrayOutputStream) os;
         fileInfo.setFileContents(baos.toByteArray());
       } else fileInfo.file = new File(path);
       dataTable.put(paramName, fileInfo);
       uplInfo.currSize = uplInfo.totalSize;
     } // end try
     catch (IOException e) {
       throw e;
     }
   }
   return dataTable;
 }