public WriteOnlyBufferedStream(Stream stream, int bufferSize)
        {
            this.stream = stream;

            this.buffer    = VariableSizedBufferPool.Get(bufferSize, true);
            this._position = 0;
        }
Exemple #2
0
        public static void WriteString(this BufferPoolMemoryStream ms, string str)
        {
            var byteCount = Encoding.UTF8.GetByteCount(str);

            byte[] buffer = VariableSizedBufferPool.Get(byteCount, true);
            Encoding.UTF8.GetBytes(str, 0, str.Length, buffer, 0);
            ms.Write(buffer, 0, byteCount);
            VariableSizedBufferPool.Release(buffer);
        }
Exemple #3
0
        /// <summary>
        /// On WP8 platform there are no ASCII encoding.
        /// </summary>
        public static byte[] GetASCIIBytes(this string str)
        {
            byte[] result = VariableSizedBufferPool.Get(str.Length, false);
            for (int i = 0; i < str.Length; ++i)
            {
                char ch = str[i];
                result[i] = (byte)((ch < (char)0x80) ? ch : '?');
            }

            return(result);
        }
        public byte[] ToArray(bool canBeLarger)
        {
            int l = length - initialIndex;

            byte[] outBuffer = l > 0 ? VariableSizedBufferPool.Get(l, canBeLarger) : VariableSizedBufferPool.NoData;

            if (internalBuffer != null)
            {
                Buffer.BlockCopy(internalBuffer, initialIndex, outBuffer, 0, l);
            }
            return(outBuffer);
        }
        /// <summary>
        /// Resize a byte array. It will release the old one to the pool, and the new one is from the pool too.
        /// </summary>
        public static byte[] Resize(ref byte[] buffer, int newSize, bool canBeLarger)
        {
            if (!_isEnabled)
            {
                Array.Resize <byte>(ref buffer, newSize);
                return(buffer);
            }

            byte[] newBuf = VariableSizedBufferPool.Get(newSize, canBeLarger);
            Array.Copy(buffer, 0, newBuf, 0, Math.Min(newBuf.Length, buffer.Length));
            VariableSizedBufferPool.Release(buffer);
            return(buffer = newBuf);
        }
        public BufferPoolMemoryStream(int capacity)
        {
            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException("capacity");
            }

            canWrite = true;

            internalBuffer = capacity > 0 ? VariableSizedBufferPool.Get(capacity, true) : VariableSizedBufferPool.NoData;
            this.capacity  = internalBuffer.Length;

            expandable     = true;
            allowGetBuffer = true;
        }
Exemple #7
0
 public ReadOnlyBufferedStream(Stream nstream, int bufferSize)
 {
     stream = nstream;
     buf    = VariableSizedBufferPool.Get(bufferSize, true);
 }
Exemple #8
0
 public ReadOnlyBufferedStream(Stream nstream)
 {
     stream = nstream;
     buf    = VariableSizedBufferPool.Get(READBUFFER, true);
 }