Class InputStream
Object
A stream of binary or character data which can be read from.
- Source Code:
- View Source
Field Summary
byteOrder :ByteOrder - Determines the endianness of the data in this stream when reading multi-byte values.
Instance Method Summary
read ():UInt8? - Reads and returns a single byte.
read ():UInt16? - Reads two bytes from this stream, interpreting them as a
UInt16
value. read ():UInt32? - Reads four bytes from this stream, interpreting them as a
UInt32
value. read ():UInt64? - Reads eight bytes from this stream, interpreting them as a
UInt64
value. read ():Int8? - Reads a single byte from this stream as an
Int8
. read ():Int16? - Reads two bytes from this stream, interpreting them as an
Int16
value. read ():Int32? - Reads four bytes from this stream, interpreting them as an
Int32
value. read ():Int64? - Reads eight bytes from this stream, interpreting them as an
Int64
value. read ():Char8? - Reads a single byte from this stream as a
Char8
. read (buffer :
,Pointer<UInt8> max :
):Int Int - Reads up to
max
bytes from this stream into a buffer and returns the number of bytes actually read. read (buffer :
,Pointer<Int8> max :
):Int Int - As
read(Pointer<UInt8>, Int)
, but treats the read bytes as signed. read (buffer :
,Pointer<Char8> max :
):Int Int - As
read(Pointer<UInt8>, Int)
, but treats the read bytes asChar8
s. readFully ():String - Reads from this stream until the end, returning the data read as a
String
. readFully ():Array<UInt8> - Reads from this stream until the end, returning the data read as an
Array<UInt8>
. readLine ():String? - Reads a single line of text from this stream and returns it as a
String
. sendTo (out :
):OutputStream Maybe<Int> - Continually reads from this stream, sending all of the data read to an
OutputStream
. lines ():Iterator<String> - Returns an
Iterator
which reads from this string one line at a time. close ():Error? - Closes this
InputStream
.
Fields
Determines the endianness of the data in this stream when reading multi-byte values. Defaults to
LITTLE_ENDIAN
, but may be freely changed.
Instance Methods
@extendable
method read
():UInt8?
Reads and returns a single byte. Blocks until at least one byte is available for reading, or
returns null
if the end of the stream has been reached or in the event of an error.
@extendable
method read
():UInt16?
Reads two bytes from this stream, interpreting them as a UInt16
value. The interpretation of
the bytes is determined by the byteOrder
field.
@extendable
method read
():UInt32?
Reads four bytes from this stream, interpreting them as a UInt32
value. The interpretation of
the bytes is determined by the byteOrder
field.
@extendable
method read
():UInt64?
Reads eight bytes from this stream, interpreting them as a UInt64
value. The interpretation of
the bytes is determined by the byteOrder
field.
method read
():Int8?
Reads a single byte from this stream as an Int8
.
method read
():Int16?
Reads two bytes from this stream, interpreting them as an Int16
value. The interpretation of
the bytes is determined by the byteOrder
field.
method read
():Int32?
Reads four bytes from this stream, interpreting them as an Int32
value. The interpretation of
the bytes is determined by the byteOrder
field.
method read
():Int64?
Reads eight bytes from this stream, interpreting them as an Int64
value. The interpretation of
the bytes is determined by the byteOrder
field.
method read
():Char8?
Reads a single byte from this stream as a Char8
.
@extendable
@post(@return >= 0)
method read
(buffer :Pointer<UInt8>
,
max :Int
):Int
Reads up to max
bytes from this stream into a buffer and returns the number of bytes actually
read. Blocks until at least one byte is available for reading, or returns 0
if the end of the
stream has been reached or if an error occurs.
- Parameters:
-
- value of typebuffer Pointer<UInt8>
- value of typemax Int
method read
(buffer :Pointer<Int8>
,
max :Int
):Int
As read(Pointer<UInt8>, Int)
, but treats the read bytes as signed.
- Parameters:
-
- value of typebuffer Pointer<Int8>
- value of typemax Int
method read
(buffer :Pointer<Char8>
,
max :Int
):Int
As read(Pointer<UInt8>, Int)
, but treats the read bytes as Char8
s.
- Parameters:
-
- value of typebuffer Pointer<Char8>
- value of typemax Int
method readFully
():String
Reads from this stream until the end, returning the data read as a String
. As streams may
contain a very large (or even infinite) amount of data, you should exercise caution when using
readFully
.
method readFully
():Array<UInt8>
Reads from this stream until the end, returning the data read as an Array<UInt8>
. As streams
may contain a very large (or even infinite) amount of data, you should exercise caution when
using readFully
.
FIXME error
method readLine
():String?
Reads a single line of text from this stream and returns it as a String
. Either "\n"
or
"\r\n"
is accepted as a valid line ending. The line ending is not part of the returned string.
Returns null
if an error occurs while reading.
method sendTo
(out :OutputStream
):Maybe<Int>
Continually reads from this stream, sending all of the data read to an OutputStream
. Returns
the number of bytes transferred when the end of the input is reached (which may be "never" for
some InputStream
s).
- Parameters:
-
- value of typeout OutputStream
function lines
():Iterator<String>
Returns an Iterator
which reads from this string one line at a time. The Iterator
will
report that it is finished either when the end of the stream is reached or an error occurs.
@extendable
method close
():Error?
Closes this InputStream
. The default implementation does nothing.