Class RandomAccessFileOrArray
Class that is used to unify reading from random access files and arrays.
public class RandomAccessFileOrArray
- Inheritance
-
RandomAccessFileOrArray
- Inherited Members
Constructors
RandomAccessFileOrArray(IRandomAccessSource)
Creates a RandomAccessFileOrArray that wraps the specified byte source.
public RandomAccessFileOrArray(IRandomAccessSource byteSource)
Parameters
byteSource
IRandomAccessSourcethe byte source to wrap
Remarks
Creates a RandomAccessFileOrArray that wraps the specified byte source. The byte source will be closed when this RandomAccessFileOrArray is closed.
Fields
plainRandomAccess
When true the file access is not done through a memory mapped file.
public static bool plainRandomAccess
Field Value
Remarks
When true the file access is not done through a memory mapped file. Use it if the file is too big to be mapped in your address space.
Methods
Close()
Closes the underlying source.
public virtual void Close()
CreateSourceView()
Creates the view of the byte source of this object.
public virtual IRandomAccessSource CreateSourceView()
Returns
- IRandomAccessSource
the byte source view.
Remarks
Creates the view of the byte source of this object. Closing the view won't affect this object. Closing source will have adverse effect on the view.
CreateView()
Creates an independent view of this object (with it's own file pointer and push back queue).
public virtual RandomAccessFileOrArray CreateView()
Returns
- RandomAccessFileOrArray
the new view
Remarks
Creates an independent view of this object (with it's own file pointer and push back queue). Closing the new object will not close this object. Closing this object will have adverse effect on the view.
GetPosition()
Gets the current position of the source considering the pushed byte to the source.
public virtual long GetPosition()
Returns
- long
the index of last read byte in the source in or the index of last read byte in source - 1 in case byte was pushed.
Length()
Gets the total amount of bytes in the source.
public virtual long Length()
Returns
- long
source's size.
PushBack(byte)
Pushes a byte back.
public virtual void PushBack(byte b)
Parameters
b
bytethe byte to push
Remarks
Pushes a byte back. The next get() will return this byte instead of the value from the underlying data source
Read()
Reads a single byte
public virtual int Read()
Returns
- int
the byte, or -1 if EOF is reached
Read(byte[])
Reads the bytes to the buffer.
public virtual int Read(byte[] b)
Parameters
b
byte[]the destination buffer
Returns
- int
the number of bytes actually read
Remarks
Reads the bytes to the buffer. This method will try to read as many bytes as the buffer can hold.
Read(byte[], int, int)
Reads the specified amount of bytes to the buffer applying the offset.
public virtual int Read(byte[] b, int off, int len)
Parameters
b
byte[]destination buffer
off
intoffset at which to start storing characters
len
intmaximum number of characters to read
Returns
- int
the number of bytes actually read or -1 in case of EOF
ReadBoolean()
public virtual bool ReadBoolean()
Returns
ReadByte()
public virtual byte ReadByte()
Returns
ReadChar()
public virtual char ReadChar()
Returns
ReadCharLE()
Reads a Unicode character from this stream in little-endian order.
public char ReadCharLE()
Returns
- char
the next two bytes of this stream as a Unicode character.
Remarks
Reads a Unicode character from this stream in little-endian order.
This method reads two
bytes from the stream, starting at the current stream pointer.
If the bytes read, in order, are
b1
and
b2
, where
0 <= b1, b2 <= 255
,
then the result is equal to:
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.(char)((b2 << 8) | b1)
ReadDouble()
public virtual double ReadDouble()
Returns
ReadDoubleLE()
public double ReadDoubleLE()
Returns
ReadFloat()
public virtual float ReadFloat()
Returns
ReadFloatLE()
public float ReadFloatLE()
Returns
ReadFully(byte[])
public virtual void ReadFully(byte[] b)
Parameters
b
byte[]
ReadFully(byte[], int, int)
public virtual void ReadFully(byte[] b, int off, int len)
Parameters
ReadInt()
public virtual int ReadInt()
Returns
ReadIntLE()
Reads a signed 32-bit integer from this stream in little-endian order.
public int ReadIntLE()
Returns
- int
the next four bytes of this stream, interpreted as an
int
.
Remarks
Reads a signed 32-bit integer from this stream in little-endian order.
This method reads 4
bytes from the stream, starting at the current stream pointer.
If the bytes read, in order, are
b1
,
b2
,
b3
, and
b4
, where
0 <= b1, b2, b3, b4 <= 255
,
then the result is equal to:
This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.(b4 << 24) | (b3 << 16) + (b2 << 8) + b1
ReadLine()
public virtual string ReadLine()
Returns
ReadLong()
public virtual long ReadLong()
Returns
ReadLongLE()
public long ReadLongLE()
Returns
ReadShort()
public virtual short ReadShort()
Returns
ReadShortLE()
Reads a signed 16-bit number from this stream in little-endian order.
public short ReadShortLE()
Returns
- short
the next two bytes of this stream, interpreted as a signed 16-bit number.
Remarks
Reads a signed 16-bit number from this stream in little-endian order.
The method reads two
bytes from this stream, starting at the current stream pointer.
If the two bytes read, in order, are
b1
and
b2
, where each of the two values is
between
0
and
255
, inclusive, then the
result is equal to:
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.(short)((b2 << 8) | b1)
ReadString(int, string)
Reads a
String
from the font file as bytes using the given encoding.
public virtual string ReadString(int length, string encoding)
Parameters
Returns
- string
the
String
read
ReadUnsignedByte()
public virtual int ReadUnsignedByte()
Returns
ReadUnsignedInt()
Reads an unsigned 32-bit integer from this stream.
public long ReadUnsignedInt()
Returns
- long
the next four bytes of this stream, interpreted as a
long
.
Remarks
Reads an unsigned 32-bit integer from this stream. This method reads 4
bytes from the stream, starting at the current stream pointer.
If the bytes read, in order, are
b1
,
b2
,
b3
, and
b4
, where
0 <= b1, b2, b3, b4 <= 255
,
then the result is equal to:
This method blocks until the four bytes are read, the end of the stream is detected, or an exception is thrown.(b1 << 24) | (b2 << 16) + (b3 << 8) + b4
ReadUnsignedIntLE()
public long ReadUnsignedIntLE()
Returns
ReadUnsignedShort()
public virtual int ReadUnsignedShort()
Returns
ReadUnsignedShortLE()
Reads an unsigned 16-bit number from this stream in little-endian order.
public int ReadUnsignedShortLE()
Returns
- int
the next two bytes of this stream, interpreted as an unsigned 16-bit integer.
Remarks
Reads an unsigned 16-bit number from this stream in little-endian order.
This method reads
two bytes from the stream, starting at the current stream pointer.
If the bytes read, in order, are
b1
and
b2
, where
0 <= b1, b2 <= 255
,
then the result is equal to:
This method blocks until the two bytes are read, the end of the stream is detected, or an exception is thrown.(b2 << 8) | b1
Seek(long)
Sets the current position in the source to the specified index.
public virtual void Seek(long pos)
Parameters
pos
longthe position to set
Skip(long)
Make an attempt to skip the specified amount of bytes in source.
public virtual long Skip(long n)
Parameters
n
longthe number of bytes to skip
Returns
- long
the actual number of bytes skipped
Remarks
Make an attempt to skip the specified amount of bytes in source. However it may skip less amount of bytes. Possibly zero.
SkipBytes(int)
public virtual int SkipBytes(int n)
Parameters
n
int