@haxall/haxall
    Preparing search index...

    Class InStream

    InStream is used to read binary and text stream based input.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    type$: Type

    Methods

    • Return the number of bytes available on input stream without blocking. Return zero if no bytes available or it is unknown. Throw IOErr on error.

      Returns number

    • The current charset used to decode bytes into Unicode characters. The default charset should always be UTF-8.

      Returns Charset

    • The current charset used to decode bytes into Unicode characters. The default charset should always be UTF-8.

      Parameters

      Returns void

    • Close the input stream. This method is guaranteed to never throw an IOErr. Return true if the stream was closed successfully or false if the stream was closed abnormally. Default implementation does nothing and returns true.

      Returns boolean

    • Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:

      this < that   =>  <0
      this == that => 0
      this > that => >0

      This method may also be accessed via the < <= <=> >= and > shortcut operators. If not overridden the default implementation compares the toStr representations. Also see docLang.

      Examples:

      3.compare(8)  =>  -1
      8.compare(3) => 1
      8.compare(8) => 0
      3 <=> 8 => -1 // shortcut for 3.compare(8)

      Parameters

      Returns number

    • Read the entire stream into Str lines based on the current encoding. Call the specified function for each line read. Each line is terminated by \n, \r\n, \r, or EOF using the same semantics as readLine with the null default max line length. The Str lines themselves do not contain a trailing newline. Empty lines are returned as the empty Str "". This InStream is guaranteed to be closed upon return.

      Parameters

      • f: (arg0: string) => void

      Returns void

    • Byte order mode for binary reads. Default is Endian.big (network byte order).

      Returns Endian

    • Byte order mode for binary reads. Default is Endian.big (network byte order).

      Parameters

      Returns void

    • Compare this object to the specified for equality. This method may be accessed via the == and != shortcut operators. If not overridden the default implementation compares for reference equality using the === operator. If this method is overridden, then hash() must also be overridden such that any two objects which return true for equals() must return the same value for hash(). This method must accept null and return false.

      Parameters

      Returns boolean

    • Return a unique hashcode for this object. If a class overrides hash() then it must ensure if equals() returns true for any two objects then they have same hash code.

      Returns number

    • Return if this Obj is immutable and safe to share between threads:

      • an instance of a const class
      • the result of toImmutable on List, Map, or Buf
      • a Func object may or may not be immutable - see sys::Func.
      • other instances are assumed mutable and return false

      Returns boolean

    • Peek at the next byte to be read without actually consuming it. Peek has the same semantics as a read/unread. Return null if at end of stream.

      Returns number

    • Peek at the next char to be read without actually consuming it. Peek has the same semantics as a readChar/unreadChar. Return null if at end of stream.

      Returns number

    • Pipe bytes from this input stream to the specified output stream. If n is specified, then block until exactly n bytes have been read or throw IOErr if end of stream is reached first. If n is null then the entire contents of this input stream are piped. If close is true, then this input stream is guaranteed to be closed upon return (the OutStream is never closed). Return the number of bytes piped to the output stream.

      Parameters

      • out: OutStream
      • Optionaln: number
      • Optionalclose: boolean

      Returns number

    • Read the next unsigned byte from the input stream. Return null if at end of stream. Throw IOErr on error.

      Returns number

    • Read the entire contents of the stream into a memory Buf. The resulting buffer is automatically positioned at the beginning. This InStream is guaranteed to be closed.

      Returns Buf

    • Read the entire stream into a list of Str lines based on the configured charset encoding. Each Str in the list maps to a line terminated by \n, \r\n, \r, or EOF using the same semantics as readLine with default max line length of null. The Str lines themselves do not contain a trailing newline. Empty lines are returned as the empty Str "". Return an empty list if currently at end of stream (not null). Throw IOErr if there is a problem reading the stream or an invalid character encoding is encountered. This InStream is guaranteed to be closed upon return.

      Returns List<string>

    • Read the entire stream into a Str based on the configured charset encoding. If the normalizeNewlines flag is true, then all occurances of \r\n or \r newlines are normalized into \n. Return "" if the stream is empty. Throw IOErr if there is a problem reading the stream or an invalid character encoding is encountered. This InStream is guaranteed to be closed.

      Parameters

      • OptionalnormalizeNewlines: boolean

      Returns string

    • Read between 0 and 64 bits from the input stream. Bits which are partial bytes are consumed from the input stream one byte at a time. Throw IOErr on error or if end of stream is reached before given number of bits can be read.

      Parameters

      • num: number

      Returns number

    • Read the next byte and return true if nonzero. This method may be paired with OutStream.writeBool. Throw IOErr on error or if the end of stream is reached before one byte can be read.

      Returns boolean

    • Attempt to read the next n bytes into the Buf at its current position. The buffer will be grown as needed. Return the number of bytes read and increment buf's size and position accordingly. Return null and leave buf's state untouched if end of stream. Note this method may not read the full number of n bytes, use readBufFully if you must block until all n bytes read. Throw IOErr on error.

      Parameters

      • buf: Buf
      • n: number

      Returns number

    • Read the next n bytes from the stream into the Buf at its current position. The buffer will be grown as needed. If the buf parameter is null, then a memory buffer is automatically created with a capacity of n. Block until exactly n bytes have been read or throw IOErr if end of stream is reached first. Return the Buf passed in or the one created automatically if buf is null. The buffer is automatically positioned at zero.

      Parameters

      • buf: Buf
      • n: number

      Returns Buf

    • Read a single Unicode character from the stream using the current charset encoding. Return null if at end of stream. Throw IOErr if there is a problem reading the stream, or an invalid character encoding is encountered.

      Returns number

    • Read the next n chars from the stream as a Str using the current charset. Block until exactly n chars have been read or throw IOErr if end of stream is reached first.

      Parameters

      • n: number

      Returns string

    • Read a decimal string according to readUtf.

      Returns number

    • Read the next four bytes as a 32-bit floating point number using configured endian according to Float.bits32. This method may be paired with OutStream.writeF4. Throw IOErr on error or if the end of stream is reached before four bytes can be read.

      Returns number

    • Read the next eight bytes as a 64-bit floating point number using configured endian according to Float.bits. This method may be paired with OutStream.writeF8. Throw IOErr on error or if the end of stream is reached before four bytes can be read.

      Returns number

    • Read the next line from the input stream as a Str based on the configured charset. A line is terminated by \n, \r\n, \r, or EOF. The Str returned never contains the trailing newline.

      The max parameter specifies the maximum number of Unicode characters (not bytes) to read before truncating the line and returning. If max is null, then no boundary is enforced except of course the end of the stream.

      Return null if the end of stream has been reached. Throw IOErr if there is a problem reading the stream or an invalid character encoding is encountered.

      Parameters

      • Optionalmax: number

      Returns string

    • Read a string terminated by the "\0" character. The "\0" character is read from the stream, but not included in the string result.

      The max parameter specifies the maximum number of Unicode characters (not bytes) to read before truncating the string and returning. If max is null, then no boundary is enforced except of course the end of the stream.

      Parameters

      • Optionalmax: number

      Returns string

    • Read a serialized object from the stream according to the Fantom serialization format. Throw IOErr or ParseErr on error. This method may consume bytes/chars past the end of the serialized object (we may want to add a "full stop" token at some point to support compound object streams).

      The options may be used to specify additional decoding logic:

      • "makeArgs": Obj[] arguments to pass to the root object's make constructor via Type.make

      Parameters

      Returns JsObj

    • Read the entire stream into a Str:Str of name/value pairs using the Fantom props file format. This format is similar to but different than the Java properties file format:

      • Input must be UTF-8 encoded (current charset is ignored)
      • Name/value pairs formatted as logical line: <name>=<value>
      • Any Unicode character allowed in name or value
      • Leading and trailing whitespace trimmed from both name and value
      • Duplicate name keys within one file is an error condition
      • Lines starting with # are comments
      • Comment to end of line is // if start of line or preceeded by whitespace
      • Block comment is /* */ (may be nested)
      • Use trailing \ to continue logical line to another actual line, any leading whitespace (space or tab char) is trimmed from beginning of continued line
      • Fantom Str literal escape sequences supported: \n \r \t or \uxxxx
      • The $ character is treated as a normal character and should not be escaped, but convention is to indicate a variable in a format string
      • Convention is that name is lower camel case with dot separators

      Throw IOErr if there is a problem reading the stream or an invalid props format is encountered. This InStream is guaranteed to be closed.

      Also see Env.props.

      Returns Map<string, string>

    • Read the next byte as a signed 8-bit number. This method may be paired with OutStream.write. Throw IOErr on error or if the end of stream is reached before one byte can be read.

      Returns number

    • Read the next two bytes as a signed 16-bit number using configured endian. This method may be paired with OutStream.writeI2. Throw IOErr on error or if the end of stream is reached before two bytes can be read.

      Returns number

    • Read the next four bytes as a signed 32-bit number using configured endian. This method may be paired with OutStream.writeI4. Throw IOErr on error or if the end of stream is reached before four bytes can be read.

      Returns number

    • Read the next eight bytes as a signed 64-bit number using configured endian. This method may be paired with OutStream.writeI8. Throw IOErr on error or if the end of stream is reached before eight bytes can be read. Note there is no readU8 (because Java doesn't support unsigned longs).

      Returns number

    • Read a Str token from the input stream which is terminated when the specified function c returns true. The terminating char is unread and will be the next char read once this method returns. Characters are read based on the currently configured charset.

      If c is null then the default implementation tokenizes up until the next character which returns true for Int.isSpace.

      The max parameter specifies the maximum number of Unicode characters (not bytes) to read before truncating the line and returning. If max is null, then no boundary is enforced except of course the end of the stream.

      Return null if the end of stream has been reached. Throw IOErr if there is a problem reading the stream or an invalid character encoding is encountered.

      Parameters

      • Optionalmax: number
      • Optionalc: (arg0: number) => boolean

      Returns string

    • Read the next byte as an unsigned 8-bit number. This method may be paired with OutStream.write. Throw IOErr on error or if the end of stream is reached before one byte can be read. This method differs from read in that it will throw IOErr on end of stream rather than return null.

      Returns number

    • Read the next two bytes as an unsigned 16-bit number using configured endian. This method may be paired with OutStream.writeI2. Throw IOErr on error or if the end of stream is reached before two bytes can be read.

      Returns number

    • Read the next four bytes as an unsigned 32-bit number using configured endian. This method may be paired with OutStream.writeI4. Throw IOErr on error or if the end of stream is reached before four bytes can be read.

      Returns number

    • Read a Str in modified UTF-8 format according to the java.io.DataInput specification. This method may be paired with OutStream.writeUtf. Throw IOErr on error, invalid UTF encoding, or if the end of stream is reached before the string is fully read.

      Returns string

    • Attempt to skip n number of bytes. Return the number of bytes actually skipped which may be equal to or less than n.

      Parameters

      • n: number

      Returns number

    • Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:

      • if type is const, return this
      • if already an immutable List, Map, Buf, or Func return this
      • if a List, then attempt to perform a deep clone by calling toImmutable on all items
      • if a Map, then attempt to perform a deep clone by calling toImmutable on all values (keys are already immutable)
      • some Funcs can be made immutable - see sys::Func
      • if a Buf create immutable copy, see sys::Buf
      • any other object throws NotImmutableErr

      Returns Readonly<this>

    • Return a string representation of this object.

      Returns string

    • Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:

      a->x        a.trap("x", null)
      a->x() a.trap("x", null)
      a->x = b a.trap("x", [b])
      a->x(b) a.trap("x", [b])
      a->x(b, c) a.trap("x", [b, c])

      The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.

      Parameters

      Returns JsObj

    • Get the Type instance which represents this object's class. Also seeType.of or Pod.of.

      Returns Type

    • Pushback a byte so that it is the next byte to be read. There is a finite limit to the number of bytes which may be pushed back. Return this.

      Parameters

      • b: number

      Returns this

    • Pushback a char so that it is the next char to be read. This method pushes back one or more bytes depending on the current character encoding. Return this.

      Parameters

      • b: number

      Returns this

    • This method called whenever an it-block is applied to an object. The default implementation calls the function with this, and then returns this.

      Parameters

      • f: (arg0: this) => void

      Returns this

    • Write x.toStr to standard output followed by newline. If x is null then print "null". If no argument is provided then print an empty line.

      Parameters

      Returns void