[271] | 1 | Namespace System
|
---|
| 2 | Namespace IO
|
---|
[111] | 3 |
|
---|
[112] | 4 | Class Stream
|
---|
[605] | 5 | Implements IDisposable
|
---|
[347] | 6 |
|
---|
[605] | 7 | Protected
|
---|
[468] | 8 | Sub Stream()
|
---|
| 9 | End Sub
|
---|
[114] | 10 | Public
|
---|
[605] | 11 | Sub ~Stream()
|
---|
[388] | 12 | This.Dispose(False)
|
---|
[119] | 13 | End Sub
|
---|
| 14 | Public
|
---|
| 15 | Abstract Function CanRead() As Boolean
|
---|
| 16 | Abstract Function CanSeek() As Boolean
|
---|
[111] | 17 |
|
---|
[119] | 18 | Virtual Function CanTimeout() As Boolean
|
---|
[605] | 19 | Return False
|
---|
[119] | 20 | End Function
|
---|
| 21 |
|
---|
| 22 | Abstract Function CanWrite() As Boolean
|
---|
[605] | 23 | Abstract Function Length() As QWord
|
---|
| 24 | Abstract Sub Position(value As QWord)
|
---|
| 25 | Abstract Function Position() As QWord
|
---|
[119] | 26 |
|
---|
| 27 | Virtual Sub ReadTimeout(value As Long)
|
---|
[605] | 28 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
---|
[119] | 29 | End Sub
|
---|
| 30 |
|
---|
| 31 | Virtual Function ReadTimeout() As Long
|
---|
[605] | 32 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
---|
[119] | 33 | End Function
|
---|
| 34 |
|
---|
| 35 | Virtual Sub WriteTimeout(value As Long)
|
---|
[605] | 36 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
---|
[119] | 37 | End Sub
|
---|
| 38 |
|
---|
| 39 | Virtual Function WriteTimeout() As Long
|
---|
[605] | 40 | Throw New InvalidOperationException("Stream does not support Timeout.")
|
---|
[119] | 41 | End Function
|
---|
| 42 |
|
---|
[112] | 43 | Public
|
---|
[347] | 44 | Virtual Function BeginRead(buffer As *Byte, offset As Long, count As Long, callback As AsyncCallback, state As Object) As System.IAsyncResult
|
---|
[605] | 45 | Dim r = Read(buffer,offset,count)
|
---|
| 46 | Return New Detail.SyncStreamResultImpl(r, state)
|
---|
[347] | 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)
|
---|
[605] | 50 | Return New Detail.SyncStreamResultImpl(0, state)
|
---|
[347] | 51 | End Function
|
---|
[432] | 52 | Sub Close()
|
---|
[388] | 53 | Dispose(True)
|
---|
[347] | 54 | End Sub
|
---|
[432] | 55 | Sub Dispose()
|
---|
[388] | 56 | Dispose(True)
|
---|
| 57 | End Sub
|
---|
[568] | 58 | Virtual Function EndRead(asyncResult As System.IAsyncResult) As Long
|
---|
[605] | 59 | Dim ar = asyncResult As Detail.IAsyncStreamResult
|
---|
| 60 | EndRead = ar.WaitAndGetResult
|
---|
[468] | 61 | End Function
|
---|
[568] | 62 | Virtual Sub EndWrite(asyncResult As System.IAsyncResult)
|
---|
[468] | 63 | End Sub
|
---|
[119] | 64 | Abstract Sub Flush()
|
---|
[337] | 65 | Abstract Function Read(buffer As *Byte, offset As Long, count As Long) As Long
|
---|
[112] | 66 |
|
---|
[119] | 67 | Virtual Function ReadByte() As Long
|
---|
| 68 | Dim b As Byte
|
---|
[337] | 69 | Dim ret = Read(VarPtr(b), 0, 1)
|
---|
[119] | 70 | If ret <> 0 Then
|
---|
| 71 | Return b
|
---|
| 72 | Else
|
---|
| 73 | Return -1
|
---|
| 74 | End If
|
---|
| 75 | End Function
|
---|
| 76 |
|
---|
[391] | 77 | Abstract Function Seek(offset As Int64, origin As SeekOrigin) As Int64
|
---|
[605] | 78 | Abstract Sub SetLength(value As QWord)
|
---|
[337] | 79 | Abstract Sub Write(buffer As *Byte, offset As Long, count As Long)
|
---|
[119] | 80 | Virtual Sub WriteByte(b As Byte)
|
---|
[337] | 81 | Write(VarPtr(b), 0, 1)
|
---|
[119] | 82 | End Sub
|
---|
[609] | 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
|
---|
[112] | 91 | Protected
|
---|
[432] | 92 | Virtual Sub Dispose(disposing As Boolean)
|
---|
| 93 | End Sub
|
---|
[609] | 94 |
|
---|
| 95 | Private
|
---|
| 96 | Static null = Nothing As Stream
|
---|
[112] | 97 | End Class
|
---|
[271] | 98 |
|
---|
[609] | 99 | Namespace Detail
|
---|
[271] | 100 |
|
---|
[609] | 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 |
|
---|
[682] | 157 | /*!
|
---|
| 158 | @brief 書き込みバイト数を記憶するヌルストリーム
|
---|
| 159 | Encoding関連で使用
|
---|
| 160 | @date 2009/02/16
|
---|
| 161 | @auther Egtra
|
---|
| 162 | */
|
---|
| 163 | Class WriteCountingNullStream
|
---|
| 164 | Inherits NullStream
|
---|
| 165 | Public
|
---|
| 166 | Sub WriteCountingNullStream()
|
---|
| 167 | writeCount = 0
|
---|
| 168 | End Sub
|
---|
| 169 |
|
---|
| 170 | Override Sub Write(buffer As *Byte, offset As Long, count As Long)
|
---|
| 171 | If count < 0 Then
|
---|
| 172 | Throw New ArgumentOutOfRangeException("count")
|
---|
| 173 | End If
|
---|
| 174 | writeCount += count
|
---|
| 175 | End Sub
|
---|
| 176 |
|
---|
| 177 | Override Sub WriteByte(b As Byte)
|
---|
| 178 | writeCount++
|
---|
| 179 | End Sub
|
---|
| 180 |
|
---|
| 181 | /*!
|
---|
| 182 | @brief 書き込まれたバイト数を返す。
|
---|
| 183 | */
|
---|
| 184 | Function WriteCount() As Long
|
---|
| 185 | WriteCount = writeCount
|
---|
| 186 | End Function
|
---|
| 187 |
|
---|
| 188 | Private
|
---|
| 189 | writeCount As Long
|
---|
| 190 | End Class
|
---|
| 191 |
|
---|
[271] | 192 | End Namespace
|
---|
[609] | 193 |
|
---|
[271] | 194 | End Namespace
|
---|
[609] | 195 | End Namespace
|
---|