public bool ReadBoundary() { try { string line = ReadLine(); while (line == "") { line = ReadLine(); } if (line [0] != '-' || line [1] != '-') { return(false); } if (!StrUtils.EndsWith(line, boundary, false)) { return(true); } } catch { } return(false); }
/* * byte[] MoveToNextBoundary (int maxlength) * { * long retval = 0; * bool got_cr = false; * * long start = data.Position; * int state = 0; * int c = data.ReadByte (); * while (true) { * if (data.Position - start > maxlength) * throw new InvalidDataException("data too long"); * * if (c == -1) * return -1; * * if (state == 0 && c == LF) { * retval = data.Position - 1; * if (got_cr) * retval--; * state = 1; * c = data.ReadByte (); * } else if (state == 0) { * got_cr = (c == CR); * c = data.ReadByte (); * } else if (state == 1 && c == '-') { * c = data.ReadByte (); * if (c == -1) * return -1; * * if (c != '-') { * state = 0; * got_cr = false; * continue; // no ReadByte() here * } * * int nread = data.Read (buffer, 0, buffer.Length); * int bl = buffer.Length; * if (nread != bl) * return -1; * * if (!CompareBytes (boundary_bytes, buffer)) { * state = 0; * data.Position = retval + 2; * if (got_cr) { * data.ReadByte(); //data.Position++; * got_cr = false; * } * c = data.ReadByte (); * continue; * } * * if (buffer [bl - 2] == '-' && buffer [bl - 1] == '-') { * at_eof = true; * } else if (buffer [bl - 2] != CR || buffer [bl - 1] != LF) { * state = 0; * data.Position = retval + 2; * if (got_cr) { * data.ReadByte(); //data.Position++; * got_cr = false; * } * c = data.ReadByte (); * continue; * } * data.Position = retval + 2; * if (got_cr) * data.ReadByte(); * //data.Position++; * break; * } else { * // state == 1 * state = 0; // no ReadByte() here * } * } * * return retval; * }*/ public Element ReadNextElement(int maxlength) { Element elem = new Element(); string header; bool stopDoNotMovePutYourHandsInTheAir = false; while ((header = ReadHeaders()) != null) { if (StrUtils.StartsWith(header, "Content-Disposition:", true)) { elem.Name = GetContentDispositionAttribute(header, "name"); elem.Filename = StripPath(GetContentDispositionAttributeWithEncoding(header, "filename")); if (elem.Name == lastElementName) { stopDoNotMovePutYourHandsInTheAir = true; } } else if (StrUtils.StartsWith(header, "Content-Type:", true)) { elem.ContentType = header.Substring("Content-Type:".Length).Trim(); } } if (stopDoNotMovePutYourHandsInTheAir) { return(null); } //long pos = MoveToNextBoundary (maxlength); //if (pos == -1) // return null; //elem.Length = pos - start; //Console.WriteLine("gonna do fancy stuff for {0}", elem.Name); elem.Data = MoveToNextBoundary(maxlength); return(elem); }