| 1 | Namespace System
|
|---|
| 2 | Namespace IO
|
|---|
| 3 |
|
|---|
| 4 | Class Stream
|
|---|
| 5 | Implements IDisposable
|
|---|
| 6 |
|
|---|
| 7 | Protected
|
|---|
| 8 | Sub Stream()
|
|---|
| 9 | End Sub
|
|---|
| 10 | Public
|
|---|
| 11 | Sub ~Stream()
|
|---|
| 12 | This.Dispose(False)
|
|---|
| 13 | End Sub
|
|---|
| 14 | Public
|
|---|
| 15 | Abstract Function CanRead() As Boolean
|
|---|
| 16 | Abstract Function CanSeek() As Boolean
|
|---|
| 17 |
|
|---|
| 18 | Virtual Function CanTimeout() As Boolean
|
|---|
| 19 | Return False
|
|---|
| 20 | End Function
|
|---|
| 21 |
|
|---|
| 22 | Abstract Function CanWrite() As Boolean
|
|---|
| 23 | Abstract Function Length() As QWord
|
|---|
| 24 | Abstract Sub Position(value As QWord)
|
|---|
| 25 | Abstract Function Position() As QWord
|
|---|
| 26 |
|
|---|
| 27 | Virtual Sub ReadTimeout(value As Long)
|
|---|
| 28 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
|---|
| 29 | End Sub
|
|---|
| 30 |
|
|---|
| 31 | Virtual Function ReadTimeout() As Long
|
|---|
| 32 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
|---|
| 33 | End Function
|
|---|
| 34 |
|
|---|
| 35 | Virtual Sub WriteTimeout(value As Long)
|
|---|
| 36 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
|---|
| 37 | End Sub
|
|---|
| 38 |
|
|---|
| 39 | Virtual Function WriteTimeout() As Long
|
|---|
| 40 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
|---|
| 41 | End Function
|
|---|
| 42 |
|
|---|
| 43 | Public
|
|---|
| 44 | Virtual Function BeginRead(buffer As *Byte, offset As Long, count As Long, callback As AsyncCallback, state As Object) As System.IAsyncResult
|
|---|
| 45 | Dim r = Read(buffer,offset,count)
|
|---|
| 46 | Return New Detail.SyncStreamResultImpl(r, state)
|
|---|
| 47 | End Function
|
|---|
| 48 | Virtual Function BeginWrite(buffer As *Byte, offset As Long, count As Long, callback As AsyncCallback, state As Object) As System.IAsyncResult
|
|---|
| 49 | Write(buffer,offset,count)
|
|---|
| 50 | Return New Detail.SyncStreamResultImpl(0, state)
|
|---|
| 51 | End Function
|
|---|
| 52 | Sub Close()
|
|---|
| 53 | Dispose(True)
|
|---|
| 54 | End Sub
|
|---|
| 55 | Sub Dispose()
|
|---|
| 56 | Dispose(True)
|
|---|
| 57 | End Sub
|
|---|
| 58 | Virtual Function EndRead(asyncResult As System.IAsyncResult) As Long
|
|---|
| 59 | Dim ar = asyncResult As Detail.IAsyncStreamResult
|
|---|
| 60 | EndRead = ar.WaitAndGetResult
|
|---|
| 61 | End Function
|
|---|
| 62 | Virtual Sub EndWrite(asyncResult As System.IAsyncResult)
|
|---|
| 63 | End Sub
|
|---|
| 64 | Abstract Sub Flush()
|
|---|
| 65 | Abstract Function Read(buffer As *Byte, offset As Long, count As Long) As Long
|
|---|
| 66 |
|
|---|
| 67 | Virtual Function ReadByte() As Long
|
|---|
| 68 | Dim b As Byte
|
|---|
| 69 | Dim ret = Read(VarPtr(b), 0, 1)
|
|---|
| 70 | If ret <> 0 Then
|
|---|
| 71 | Return b
|
|---|
| 72 | Else
|
|---|
| 73 | Return -1
|
|---|
| 74 | End If
|
|---|
| 75 | End Function
|
|---|
| 76 |
|
|---|
| 77 | Abstract Function Seek(offset As Int64, origin As SeekOrigin) As Int64
|
|---|
| 78 | Abstract Sub SetLength(value As QWord)
|
|---|
| 79 | Abstract Sub Write(buffer As *Byte, offset As Long, count As Long)
|
|---|
| 80 | Virtual Sub WriteByte(b As Byte)
|
|---|
| 81 | Write(VarPtr(b), 0, 1)
|
|---|
| 82 | End Sub
|
|---|
| 83 |
|
|---|
| 84 | Static Function Null() As Stream
|
|---|
| 85 | '(Constではなく)読み取り専用にはこうするしかないはず。
|
|---|
| 86 | If ActiveBasic.IsNothing(null) Then
|
|---|
| 87 | null = New Detail.NullStream
|
|---|
| 88 | End If
|
|---|
| 89 | Null = null
|
|---|
| 90 | End Function
|
|---|
| 91 | Protected
|
|---|
| 92 | Virtual Sub Dispose(disposing As Boolean)
|
|---|
| 93 | End Sub
|
|---|
| 94 |
|
|---|
| 95 | Private
|
|---|
| 96 | Static null = Nothing As Stream
|
|---|
| 97 | End Class
|
|---|
| 98 |
|
|---|
| 99 | Namespace Detail
|
|---|
| 100 |
|
|---|
| 101 | /*!
|
|---|
| 102 | @brief ヌルストリーム
|
|---|
| 103 | @date 2008/08/21
|
|---|
| 104 | @auther Egtra
|
|---|
| 105 | */
|
|---|
| 106 | Class NullStream
|
|---|
| 107 | Inherits Stream
|
|---|
| 108 | Public
|
|---|
| 109 | Override Function CanRead() As Boolean
|
|---|
| 110 | CanRead = True
|
|---|
| 111 | End Function
|
|---|
| 112 |
|
|---|
| 113 | Override Function Read(buffer As *Byte, offset As Long, count As Long) As Long
|
|---|
| 114 | Read = 0
|
|---|
| 115 | End Function
|
|---|
| 116 |
|
|---|
| 117 | Override Function ReadByte() As Long
|
|---|
| 118 | ReadByte = -1
|
|---|
| 119 | End Function
|
|---|
| 120 |
|
|---|
| 121 | Override Function CanWrite() As Boolean
|
|---|
| 122 | CanWrite = True
|
|---|
| 123 | End Function
|
|---|
| 124 |
|
|---|
| 125 | Override Sub Write(buffer As *Byte, offset As Long, count As Long)
|
|---|
| 126 | End Sub
|
|---|
| 127 |
|
|---|
| 128 | Override Sub WriteByte(b As Byte)
|
|---|
| 129 | End Sub
|
|---|
| 130 |
|
|---|
| 131 | Override Sub Flush()
|
|---|
| 132 | End Sub
|
|---|
| 133 |
|
|---|
| 134 | Override Function CanSeek() As Boolean
|
|---|
| 135 | CanSeek = True
|
|---|
| 136 | End Function
|
|---|
| 137 |
|
|---|
| 138 | Override Function Length() As QWord
|
|---|
| 139 | Length = 0
|
|---|
| 140 | End Function
|
|---|
| 141 |
|
|---|
| 142 | Override Sub Position(value As QWord)
|
|---|
| 143 | End Sub
|
|---|
| 144 |
|
|---|
| 145 | Override Function Position() As QWord
|
|---|
| 146 | Position = 0
|
|---|
| 147 | End Function
|
|---|
| 148 |
|
|---|
| 149 | Override Function Seek(offset As Int64, origin As SeekOrigin) As Int64
|
|---|
| 150 | Seek = 0
|
|---|
| 151 | End Function
|
|---|
| 152 |
|
|---|
| 153 | Override Sub SetLength(value As QWord)
|
|---|
| 154 | End Sub
|
|---|
| 155 | End Class
|
|---|
| 156 |
|
|---|
| 157 | End Namespace
|
|---|
| 158 |
|
|---|
| 159 | End Namespace
|
|---|
| 160 | End Namespace
|
|---|