type

OutStream

src class OutStream : Obj

OutStream is used to write binary and text data to an output stream.

constructors

make

Constructor for an OutStream which wraps another stream.

fields

charset

The current charset used to encode Unicode characters into bytes.

endian

Byte order mode for binary writes.

xmlEscNewlines

XML escape newline characters.

xmlEscQuotes

XML escape single and double quotes.

xmlEscUnicode

XML escape any character greater then 0x7f.

methods

close

Close the output stream.

flush

Flush the stream so any buffered bytes are written out.

print

Convenience for writeChars(obj.toStr).

printLine

Convenience for writeChars(obj.toStr + "\n").

sync

If this output stream is mapped to a file device, then synchronize all memory buffers to the physical storage device.

write

Write a byte to the output stream.

writeBits

Write between 0 and 64 bits of the given integer value.

writeBool

Write one byte, one if true or zero if false.

writeBuf

Write n bytes from the specified Buf at its current position to this output stream.

writeChar

Write one or more bytes to the stream for the specified Unicode character based on the current charset encoding.

writeChars

Write the Unicode characters in the specified string to the stream using the current charset encoding.

writeDecimal

Write a decimal as a string according to writeUtf.

writeF4

Write four bytes as a 32-bit floating point number using configured endian order according to Float.bits32.

writeF8

Write eight bytes as a 64-bit floating point number using configured endian order according to Float.bits.

writeI2

Write two bytes as a 16-bit number using configured endian.

writeI4

Write four bytes as a 32-bit number using configured endian.

writeI8

Write eight bytes as a 64-bit number using configured endian.

writeObj

Write a serialized object from the stream according to the Fantom serialization format.

writeProps

Write the given map of Str name/value pairs to the output stream according to the Fantom props file format (see InStream.readProps for full specification).

writeUtf

Write a Str in modified UTF-8 format according to the java.io.DataOutput specification.

writeXml

Write a string to this output stream using XML escape sequences.

Slot Details

charset

src Charset charset

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

close

src virtual Bool close()

Close the output 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.

endian

src Endian endian

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

flush

src virtual This flush()

Flush the stream so any buffered bytes are written out. Default implementation does nothing. Throw IOErr on error. Return this.

make

src new make(OutStream? out)

Constructor for an OutStream which wraps another stream. All writes to this stream will be routed to the specified inner stream.

If out is null, then it is the subclass responsibility to handle writes by overriding the following methods: write and writeBuf.

print

src This print(Obj? s)

Convenience for writeChars(obj.toStr). If obj is null, then print the string "null". Return this.

printLine

src This printLine(Obj? obj := "")

Convenience for writeChars(obj.toStr + "\n"). If obj is null then print the string "null\n". Return this.

sync

src virtual This sync()

If this output stream is mapped to a file device, then synchronize all memory buffers to the physical storage device. Throw IOErr on error. Return this.

write

src virtual This write(Int byte)

Write a byte to the output stream. Throw IOErr on error. Return this.

writeBits

src This writeBits(Int val, Int num)

Write between 0 and 64 bits of the given integer value. Bits which are only a partial byte are bufferred in RAM until flush.

writeBool

src This writeBool(Bool b)

Write one byte, one if true or zero if false. This method is paired with InStream.readBool. Throw IOErr on error. Return this.

writeBuf

src virtual This writeBuf(Buf buf, Int n := buf.remaining())

Write n bytes from the specified Buf at its current position to this output stream. If n is defaulted to buf.remaining(), then everything left in the buffer is drained to this output stream. The buf's position is advanced n bytes upon return. Throw IOErr on error. Return this.

writeChar

src This writeChar(Int char)

Write one or more bytes to the stream for the specified Unicode character based on the current charset encoding. Return this.

writeChars

src This writeChars(Str str, Int off := 0, Int len := str.size() - off)

Write the Unicode characters in the specified string to the stream using the current charset encoding. The off arg specifies the index offset to start writing characters and len the number of characters in str to write. Return this.

writeDecimal

src This writeDecimal(Decimal d)

Write a decimal as a string according to writeUtf.

writeF4

src This writeF4(Float r)

Write four bytes as a 32-bit floating point number using configured endian order according to Float.bits32. This is paired with InStream.readF4. Throw IOErr on error. Return this.

writeF8

src This writeF8(Float r)

Write eight bytes as a 64-bit floating point number using configured endian order according to Float.bits. This is paired with InStream.readF8. Throw IOErr on error. Return this.

writeI2

src This writeI2(Int n)

Write two bytes as a 16-bit number using configured endian. This method may be paired with InStream.readU2 or InStream.readS2. Throw IOErr on error. Return this.

writeI4

src This writeI4(Int n)

Write four bytes as a 32-bit number using configured endian. This method may be paired with InStream.readU4 or InStream.readS4. Throw IOErr on error. Return this.

writeI8

src This writeI8(Int n)

Write eight bytes as a 64-bit number using configured endian. This is paired with InStream.readS8. Throw IOErr on error. Return this.

writeObj

src This writeObj(Obj? obj, [Str:Obj]? options := null)

Write a serialized object from the stream according to the Fantom serialization format. Throw IOErr on error. Return this.

The options may be used to specify the format of the output:

  • "indent": Int specifies how many spaces to indent each level. Default is 0.
  • "skipDefaults": Bool specifies if we should skip fields at their default values. Field values are compared according to the equals method. Default is false.
  • "skipErrors": Bool specifies if we should skip objects which aren't serializable. If true then we output null and a comment. Default is false.

writeProps

src This writeProps(Str:Str props, Bool close := true)

Write the given map of Str name/value pairs to the output stream according to the Fantom props file format (see InStream.readProps for full specification). The props are written using UTF-8 regardless of this stream's current charset. If close argument is true, then automatically close the stream. Return this.

writeUtf

src This writeUtf(Str s)

Write a Str in modified UTF-8 format according to the java.io.DataOutput specification. This method is paired with InStream.readUtf. Throw IOErr on error. Return this.

writeXml

src This writeXml(Str str, Int mode := 0)

Write a string to this output stream using XML escape sequences. By default only the < > & characters are escaped. You can use the following flags to escape additional characters:

Any control character less than 0x20 which is not \t, \n or \r is always escaped with a numeric reference. Return this.

xmlEscNewlines

src const static Int xmlEscNewlines := 1

XML escape newline characters. See writeXml.

xmlEscQuotes

src const static Int xmlEscQuotes := 2

XML escape single and double quotes. See writeXml.

xmlEscUnicode

src const static Int xmlEscUnicode := 4

XML escape any character greater then 0x7f. See writeXml.