TextStream

Moduleejs.io
Definition class TextStream
InheritanceTextStream inherit Object
Specifiedejscript-1.1
StabilityEvolving.

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

QualifiersPropertyTypeDescription
public get availableNumberThe number of bytes available to read.

TextStream Methods

QualifiersMethod
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

public close(graceful: Boolean = true): Void

Close the input stream and free up all associated resources.

Parameters
graceful: Boolean [default: true]

public flush(graceful: Boolean = true): 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.
Parameters
graceful: Boolean If true, write all pending data. [default: true]

public read(buffer: ByteArray, offset: Number = 0 , count: Number = -1): Number

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 readLines(numLines: Number = -1): Array

Read a required number of lines of data from the stream.

Parameters
numLines: Number Of lines to read. Defaults to read all lines. [default: -1]
Returns
Array containing the read lines.
Throws
IOError: if an I/O error occurs.

public readString(count: Number = -1): String

Read a string from the stream.

Parameters
count: Number Of bytes to read. Returns the entire stream contents if count is -1. [default: -1]
Returns
A string.
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.

public write(data: Array): Number

Write characters to the stream.

Description
Endpoint can accept more data.
Parameters
data: Array String to write.
Returns
The total number of elements that were written.
Throws
IOError: if there is an I/O error.

public writeLine(lines: Array): Number

Write text lines to the stream.

Description
The text line is written after appending the system text newline character or characters.
Parameters
lines: Array Text lines to write.
Returns
The number of characters written or -1 if unsuccessful.
Throws
IOError: if the file could not be written.