TextReader CLASS

A text reader that reads text by lines, with '\n' invariably treated as the line separator, regardless of the OS.

On Microsoft Windows the line separator is "\r\n". Since it contains '\n', this reader will still be able to recognize a line break. It will also strip of the penultimate character (\r) when returning the line in text. If the use case requires that the reader, when running on Windows, disregard '\n' that doesn't trail '\r', this class cannot be used.

This class is not thread-safe and must be protected by lock when used in a multi-threaded context.

Parent Class

All Members


TypeNameSignature
constructorTextReaderpublic TextReader(System.IO.Stream)
constructorTextReaderpublic TextReader(System.IO.Stream, string, int, bool)
methodreadlnpublic String readln()

Constructors


public TextReader(Stream stream)

Create a TextReader to read text from the specified stream. Use default buffer size (8K) and default chatset (ASCII); also close the stream after end-of-file is confirmed by the caller.

Parameters

  • stream A stream to read test from. Must be readable.

Throws


public TextReader(Stream stream, string charset, int bufferSize, bool autoClose)

Create a TextReader to read text from the specified stream.

Parameters

  • stream A stream to read the text from. Must be readable.
  • charset The charset to use when converting the read bytes to string. Charset names should have been registered by RFC 2278: IANA Charset Registration Procedures.
  • bufferSize The initial buffer size. Will be set to 1 if it's less than 1. The caller may use a bigger value if most of the lines are known to be long. the TextReader instance may dynamically expand the size as it sees fit.
  • autoClose Close the stream as soon as the end is reached.

Throws


Methods


public String readln()

Read the next line off of the stream.

Returns

  • Null if reaching the end of the stream; otherwise the line in string, excluding the trailing characters marking the end of line.