<commit_before>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//------------------------------------------------------------
//------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;


namespace System.Runtime.Serialization.Json
{
#if FEATURE_LEGACYNETCF
    public
#else
    internal
#endif
    class JavaScriptDeserializer
    {
        internal const string s_jsonBeta2Prefix = @"{""d"":";
        private JavaScriptObjectDeserializer _deserializer;

        internal object DeserializeObject()
        {
            return _deserializer.BasicDeserialize();
        }

        internal JavaScriptDeserializer(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            Stream incomingStream = stream;
            if (!stream.CanSeek)
            {
                //Incoming stream if not seekable then read it in to memory.
                incomingStream = new BufferedStreamReader(stream);
            }

            Encoding streamEncoding = DetectEncoding(incomingStream.ReadByte(), incomingStream.ReadByte());
            //Move the stream back to 0
            incomingStream.Position = 0;
            //If the stream contains a BOM, StreamReader will detect it and override our encoding setting
            string input = new StreamReader(incomingStream, streamEncoding, true/*detectEncodingFromByteOrderMarks*/).ReadToEnd();
            _deserializer = new JavaScriptObjectDeserializer(input);
        }

#if FEATURE_LEGACYNETCF
        public
#else
        internal
#endif
        class BufferedStreamReader : Stream
        {
            private byte[] _bomBuffer = new byte[2];
            private int _bufferedBytesIndex = 0;
            private Stream _internalStream;

#if FEATURE_LEGACYNETCF
            public
#else
            internal
#endif
            BufferedStreamReader(Stream stream)
            {
                _internalStream = stream;
                //Buffer the first two bytes
                stream.Read(_bomBuffer, 0, 2);
            }

            public override long Position<commit_msg>DevDiv 1169976: [CoreCLR x86 Dogfooding] Microsoft Minesweeper: Adventure mode not working with CoreCLR<commit_after>// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//------------------------------------------------------------
//------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;


namespace System.Runtime.Serialization.Json
{
#if FEATURE_LEGACYNETCF
    public
#else
    internal
#endif
    class JavaScriptDeserializer
    {
        internal const string s_jsonBeta2Prefix = @"{""d"":";
        private JavaScriptObjectDeserializer _deserializer;

        internal object DeserializeObject()
        {
            return _deserializer.BasicDeserialize();
        }

        internal JavaScriptDeserializer(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            Stream incomingStream = stream;
            if (!stream.CanSeek)
            {
                //Incoming stream if not seekable then read it in to memory.
                incomingStream = new BufferedStreamReader(stream);
            }

            Encoding streamEncoding = DetectEncoding(incomingStream.ReadByte(), incomingStream.ReadByte());
            //Move the stream back to 0
            incomingStream.Position = 0;
            //If the stream contains a BOM, StreamReader will detect it and override our encoding setting
            string input = new StreamReader(incomingStream, streamEncoding, true/*detectEncodingFromByteOrderMarks*/).ReadToEnd();

            if (string.IsNullOrEmpty(input))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExpectingElement, XmlDictionaryString.Empty, "root")));
            }

            _deserializer = new JavaScriptObjectDeserializer(input);
        }

#if FEATURE_LEGACYNETCF
        public
#else
        internal
#endif
        class BufferedStreamReader : Stream
        {
            private byte[] _bomBuffer = new byte[2];
            private int _bufferedBytesIndex = 0;
            private Stream _internalStream;

#if FEATURE_LEGACYNETCF
            public
#else
            internal
#endif
            BufferedStreamReader(Stream stream)
            {
                _internalStream = stream;
                //Buffer the first two bytes
                stream.Read(_bomBuffer, 0, 2);
            }

            public override long Position
{'fraction_non_alphanumeric': 0.11175917215428034, 'fraction_numerical': 0.004327375352775165, 'mean_word_length': 1.9566184649610678, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '2283164', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1226, 'n_words': 363}