/// <summary> Create a source of characters.</summary>
        /// <param name="stream">The stream of bytes to use.
        /// </param>
        /// <param name="charset">The character set used in encoding the stream.
        /// </param>
        /// <param name="size">The initial character buffer size.
        /// </param>
        /// <exception cref="UnsupportedEncodingException">If the character set
        /// is unsupported.
        /// </exception>
        public InputStreamSource(System.IO.Stream stream, System.String charset, int size)
            : base(stream)
        {
            if (null == stream)
            {
                stream = new ParserStream(null);
            }
            // bug #1044707 mark()/reset() issues
            else
            {
                //UPGRADE_ISSUE: Method 'java.io.InputStream.markSupported' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioInputStreammarkSupported'"
                //if (!stream.markSupported())
                // wrap the stream so we can reset
                //	stream = new Stream(stream);
            }
            // else
            // just because mark is supported doesn't guarantee
            // proper reset operation; there is no call to mark
            // in this code, so if reset misbehaves there is an
            // appropriate message in setEncoding() to suggest
            // wraping it in a Stream.
            // This was deemed better than an attempt to call
            // reset at this point just to check if we would
            // succeed later, or to call mark with an arbitrary
            // lookahead size
            mStream = stream;
            if (null == charset || String.Empty == charset)
            {
#if NETFX_CORE && UNITY_METRO && !UNITY_EDITOR
                mEncoding = WinRTLegacy.Text.Encoding.Default.EncodingName;
                mReader   = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding(mEncoding));
#else
                mReader   = new System.IO.StreamReader(stream, System.Text.Encoding.Default);
                mEncoding = mReader.CurrentEncoding.EncodingName;
#endif
            }
            else
            {
                mEncoding = charset;
                mReader   = new System.IO.StreamReader(stream, System.Text.Encoding.GetEncoding(charset));
            }
            mBuffer = new char[size];
            mLevel  = 0;
            mOffset = 0;
            mMark   = -1;
        }
Ejemplo n.º 2
0
        private void GetPageContent(HttpProtocol obProtocol, bool bIsRefresh)
        {
            if (m_bHasContent && !bIsRefresh)
            {
                return;
            }

            if (obProtocol == null)
            {
                throw new ArgumentNullException("obProtocol", "Null HttpProtocol object specified");
            }

            lock (this)
            {
                ParserStream  stream  = null;
                System.String type    = String.Empty;
                System.String charset = String.Empty;
                try
                {
                    m_obProtocolOutput = obProtocol.GetProtocolOutput();
                    if (m_obProtocolOutput.Status.Code == HttpProtocolStatus.SUCCESS)
                    {
                        m_bHasContent = true;
                        this.m_HttpContentProperties = m_obProtocolOutput.Content.ContentProperties;
                        type    = this.ContentType;
                        charset = GetCharset(type);
                        stream  = new ParserStream(new System.IO.MemoryStream(m_obProtocolOutput.Content.ContentData));
                    }

                    if (null != stream)
                    {
                        mSource = new InputStreamSource(stream, charset, m_obProtocolOutput.Content.ContentData.Length);
                    }
                }
                catch (System.Exception e)
                {
                    throw new ParserException("Failed to get page content", e);
                }

                mUrl   = obProtocol.URL.ToString();
                mIndex = new PageIndex(this);
            }
        }