Any kind of stream to read/write/both to or from a source

Introduced properties

abstract fun close

core :: Stream :: close

close the stream
fun codec: Codec

core :: Stream :: codec

Codec used to transform raw data to text
fun codec=(c: Codec)

core :: Stream :: codec=

Change the codec for this stream.
fun finish

core :: Stream :: finish

Post-work hook.
fun last_error: nullable IOError

core :: Stream :: last_error

Error produced by the file stream
protected fun last_error=(last_error: nullable IOError)

core :: Stream :: last_error=

Error produced by the file stream
protected fun lookahead: CString

core :: Stream :: lookahead

Lookahead buffer for codecs
protected fun lookahead=(lookahead: CString)

core :: Stream :: lookahead=

Lookahead buffer for codecs
protected fun lookahead_capacity: Int

core :: Stream :: lookahead_capacity

Capacity of the lookahead
protected fun lookahead_capacity=(lookahead_capacity: Int)

core :: Stream :: lookahead_capacity=

Capacity of the lookahead
protected fun lookahead_length: Int

core :: Stream :: lookahead_length

Current occupation of the lookahead
protected fun lookahead_length=(lookahead_length: Int)

core :: Stream :: lookahead_length=

Current occupation of the lookahead
protected fun set_codec(codec: Codec)

core :: Stream :: set_codec

Codec used to transform raw data to text
fun start

core :: Stream :: start

Pre-work hook.
protected fun write_buffer: CString

core :: Stream :: write_buffer

Buffer for writing data to a stream
protected fun write_buffer=(write_buffer: CString)

core :: Stream :: write_buffer=

Buffer for writing data to a stream

Redefined properties

redef type SELF: Stream

core $ Stream :: SELF

Type of this instance, automatically specialized in every class
redef init init

core $ Stream :: init

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
abstract fun close

core :: Stream :: close

close the stream
fun codec: Codec

core :: Stream :: codec

Codec used to transform raw data to text
fun codec=(c: Codec)

core :: Stream :: codec=

Change the codec for this stream.
fun finish

core :: Stream :: finish

Post-work hook.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun last_error: nullable IOError

core :: Stream :: last_error

Error produced by the file stream
protected fun last_error=(last_error: nullable IOError)

core :: Stream :: last_error=

Error produced by the file stream
protected fun lookahead: CString

core :: Stream :: lookahead

Lookahead buffer for codecs
protected fun lookahead=(lookahead: CString)

core :: Stream :: lookahead=

Lookahead buffer for codecs
protected fun lookahead_capacity: Int

core :: Stream :: lookahead_capacity

Capacity of the lookahead
protected fun lookahead_capacity=(lookahead_capacity: Int)

core :: Stream :: lookahead_capacity=

Capacity of the lookahead
protected fun lookahead_length: Int

core :: Stream :: lookahead_length

Current occupation of the lookahead
protected fun lookahead_length=(lookahead_length: Int)

core :: Stream :: lookahead_length=

Current occupation of the lookahead
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
protected fun set_codec(codec: Codec)

core :: Stream :: set_codec

Codec used to transform raw data to text
fun start

core :: Stream :: start

Pre-work hook.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
protected fun write_buffer: CString

core :: Stream :: write_buffer

Buffer for writing data to a stream
protected fun write_buffer=(write_buffer: CString)

core :: Stream :: write_buffer=

Buffer for writing data to a stream
package_diagram core::Stream Stream core::Object Object core::Stream->core::Object core::FileStream FileStream core::FileStream->core::Stream core::Protocol Protocol core::Protocol->core::Stream binary::BinaryStream BinaryStream binary::BinaryStream->core::Stream core::FileReader FileReader core::FileReader->core::FileStream core::FileWriter FileWriter core::FileWriter->core::FileStream core::FileReader... ... core::FileReader...->core::FileReader core::FileWriter... ... core::FileWriter...->core::FileWriter core::ReaderProtocol ReaderProtocol core::ReaderProtocol->core::Protocol core::WriterProtocol WriterProtocol core::WriterProtocol->core::Protocol core::ReaderProtocol... ... core::ReaderProtocol...->core::ReaderProtocol core::WriterProtocol... ... core::WriterProtocol...->core::WriterProtocol core::Writer Writer core::Writer->binary::BinaryStream core::Reader Reader core::Reader->binary::BinaryStream core::Writer... ... core::Writer...->core::Writer core::Reader... ... core::Reader...->core::Reader

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

abstract class BinaryStream

binary :: BinaryStream

A stream of binary data
abstract class FileStream

core :: FileStream

Stream used to interact with a File or FileDescriptor
class Protocol

core :: Protocol

Stream class used as a Decorator over a stream

Descendants

class BytesReader

core :: BytesReader

Read from bytes in memory
class BytesWriter

core :: BytesWriter

Write to bytes in memory
class Connection

libevent :: Connection

Spawned to manage a specific connection
abstract class Duplex

core :: Duplex

A Stream that can be written to and read from
class DuplexProtocol

core :: DuplexProtocol

Reader/Writer decorator over a duplex-capable stream
class EchoConnection

libevent :: EchoConnection

Connection echoing data received from clients back at them
class FileReader

core :: FileReader

Stream that can read from a File
class FileWriter

core :: FileWriter

Stream that can write to a File
class HTTPConnection

nitcorn :: HTTPConnection

Connection rebuilding HTTP requests
class HttpServer

nitcorn :: HttpServer

A server handling a single connection
abstract class PollableReader

core :: PollableReader

Reader capable of declaring if readable without blocking
class ProcessDuplex

core :: ProcessDuplex

Process on which stdout can be read and stdin can be written to like a Duplex
class ProcessReader

core :: ProcessReader

Process on which the stdout is readable like a Reader
class ProcessWriter

core :: ProcessWriter

Process on which stdin is writable like a Writer
abstract class Reader

core :: Reader

A Stream that can be read from
class ReaderProtocol

core :: ReaderProtocol

Reader decorator over a read-capable stream
class Stderr

core :: Stderr

Standard error stream.
class Stdin

core :: Stdin

Standard input stream.
class Stdout

core :: Stdout

Standard output stream.
class StringReader

core :: StringReader

Stream reading from a String source
class StringWriter

core :: StringWriter

Stream writing to a String
class TCPStream

socket :: TCPStream

Simple communication stream with a remote socket
class WebsocketConnection

websocket :: WebsocketConnection

Connection to a websocket client
abstract class Writer

core :: Writer

A Stream that can be written to
class WriterProtocol

core :: WriterProtocol

Writer decorator over a write-capable stream

Class definitions

core $ Stream
# Any kind of stream to read/write/both to or from a source
abstract class Stream
	# Codec used to transform raw data to text
	#
	# Note: defaults to UTF-8
	var codec: Codec = utf8_codec is protected writable(set_codec)

	# Lookahead buffer for codecs
	#
	# Since some codecs are multibyte, a lookahead may be required
	# to store the next bytes and consume them only if a valid character
	# is read.
	protected var lookahead: CString is noinit

	# Capacity of the lookahead
	protected var lookahead_capacity = 0

	# Current occupation of the lookahead
	protected var lookahead_length = 0

	# Buffer for writing data to a stream
	protected var write_buffer: CString is noinit

	init do
		var lcap = codec.max_lookahead
		lookahead = new CString(lcap)
		write_buffer = new CString(lcap)
		lookahead_length = 0
		lookahead_capacity = lcap
	end

	# Change the codec for this stream.
	fun codec=(c: Codec) do
		if c.max_lookahead > lookahead_capacity then
			var lcap = codec.max_lookahead
			var lk = new CString(lcap)
			var llen = lookahead_length
			if llen > 0 then
				lookahead.copy_to(lk, llen, 0, 0)
			end
			lookahead = lk
			lookahead_capacity = lcap
			write_buffer = new CString(lcap)
		end
		set_codec(c)
	end

	# Error produced by the file stream
	#
	#     var ifs = new FileReader.open("donotmakethisfile.binx")
	#     ifs.read_all
	#     ifs.close
	#     assert ifs.last_error != null
	var last_error: nullable IOError = null

	# close the stream
	fun close is abstract

	# Pre-work hook.
	#
	# Used to inform `self` that operations will start.
	# Specific streams can use this to prepare some resources.
	#
	# Is automatically invoked at the beginning of `with` structures.
	#
	# Do nothing by default.
	fun start do end

	# Post-work hook.
	#
	# Used to inform `self` that the operations are over.
	# Specific streams can use this to free some resources.
	#
	# Is automatically invoked at the end of `with` structures.
	#
	# call `close` by default.
	fun finish do close
end
lib/core/stream.nit:29,1--106,3