TextStream
Module | ejs.io |
Definition | class TextStream |
Inheritance | TextStream ![]() |
Specified | ejscript-1.1 |
Stability | Evolving. |
TextStreams interpret data as a stream of Unicode characters.
They provide methods to read and write data in various text encodings and to read/write lines of text appending appropriate system dependent new line terminators. TextStreams can be stacked upon other Streams such as files, byte arrays, sockets, or Http objects.
Properties
Qualifiers | Property | Type | Description |
---|---|---|---|
public get | available | Number | The number of bytes available to read. |
TextStream Methods
Qualifiers | Method |
---|---|
public | close(graceful: Boolean = true): Void |
Close the input stream and free up all associated resources. | |
public | flush(graceful: Boolean = true): Void |
Flush the stream and the underlying file data. | |
public | read(buffer: ByteArray, offset: Number = 0 , count: Number = -1): Number |
Read characters from the stream into the supplied byte array. | |
public | readLine(): String |
Read a line from the stream. | |
public | readLines(numLines: Number = -1): Array |
Read a required number of lines of data from the stream. | |
public | readString(count: Number = -1): String |
Read a string from the stream. | |
TextStream(stream: Stream) | |
Create a text filter stream. | |
public | write(data: Array): Number |
Write characters to the stream. | |
public | writeLine(lines: Array): Number |
Write text lines to the stream. |
Method Detail
Close the input stream and free up all associated resources.
- Parameters
graceful: Boolean [default: true]
Flush the stream and the underlying file data.
- Description
- Will block while flushing. Note: may complete before the data is actually written to disk.
- Parameters
graceful: Boolean If true, write all pending data. [default: true]
Read characters from the stream into the supplied byte array.
- Description
- This routine is used by upper streams to read data from the text stream as raw bytes.
- Parameters
buffer: ByteArray Destination byte array for the read data. offset: Number Offset in the byte array to place the data. If the offset is -1, then data is appended to the buffer write position which is then updated. [default: 0 ] count: Number Number of bytes to read. [default: -1]
- Returns
- A count of characters actually read.
- Throws
- IOError: if an I/O error occurs.
public readLine(): String
Read a line from the stream.
- Returns
- A string containing the next line without the newline character. Return null on eof.
- Throws
- IOError: if an I/O error occurs.
public TextStream(stream: Stream)
Create a text filter stream.
- Description
- A Text filter stream must be stacked upon a stream source such as a File.
- Parameters
stream: Stream Stream data source/sink to stack upon.