Пример #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            // find the number of bytes to copy
            int numBytes = _length - _pos;

            if (count < numBytes)
            {
                numBytes = count;
            }

            // copy the bytes
            if (numBytes > 0)
            {
                _data.CopyBytes(_offset + _pos, buffer, offset, numBytes);
            }

            // adjust the position
            _pos += numBytes;
            return(numBytes);
        }
Пример #2
0
        private void ParsePartHeaders()
        {
            _partName        = null;
            _partFilename    = null;
            _partContentType = null;

            while (GetNextLine())
            {
                if (_lineLength == 0)
                {
                    break;  // empty line signals end of headers
                }
                // get line as String
                byte[] lineBytes = new byte[_lineLength];
                _data.CopyBytes(_lineStart, lineBytes, 0, _lineLength);
                String line = _encoding.GetString(lineBytes);

                // parse into header and value
                int ic = line.IndexOf(':');
                if (ic < 0)
                {
                    continue;   // not a header
                }
                // remeber header
                String header = line.Substring(0, ic);

                if (StringUtil.EqualsIgnoreCase(header, "Content-Disposition"))
                {
                    // parse name and filename
                    _partName     = ExtractValueFromContentDispositionHeader(line, ic + 1, "name");
                    _partFilename = ExtractValueFromContentDispositionHeader(line, ic + 1, "filename");
                }
                else if (StringUtil.EqualsIgnoreCase(header, "Content-Type"))
                {
                    _partContentType = line.Substring(ic + 1).Trim();
                }
            }
        }