TextStream
Module | ejs.io |
Namespace | "ejs.io" |
Definition | class TextStream |
Specified | Ejs-11. |
Inheritance | TextStream ![]() |
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 static const | LATIN1 | String | Text encoding formats for use with $encoding. |
public static const | UTF_16 | String | Text encoding formats for use with $encoding. |
public static const | UTF_8 | String | Text encoding formats for use with $encoding. |
TextStream Methods
Qualifiers | Method |
---|---|
public | available(): Number |
Return the number of bytes available to read. | |
public | close(graceful: Boolean): Void |
Close the input stream and free up all associated resources. | |
public get | encoding(): String |
Get the current text encoding. | |
public set | encoding(encoding: String): Void |
Set the current text encoding. | |
public | flush(): Void |
Flush the stream and the underlying file data. | |
public | read(buffer: ByteArray, offset: Number, count: Number): Number |
Read characters from the stream into the supplied byte array. | |
public | readLine(): String |
Read a line from the stream. | |
public | readLines(numLines: Number): Array |
Read a required number of lines of data from the stream. | |
public | readString(count: Number): String |
Read a string from the stream. | |
public | skip(n: Number): Void |
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
public available(): Number
Return the number of bytes available to read.
- Returns
- A the number of available bytes.
Close the input stream and free up all associated resources.
- Parameters
graceful: Boolean [default: true]
get public encoding(): String
Get the current text encoding.
- Returns
- The current text encoding as a string.
Set the current text encoding.
- Parameters
encoding: String string containing the current text encoding. Supported encodings are: utf-8. [default: UTF_8]
public flush(): Void
Flush the stream and the underlying file data.
- Description
- Will block while flushing. Note: may complete before the data is actually written to disk.
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 < 0, then read to the write position. count: Number Number of bytes to read.
- Returns
- A count of characters actually written.
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.
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.