LumiSoft.Net.StreamLineReader.ReadLine C# (CSharp) Méthode

ReadLine() public méthode

Reads byte[] line from stream. NOTE: Returns null if end of stream reached.
public ReadLine ( ) : byte[]
Résultat byte[]
        public byte[] ReadLine()
        {
            MemoryStream strmLineBuf = new MemoryStream();
            byte      prevByte = 0;

            int currByteInt = m_StrmSource.ReadByte();
            while(currByteInt > -1){
                strmLineBuf.WriteByte((byte)currByteInt);

                // Line found
                if((prevByte == (byte)'\r' && (byte)currByteInt == (byte)'\n')){
                    strmLineBuf.SetLength(strmLineBuf.Length - 2); // Remove <CRLF>

                    return strmLineBuf.ToArray();
                }

                // Store byte
                prevByte = (byte)currByteInt;

                // Read next byte
                currByteInt = m_StrmSource.ReadByte();
            }

            // Line isn't terminated with <CRLF> and has some bytes left, return them.
            if(strmLineBuf.Length > 0){
                return strmLineBuf.ToArray();
            }

            return null;
        }

Usage Example

Exemple #1
0
        /// <summary>
        /// Does period handling.
        /// </summary>
        /// <param name="strm">Input stream.</param>
        /// <param name="add_Remove">If true add periods, else removes periods.</param>
        /// <param name="setStrmPosTo0">If true sets stream position to 0.</param>
        /// <returns></returns>
        public static MemoryStream DoPeriodHandling(Stream strm, bool add_Remove, bool setStrmPosTo0)
        {
            MemoryStream replyData = new MemoryStream();

            byte[] crlf = new byte[] { (byte)'\r', (byte)'\n' };

            if (setStrmPosTo0)
            {
                strm.Position = 0;
            }

            StreamLineReader r = new StreamLineReader(strm);

            byte[] line = r.ReadLine();

            // Loop through all lines
            while (line != null)
            {
                if (line.Length > 0)
                {
                    if (line[0] == (byte)'.')
                    {
                        /* Add period Rfc 2821 4.5.2
                         * -  Before sending a line of mail text, the SMTP client checks the
                         * first character of the line.  If it is a period, one additional
                         * period is inserted at the beginning of the line.
                         */
                        if (add_Remove)
                        {
                            replyData.WriteByte((byte)'.');
                            replyData.Write(line, 0, line.Length);
                        }

                        /* Remove period Rfc 2821 4.5.2
                         * If the first character is a period , the first characteris deleted.
                         */
                        else
                        {
                            replyData.Write(line, 1, line.Length - 1);
                        }
                    }
                    else
                    {
                        replyData.Write(line, 0, line.Length);
                    }
                }

                replyData.Write(crlf, 0, crlf.Length);

                // Read next line
                line = r.ReadLine();
            }

            replyData.Position = 0;

            return(replyData);
        }
All Usage Examples Of LumiSoft.Net.StreamLineReader::ReadLine