System.IO
Class BinaryReader

java.lang.Object
  extended by System.IO.BinaryReader
All Implemented Interfaces:
IDisposable
Direct Known Subclasses:
PacketReader

public class BinaryReader
extends java.lang.Object
implements IDisposable

Reads primitive data types as binary values in a specific encoding.

Author:
Halofreak1990

Constructor Summary
BinaryReader(Stream input)
          Initializes a new instance of the BinaryReader class based on the supplied stream and using UTF-8 encoding.
BinaryReader(Stream input, java.lang.String encoding)
          Initializes a new instance of the BinaryReader class based on the supplied stream and a specific character encoding.
 
Method Summary
 void Close()
          Closes the current reader and the underlying stream.
 void Dispose()
          Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
protected  void Dispose(boolean disposing)
          Releases the unmanaged resources used by the BinaryReader and optionally releases the managed resources.
protected  void FillBuffer(int numBytes)
          Fills the internal buffer with the specified number of bytes read from the stream.
 Stream getBaseStream()
           
 int PeekChar()
           
 int Read()
          Reads characters from the underlying stream and advances the current position of the stream in accordance with the Encoding used and the specific character being read from the stream.
 int Read(byte[] buffer, int index, int count)
           
 int Read(char[] buffer, int index, int count)
           
protected  int Read7BitEncodedInt()
           
 boolean ReadBoolean()
          Reads a Boolean value from the current stream and advances the current position of the stream by one byte.
 byte ReadByte()
           
 byte[] ReadBytes(int count)
           
 char ReadChar()
           
 char[] ReadChars(int count)
           
 double ReadDouble()
           
 short ReadInt16()
           
 int ReadInt32()
           
 long ReadInt64()
           
 float ReadSingle()
           
 java.lang.String ReadString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinaryReader

public BinaryReader(Stream input)
Initializes a new instance of the BinaryReader class based on the supplied stream and using UTF-8 encoding.

Parameters:
input - A stream.
Throws:
ArgumentException - The stream does not support reading, the stream is null, or the stream is already closed.

BinaryReader

public BinaryReader(Stream input,
                    java.lang.String encoding)
Initializes a new instance of the BinaryReader class based on the supplied stream and a specific character encoding.

Parameters:
input - The supplied stream.
encoding - The character encoding.
Throws:
ArgumentNullException - input, or encoding is null.
ArgumentException - The stream does not support reading, or the stream is already closed.
Method Detail

getBaseStream

public Stream getBaseStream()

Close

public void Close()
Closes the current reader and the underlying stream.


Dispose

public void Dispose()
Description copied from interface: IDisposable
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

Specified by:
Dispose in interface IDisposable

Dispose

protected void Dispose(boolean disposing)
Releases the unmanaged resources used by the BinaryReader and optionally releases the managed resources.

Parameters:
disposing - true to release both managed and unmanaged resources; false to release only unmanaged resources.

FillBuffer

protected void FillBuffer(int numBytes)
Fills the internal buffer with the specified number of bytes read from the stream.

Parameters:
numBytes - The number of bytes to be read.
Throws:
EndOfStreamException - The end of the stream is reached before numBytes could be read.
IOException - An I/O error occurs.

PeekChar

public int PeekChar()
Returns:
Throws:
IOException - An I/O error occurs.

Read

public int Read()
Reads characters from the underlying stream and advances the current position of the stream in accordance with the Encoding used and the specific character being read from the stream.

Returns:
The next character from the input stream, or -1 if no characters are currently available.
Throws:
ObjectDisposedException - The stream is closed.
IOException - An I/O error occurs.

Read

public int Read(byte[] buffer,
                int index,
                int count)

Read

public int Read(char[] buffer,
                int index,
                int count)
Parameters:
buffer -
index -
count -
Returns:

Read7BitEncodedInt

protected int Read7BitEncodedInt()

ReadBoolean

public boolean ReadBoolean()
Reads a Boolean value from the current stream and advances the current position of the stream by one byte.

Returns:
true if the byte is nonzero; otherwise, false.
Throws:
ObjectDisposedException - The stream is closed.
IOException - An I/O error occurs.
EndOfStreamException - The end of the stream is reached.

ReadByte

public byte ReadByte()

ReadBytes

public byte[] ReadBytes(int count)

ReadChar

public char ReadChar()

ReadChars

public char[] ReadChars(int count)

ReadDouble

public double ReadDouble()

ReadInt16

public short ReadInt16()

ReadInt32

public int ReadInt32()

ReadInt64

public long ReadInt64()

ReadSingle

public float ReadSingle()

ReadString

public java.lang.String ReadString()