Namespace System
Namespace IO


Class Stream
	Implements System.IDisposable

Public 'Protected
	Sub Stream()
	End Sub
Public
	Virtual Sub ~Stream()
		This.Dispose(False)
	End Sub
Public
	Abstract Function CanRead() As Boolean
	Abstract Function CanSeek() As Boolean

	Virtual Function CanTimeout() As Boolean
		Return True
	End Function

	Abstract Function CanWrite() As Boolean
	Abstract Function Length() As Int64
	Abstract Sub Position(value As Int64)
	Abstract Function Position() As Int64

	Virtual Sub ReadTimeout(value As Long)
		' Throw InvalidOperationException
	End Sub

	Virtual Function ReadTimeout() As Long
		' Throw InvalidOperationException
	End Function

	Virtual Sub WriteTimeout(value As Long)
		' Throw InvalidOperationException
	End Sub

	Virtual Function WriteTimeout() As Long
		' Throw InvalidOperationException
	End Function

Public
	Virtual Function BeginRead(buffer As *Byte, offset As Long, count As Long, callback As AsyncCallback, state As Object) As System.IAsyncResult
		Read(buffer,offset,count)
	End Function
	Virtual Function BeginWrite(buffer As *Byte, offset As Long, count As Long, callback As AsyncCallback, state As Object) As System.IAsyncResult
		Write(buffer,offset,count)
	End Function
	Sub Close()
		Dispose(True)
	End Sub
	Sub Dispose()
		Dispose(True)
	End Sub
	Virtual Function EndRead(ByRef asyncResult As System.IAsyncResult) As Long
	End Function
	Virtual Sub EndWrite(ByRef asyncResult As System.IAsyncResult)
	End Sub
	Abstract Sub Flush()
	Abstract Function Read(buffer As *Byte, offset As Long, count As Long) As Long

	Virtual Function ReadByte() As Long
		Dim b As Byte
		Dim ret = Read(VarPtr(b), 0, 1)
		If ret <> 0 Then
			Return b
		Else
			Return -1
		End If
	End Function

	Abstract Function Seek(offset As Int64, origin As SeekOrigin) As Int64
	Abstract Sub SetLength(value As Int64)
	Abstract Sub Write(buffer As *Byte, offset As Long, count As Long)
	Virtual Sub WriteByte(b As Byte)
		Write(VarPtr(b), 0, 1)
	End Sub
Protected
	Virtual Sub Dispose(disposing As Boolean)
	End Sub
	Virtual Function CreateWaitHandle() As System.Threading.WaitHandle
	End Function
End Class


End Namespace
End Namespace
