private void Init(Stream stream, Encoding encoding, int bufferSize) { this.stream = stream; this.encoding = encoding; this.encoder = encoding.GetEncoder(); if (bufferSize < MinBufferSize) { bufferSize = MinBufferSize; } charBuffer = new char[bufferSize]; byteBuffer = new byte[encoding.GetMaxByteCount(bufferSize)]; charLen = bufferSize; // If we're appending to a Stream that already has data, don't write // the preamble junk. if (stream.CanSeek && stream.Position > 0) { haveWrittenPreamble = true; } closable = true; #if _DEBUG if (BCLDebug.CorrectnessEnabled()) { allocatedFrom = Environment.GetStackTrace(null); } #endif }