Beispiel #1
0
        /// <summary>
        /// Writes out the specified binary bytes using the built-in "base64" encoding algorithm [X.891 Section 10.3].
        /// </summary>
        /// <param name="buffer">Byte array to encode.</param>
        /// <param name="index">The position within the buffer indicating the start of the bytes to write.</param>
        /// <param name="count">The number of bytes to write.</param>
        /// <exception cref="InvalidOperationException">The <see cref="WriteState"/> is invalid for this operation.</exception>
        public override void WriteBase64(byte[] buffer, int index, int count)
        {
            try
            {
                ValidateState(FIItemType.Content);

                if (_internalEncodingAlgorithm == null)
                {
                    _internalEncodingAlgorithm = new InternalEncodingAlgorithm();
                }

                _internalEncodingAlgorithm.Encoding = InternalEncodingAlgorithm.EncodingType.Base64Encoding;

                byte[] tempBuffer = new byte[count];
                Buffer.BlockCopy(buffer, index, tempBuffer, 0, count);

                _internalWriter.WriteEncodedData(_internalEncodingAlgorithm, tempBuffer);

                UpdateState(FIItemType.Content);
            }
            catch (Exception ex)
            {
                _state = FIState.Error;
                throw ex;
            }
        }
        internal FIEncoding Encoding(int fiTableIndex)
        {
            FIEncoding encoding = null;

            if (fiTableIndex > 0)
            {
                if (fiTableIndex < EXTENDED_ENCODING_ALGORITHM_START)
                {
                    if (fiTableIndex <= ENCODING_ALGORITHM_COUNT)
                    {
                        if (_internalEncodingAlgorithm == null)
                        {
                            _internalEncodingAlgorithm = new InternalEncodingAlgorithm();
                        }

                        _internalEncodingAlgorithm.Encoding = (InternalEncodingAlgorithm.EncodingType)fiTableIndex;
                        encoding = _internalEncodingAlgorithm;
                    }
                }
                else if ((_uriToEncodingMap != null) && (fiTableIndex < EXTENDED_ENCODING_ALGORITHM_MAX))
                {
                    // index - 1 to move from FI table index to list index
                    int realIndex = fiTableIndex - 1;
                    if (realIndex < _uriToEncodingMap.Count)
                    {
                        Dictionary <string, FIEncodingAlgorithm> .Enumerator e = _uriToEncodingMap.GetEnumerator();
                        while (e.MoveNext())
                        {
                            if (e.Current.Value.TableIndex == fiTableIndex)
                            {
                                encoding = e.Current.Value;
                                break;
                            }
                        }
                    }
                }
            }

            return(encoding);
        }
Beispiel #3
0
        /// <summary>
        /// Writes out the specified string using the built-in "cdata" encoding algorithm [X.891 Section 10.11].
        /// </summary>
        /// <param name="text">Text to encode.</param>
        /// <exception cref="InvalidOperationException">The <see cref="WriteState"/> is invalid for this operation.</exception>
        public override void WriteCData(string text)
        {
            try
            {
                ValidateState(FIItemType.Content);

                if (_internalEncodingAlgorithm == null)
                {
                    _internalEncodingAlgorithm = new InternalEncodingAlgorithm();
                }

                _internalEncodingAlgorithm.Encoding = InternalEncodingAlgorithm.EncodingType.CDataEncoding;

                _internalWriter.WriteEncodedData(_internalEncodingAlgorithm, text);

                UpdateState(FIItemType.Content);
            }
            catch (Exception ex)
            {
                _state = FIState.Error;
                throw ex;
            }
        }