public CharWriteBuffer(Stream stream, Encoding encoding, int initialSize = defaultInitialSize) { this.stream = new StreamWriter(stream, encoding); this.bufferOwner = BufferArrayPool <char> .Rent(initialSize); this.buffer = bufferOwner; this.position = 0; this.streamWritten = 0; }
public CharWriteBuffer(int initialSize) { this.stream = null; this.bufferOwner = BufferArrayPool <char> .Rent(initialSize); this.buffer = bufferOwner; this.position = 0; this.streamWritten = 0; }
public ByteWriter(int initialSize, Encoding encoding = null) { this.fromPool = true; this.bufferOwner = BufferArrayPool <byte> .Rent(initialSize); this.buffer = bufferOwner; this.encoding = encoding ?? defaultEncoding; this.position = 0; this.length = buffer.Length; }
public CharReader(Stream stream, Encoding encoding) { this.stream = new StreamReader(stream, encoding); this.streamBufferOwner = BufferArrayPool <char> .Rent(initialStreamBufferSize); this.streamBuffer = this.streamBufferOwner; this.buffer = this.streamBuffer; this.bufferPosition = 0; this.bufferLength = 0; this.segmentStart = -1; }
private void EnsureBufferSize(int additionalSize) { if (position + additionalSize <= buffer.Length) { return; } if (bufferOwner == null) { bufferOwner = BufferArrayPool <char> .Rent(defaultInitialSize); buffer = bufferOwner; if (position + additionalSize < buffer.Length) { return; } } if (position > 0 && stream != null) { #if NETSTANDARD2_0 stream.WriteToSpan(buffer.Slice(0, position)); #else stream.Write(buffer.Slice(0, position)); #endif streamWritten += position; position = 0; if (position + additionalSize < buffer.Length) { return; } } var minSize = position + additionalSize; BufferArrayPool <char> .Grow(ref bufferOwner, minSize); buffer = bufferOwner; }