Imports System.IO
Namespace IO
Public Class DataReader
Inherits BinaryReader
#Region "New"
Sub New(ByVal input As Stream)
MyBase.New(input)
End Sub
Sub New(ByVal input As Stream, ByVal encoding As System.Text.Encoding)
MyBase.New(input, encoding)
End Sub
#End Region
#Region "Function"
Public Function readUnsignedByte()
Return ReadByte()
End Function
Public Overrides Function ReadByte() As Byte
Return MyBase.ReadByte()
End Function
Public Function readVarInt()
Return ReadUInt16()
End Function
Public Overrides Function ReadUInt16() As UShort
Return (CUShort(ReadByte()) << 8) + ReadByte()
End Function
Public Overrides Function ReadBoolean() As Boolean
Return ReadByte() = 1
End Function
Public Function ReadShort()
Return ReadInt16()
End Function
Public Overrides Function ReadInt16() As Short
Dim Value As UShort = ReadUInt16()
If Value > Short.MaxValue Then
Dim Value2 As Short = -(UShort.MaxValue - Value) - 1
Return Value2
End If
Return Value
End Function
Public Function ReadInt()
Return ReadInt32()
End Function
Public Overrides Function ReadInt32() As Integer
Dim Value As UInteger = ReadUInt32()
If Value > Integer.MaxValue Then
Dim Value2 As Integer = -(UInteger.MaxValue - Value) - 1
Return Value2
End If
Return Value
End Function
Public Overrides Function ReadUInt32() As UInteger
Return (CUInt(ReadByte()) << 24) + (CUInt(ReadByte()) << 16) + (CUInt(ReadByte()) << 8) + ReadByte()
End Function
Public Overrides Function ReadDouble() As Double
Dim Bytes() As Byte = ReadBytes(8)
Array.Reverse(Bytes)
Return BitConverter.ToDouble(Bytes, 0)
End Function
Public Function ReadUTF()
Return ReadString()
End Function
Public Overrides Function ReadString() As String
Dim ByteArray() As Byte = MyBase.ReadBytes(ReadUInt16())
Return System.Text.Encoding.UTF8.GetString(ByteArray)
End Function
#End Region
End Class
End Namespace