private static void SkipToFirstDelimiter(Stream inputStream, BinaryBufferWithPatternWatching buffer)
        {
            buffer.Start();

            while (true)
            {
                int value = inputStream.ReadByte();
                if (value == -1)
                {
                    throw ParserException("Unexpected end of stream (2).");
                }

                byte byteValue = (byte)value;
                if (buffer.WriteByte(byteValue))
                {
                    return;
                }
            }
        }
        private static MultipartMessagePart ReadPart(
            MultipartMessage message,
            Stream inputStream,
            BinaryBufferWithPatternWatching buffer)
        {
            buffer.Start();

            while (true)
            {
                int value = inputStream.ReadByte();
                if (value == -1)
                {
                    throw ParserException("Unexpected end of stream (3).");
                }

                byte byteValue      = (byte)value;
                bool patternMatched = buffer.WriteByte(byteValue);

                if (!patternMatched)
                {
                    continue;
                }

                MultipartMessagePart part = ParsePart(
                    message,
                    buffer.ToArray(),
                    buffer.Pattern.Length);

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("Found part '{0}'", message.BaseEncoding.GetString(part.Data));
                }

                return(part);
            }
        }
        private static void SkipToFirstDelimiter(Stream inputStream, BinaryBufferWithPatternWatching buffer)
        {
            buffer.Start();

            while (true)
            {
                int value = inputStream.ReadByte();
                if (value == -1)
                    throw ParserException("Unexpected end of stream (2).");

                byte byteValue = (byte)value;
                if (buffer.WriteByte(byteValue))
                    return;
            }
        }
        private static MultipartMessagePart ReadPart(
            MultipartMessage message,
            Stream inputStream,
            BinaryBufferWithPatternWatching buffer)
        {
            buffer.Start();

            while (true)
            {
                int value = inputStream.ReadByte();
                if (value == -1)
                    throw ParserException("Unexpected end of stream (3).");

                byte byteValue = (byte)value;
                bool patternMatched = buffer.WriteByte(byteValue);

                if (!patternMatched)
                    continue;

                MultipartMessagePart part = ParsePart(
                    message,
                    buffer.ToArray(),
                    buffer.Pattern.Length);

                if (log.IsDebugEnabled)
                    log.DebugFormat("Found part '{0}'", message.BaseEncoding.GetString(part.Data));

                return part;
            }
        }