Stream used to interact with a File or FileDescriptor

Introduced properties

fun fd: Int

core :: FileStream :: fd

File descriptor of this file
fun file_stat: nullable FileStat

core :: FileStream :: file_stat

The status of a file. see POSIX stat(2).
fun path: nullable String

core :: FileStream :: path

The path of the file.
protected fun path=(path: nullable String)

core :: FileStream :: path=

The path of the file.
fun set_buffering_mode(buf_size: Int, mode: Int)

core :: FileStream :: set_buffering_mode

Sets the buffering mode for the current FileStream

Redefined properties

redef type SELF: FileStream

core $ FileStream :: SELF

Type of this instance, automatically specialized in every class
redef fun close

core $ FileStream :: close

close the stream

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 fd: Int

core :: FileStream :: fd

File descriptor of this file
fun file_stat: nullable FileStat

core :: FileStream :: file_stat

The status of a file. see POSIX stat(2).
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 path: nullable String

core :: FileStream :: path

The path of the file.
protected fun path=(path: nullable String)

core :: FileStream :: path=

The path of the file.
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun set_buffering_mode(buf_size: Int, mode: Int)

core :: FileStream :: set_buffering_mode

Sets the buffering mode for the current FileStream
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::FileStream FileStream core::Stream Stream core::FileStream->core::Stream core::Object Object core::Stream->core::Object ...core::Object ... ...core::Object->core::Object core::FileReader FileReader core::FileReader->core::FileStream core::FileWriter FileWriter core::FileWriter->core::FileStream core::Stdin Stdin core::Stdin->core::FileReader core::Stdin... ... core::Stdin...->core::Stdin core::Stdout Stdout core::Stdout->core::FileWriter core::Stderr Stderr core::Stderr->core::FileWriter core::Stdout... ... core::Stdout...->core::Stdout core::Stderr... ... core::Stderr...->core::Stderr

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

abstract class Stream

core :: Stream

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

Children

class FileReader

core :: FileReader

Stream that can read from a File
class FileWriter

core :: FileWriter

Stream that can write to a File

Descendants

class Stderr

core :: Stderr

Standard error stream.
class Stdin

core :: Stdin

Standard input stream.
class Stdout

core :: Stdout

Standard output stream.

Class definitions

core $ FileStream
# `Stream` used to interact with a File or FileDescriptor
abstract class FileStream
	super Stream
	# The path of the file.
	var path: nullable String = null

	# The FILE *.
	private var file: nullable NativeFile = null

	# The status of a file. see POSIX stat(2).
	#
	#     var f = new FileReader.open("/etc/issue")
	#     assert f.file_stat.is_file
	#
	# Return null in case of error
	fun file_stat: nullable FileStat
	do
		var stat = _file.as(not null).file_stat
		if stat.address_is_null then return null
		return new FileStat(stat)
	end

	# File descriptor of this file
	fun fd: Int do return _file.as(not null).fileno

	redef fun close
	do
		var file = _file
		if file == null then return
		if file.address_is_null then
			if last_error != null then return
			last_error = new IOError("Cannot close unopened file")
			return
		end
		var i = file.io_close
		if i != 0 then
			last_error = new IOError("Close failed due to error {sys.errno.strerror}")
		end
		_file = null
	end

	# Sets the buffering mode for the current FileStream
	#
	# If the buf_size is <= 0, its value will be 512 by default
	#
	# The mode is any of the buffer_mode enumeration in `Sys`:
	#
	# * `buffer_mode_full`
	# * `buffer_mode_line`
	# * `buffer_mode_none`
	fun set_buffering_mode(buf_size, mode: Int) do
		if buf_size <= 0 then buf_size = 512
		if _file.as(not null).set_buffering_type(buf_size, mode) != 0 then
			last_error = new IOError("Error while changing buffering type for FileStream, returned error {sys.errno.strerror}")
		end
	end
end
lib/core/file.nit:43,1--99,3