System.Xml.ReadContentAsBinaryHelper.ReadElementContentAsBase64 C# (CSharp) Méthode

ReadElementContentAsBase64() private méthode

private ReadElementContentAsBase64 ( byte buffer, int index, int count ) : int
buffer byte
index int
count int
Résultat int
        internal int ReadElementContentAsBase64( byte[] buffer, int index, int count ) {
            // check arguments
            if ( buffer == null ) {
                throw new ArgumentNullException( "buffer" );
            }
            if ( count < 0 ) {
                throw new ArgumentOutOfRangeException( "count" );
            }
            if ( index < 0 ) {
                throw new ArgumentOutOfRangeException( "index" );
            }
            if ( buffer.Length - index < count ) {
                throw new ArgumentOutOfRangeException( "count" );
            }

            switch ( state ) {
                case State.None:
                    if ( reader.NodeType != XmlNodeType.Element ) {
                        throw reader.CreateReadElementContentAsException( "ReadElementContentAsBase64" );
                    }
                    if ( !InitOnElement() ) {
                        return 0;
                    }
                    break;
                case State.InReadContent:
                    throw new InvalidOperationException( Res.GetString( Res.Xml_MixingBinaryContentMethods ) );
                case State.InReadElementContent:
                    // if we have a correct decoder, go read
                    if ( decoder == base64Decoder ) {
                        // read more binary data
                        return ReadElementContentAsBinary( buffer, index, count );
                    }
                    break;
                default:
                    Debug.Assert( false );
                    return 0;
            }    

            Debug.Assert( state == State.InReadElementContent );

            // setup base64 decoder
            InitBase64Decoder();

            // read more binary data
            return ReadElementContentAsBinary( buffer, index, count );
        }

Usage Example

Exemple #1
0
        public override int ReadElementContentAsBase64(byte[] buffer, int index, int count)
        {
            // check arguments
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }
            if (count < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }
            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index));
            }
            if (buffer.Length - index < count)
            {
                throw new ArgumentOutOfRangeException(nameof(count));
            }

            if (ReadState != ReadState.Interactive)
            {
                return(0);
            }

            if (_state != State.InReadBinary)
            {
                // forward ReadBase64Chunk calls into the base (wrapped) reader if possible, i.e. if it can read binary and we
                // should not check characters
                if (base.CanReadBinaryContent && (!_checkCharacters))
                {
                    _readBinaryHelper = null;
                    _state            = State.InReadBinary;
                    return(base.ReadElementContentAsBase64(buffer, index, count));
                }
                // the wrapped reader cannot read chunks or we are on an element where we should check characters or ignore whitespace
                else
                {
                    _readBinaryHelper = ReadContentAsBinaryHelper.CreateOrReset(_readBinaryHelper, this);
                }
            }
            else
            {
                // forward calls into wrapped reader
                if (_readBinaryHelper == null)
                {
                    return(base.ReadElementContentAsBase64(buffer, index, count));
                }
            }

            // turn off InReadBinary state in order to have a normal Read() behavior when called from readBinaryHelper
            _state = State.Interactive;

            // call to the helper
            int readCount = _readBinaryHelper.ReadElementContentAsBase64(buffer, index, count);

            // turn on InReadBinary in again and return
            _state = State.InReadBinary;
            return(readCount);
        }
All Usage Examples Of System.Xml.ReadContentAsBinaryHelper::ReadElementContentAsBase64