Exemplo n.º 1
0
        public int CalculateJsonLength()
        {
            // This could possibly change length as a string, thus we need to either recalculate multiple times until there is
            // no change in length from the last iteration or we need to ensure it takes the same string length no matter the
            // number.  The latter is the best approach as it reduces memory and processor load substantially.
            // Thus, we need to convert to a string and append 0s to the front to fill the full places of a int.

            //System.IO.MemoryStream ms = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(FullContent.ToString()));
            //return JsonLength = (int)ms.Length;
            return(JsonLength = System.Text.Encoding.UTF8.GetBytes(FullContent.ToString()).Length);
        }
Exemplo n.º 2
0
        public virtual MultisourcedStream MakeStream(out long contentLength)
        {
            MultisourcedStream stream;

            Timestamp = DateTime.Now;
            Duration  = Timestamp - _start;
            CalculateJsonLength();
            System.IO.MemoryStream msKnot = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(JsonLength.ToString() + "\0"));
            System.IO.MemoryStream ms     = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(FullContent.ToString()));

            if (Stream != null)
            {
                stream = new MultisourcedStream(msKnot, ms, Stream);
            }
            else
            {
                stream = new MultisourcedStream(msKnot, ms);
            }

            contentLength = stream.Length;
            return(stream);
        }