<commit_before>﻿using System;
using System.IO;
using System.Text;
using Microsoft.Azure.Jobs.Host.Bindings;
using Microsoft.ServiceBus.Messaging;

namespace Microsoft.Azure.Jobs.ServiceBus.Triggers
{
    internal class BrokeredMessageValueProvider : IValueProvider
    {
        private readonly object _value;
        private readonly Type _valueType;
        private readonly string _invokeString;

        public BrokeredMessageValueProvider(BrokeredMessage clone, object value, Type valueType)
        {
            if (value != null && !valueType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException("value is not of the correct type.");
            }

            _value = value;
            _valueType = valueType;
            _invokeString = CreateInvokeString(clone);
        }

        public Type Type
        {
            get { return _valueType; }
        }

        public object GetValue()
        {
            return _value;
        }

        public string ToInvokeString()
        {
            return _invokeString;
        }

        private static string CreateInvokeString(BrokeredMessage message)
        {
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (Stream inputStream = message.GetBody<Stream>())
                {
                    if (inputStream == null)
                    {
                        return null;
                    }

                    inputStream.CopyTo(outputStream);

                    try
                    {
                        return StrictEncodings.Utf8.GetString(outputStream.ToArray());
                    }
                    catch (DecoderFallbackException)
                    {
                        return "byte[" + message.Size + "]";
                    }
                }
            }
        }
    }
}<commit_msg>Use body length for Service Bus binary messages.<commit_after>﻿using System;
using System.IO;
using System.Text;
using Microsoft.Azure.Jobs.Host.Bindings;
using Microsoft.ServiceBus.Messaging;

namespace Microsoft.Azure.Jobs.ServiceBus.Triggers
{
    internal class BrokeredMessageValueProvider : IValueProvider
    {
        private readonly object _value;
        private readonly Type _valueType;
        private readonly string _invokeString;

        public BrokeredMessageValueProvider(BrokeredMessage clone, object value, Type valueType)
        {
            if (value != null && !valueType.IsAssignableFrom(value.GetType()))
            {
                throw new InvalidOperationException("value is not of the correct type.");
            }

            _value = value;
            _valueType = valueType;
            _invokeString = CreateInvokeString(clone);
        }

        public Type Type
        {
            get { return _valueType; }
        }

        public object GetValue()
        {
            return _value;
        }

        public string ToInvokeString()
        {
            return _invokeString;
        }

        private static string CreateInvokeString(BrokeredMessage message)
        {
            using (MemoryStream outputStream = new MemoryStream())
            {
                using (Stream inputStream = message.GetBody<Stream>())
                {
                    if (inputStream == null)
                    {
                        return null;
                    }

                    inputStream.CopyTo(outputStream);
                    byte[] bytes = outputStream.ToArray();

                    try
                    {
                        return StrictEncodings.Utf8.GetString(bytes);
                    }
                    catch (DecoderFallbackException)
                    {
                        return "byte[" + bytes.Length + "]";
                    }
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07071226536384674, 'fraction_numerical': 0.0005142710208279763, 'mean_word_length': 1.37339841366687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7252413', 'n_tokens_mistral': 923, 'n_tokens_neox': 868, 'n_words': 206}