class · System.IO

HandleStream

public class HandleStream : Stream

A file the runtime has open, by handle (0, 1 and 2 are the console's input, output and error): no buffer of its own.

Tipo
class
Espacio de nombres
System.IO
Ensamblado
System.Core
Acceso
public
Archivo fuente
Stream.ant

Herencia

Clases base
Any Stream HandleStream
Tipos derivados
NetworkStream

Constructores

new(i64 handle, str name, bool reads, bool writes)
#

A stream that cannot seek (the console, a pipe, a socket).

new(i64 handle, str name, bool reads, bool writes, bool seeks)
#

Propiedades

override bool CanRead { get; }
#

read-only

override bool CanWrite { get; }
#

read-only

override bool CanSeek { get; }
#

read-only

override i64 Length { get; }
#

read-only

override i64 Position { get; set; }
#

Métodos

override Read(u8[] buffer, i32 offset, i32 count) : i32
#

override

override Write(u8[] buffer, i32 offset, i32 count)
#

override

override Seek(i64 offset, SeekOrigin origin) : i64
#

override

override Flush()
#

override

override Close()
#

override

Miembros privados e internos (12)

i64 handle
#

private

str name
#

private

bool reads
#

private

bool writes
#

private

bool seeks
#

private

Whether the handle is a file (a position to move): the console, a pipe and a socket are not.

static extern("stream.close") CloseHandle(i64 handle) : i64
#

private static

static extern("stream.read") ReadRange(i64 handle, u8[] bytes, i64 offset, i64 count) : i64
#

private static

static extern("stream.write") WriteRange(i64 handle, u8[] bytes, i64 offset, i64 count) : i64
#

private static

static extern("stream.seek") SeekTo(i64 handle, i64 offset, i64 origin) : i64
#

private static

static extern("stream.length") LengthOf(i64 handle) : i64
#

private static

static extern("stream.flush") FlushHandle(i64 handle) : i64
#

private static

Check()
#

private

Miembros heredados (14)

Código fuente

HandleStream en Antril, descompilado a partir de su Larva HIR.

System.IO.HandleStream.ant
// System.IO.HandleStream — System.Core (decompiled from Larva HIR)

import System;

into namespace System.IO
{
	/// A file the runtime has open, by handle (0, 1 and 2 are the console's input, output and error): no buffer of its own.
	public class HandleStream : Stream
	{
		i64 handle;
		str name;
		bool reads;
		bool writes;

		/// Whether the handle is a file (a position to move): the console, a pipe and a socket are not.
		bool seeks;

		static extern("stream.close") CloseHandle(i64 handle) : i64;

		static extern("stream.read") ReadRange(i64 handle, u8[] bytes, i64 offset, i64 count) : i64;

		static extern("stream.write") WriteRange(i64 handle, u8[] bytes, i64 offset, i64 count) : i64;

		static extern("stream.seek") SeekTo(i64 handle, i64 offset, i64 origin) : i64;

		static extern("stream.length") LengthOf(i64 handle) : i64;

		static extern("stream.flush") FlushHandle(i64 handle) : i64;

		Check()
		{
			if (handle < 0)
				throw new IOError("the stream is closed: " + name);
		}

		public:
			/// A stream that cannot seek (the console, a pipe, a socket).
			new(i64 handle, str name, bool reads, bool writes) : (handle, name, reads, writes, false)
			{
			}

			new(i64 handle, str name, bool reads, bool writes, bool seeks)
			{
				this.handle = handle;
				this.name = name;
				this.reads = reads;
				this.writes = writes;
				this.seeks = seeks;
			}

			override Read(u8[] buffer, i32 offset, i32 count) : i32
			{
				Check();
				if (offset < 0 || count < 0 || offset + count > buffer.Length)
					throw new ArgumentError("Stream.Read: the range is outside the buffer");
				i64 read = ReadRange(handle, buffer, offset, count);
				if (read < 0)
					throw new IOError("cannot read " + name);
				return (i32)read;
			}

			override Write(u8[] buffer, i32 offset, i32 count)
			{
				Check();
				if (offset < 0 || count < 0 || offset + count > buffer.Length)
					throw new ArgumentError("Stream.Write: the range is outside the buffer");
				if (WriteRange(handle, buffer, offset, count) != count)
					throw new IOError("cannot write " + name);
			}

			override Seek(i64 offset, SeekOrigin origin) : i64
			{
				Check();
				if (!seeks)
					throw new IOError("the stream cannot seek: " + name);
				i64 at = SeekTo(handle, offset, origin == SeekOrigin.Begin ? 0 : origin == SeekOrigin.Current ? 1 : 2);
				if (at < 0)
					throw new IOError("cannot seek in " + name);
				return at;
			}

			override Flush()
			{
				Check();
				FlushHandle(handle);
			}

			override Close()
			{
				if (handle >= 3)
					CloseHandle(handle);
				else if (handle >= 0)
					FlushHandle(handle);
				handle = -1;
			}

			override bool CanRead
			{
				get => handle >= 0 && reads;
			}

			override bool CanWrite
			{
				get => handle >= 0 && writes;
			}

			override bool CanSeek
			{
				get => handle >= 0 && seeks;
			}

			override i64 Length
			{
				get
				{
					Check();
					i64 length = LengthOf(handle);
					if (length < 0)
						throw new IOError("the stream has no length: " + name);
					return length;
				}
			}

			override i64 Position
			{
				get => Seek(0, SeekOrigin.Current);
				set
				{
					Seek(value, SeekOrigin.Begin);
				}
			}
	}
}
Esc