net.wimpi.modbus.io
Class BytesInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by net.wimpi.modbus.io.FastByteArrayInputStream
          extended by net.wimpi.modbus.io.BytesInputStream
All Implemented Interfaces:
Closeable, DataInput

public class BytesInputStream
extends FastByteArrayInputStream
implements DataInput

Class implementing a byte array input stream with a DataInput interface.

Version:
@version@ (@date@)
Author:
Dieter Wimberger

Constructor Summary
BytesInputStream(byte[] data)
          Constructs a new BytesInputStream instance, that will read from the given data.
BytesInputStream(int size)
          Constructs a new BytesInputStream instance, with an empty buffer of a given size.
 
Method Summary
 byte[] getBuffer()
          Returns the reference to the input buffer.
 int getBufferLength()
           
 boolean readBoolean()
           
 byte readByte()
           
 char readChar()
           
 double readDouble()
           
 float readFloat()
           
 void readFully(byte[] b)
           
 void readFully(byte[] b, int off, int len)
           
 int readInt()
           
 String readLine()
           
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
 void reset(byte[] data)
          Resets this BytesInputStream using the given byte[] as new input buffer.
 void reset(byte[] data, int length)
          Resets this BytesInputStream using the given byte[] as new input buffer and a given length.
 void reset(int length)
          Resets this BytesInputStream assigning the input buffer a new length.
 int skip(int n)
          Skips the given number of bytes or all bytes till the end of the assigned input buffer length.
 int skipBytes(int n)
           
 
Methods inherited from class net.wimpi.modbus.io.FastByteArrayInputStream
available, close, getPosition, mark, markSupported, read, read, read, reset, size, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BytesInputStream

public BytesInputStream(int size)
Constructs a new BytesInputStream instance, with an empty buffer of a given size.

Parameters:
size - the size of the input buffer.

BytesInputStream

public BytesInputStream(byte[] data)
Constructs a new BytesInputStream instance, that will read from the given data.

Parameters:
data - a byte array containing data to be read.
Method Detail

reset

public void reset(byte[] data)
Resets this BytesInputStream using the given byte[] as new input buffer.

Parameters:
data - a byte array with data to be read.

reset

public void reset(byte[] data,
                  int length)
Resets this BytesInputStream using the given byte[] as new input buffer and a given length.

Parameters:
data - a byte array with data to be read.
length - the length of the buffer to be considered.

reset

public void reset(int length)
Resets this BytesInputStream assigning the input buffer a new length.

Parameters:
length - the length of the buffer to be considered.

skip

public int skip(int n)
Skips the given number of bytes or all bytes till the end of the assigned input buffer length.

Parameters:
n - the number of bytes to be skipped as int.
Returns:
the number of bytes skipped.

getBuffer

public byte[] getBuffer()
Returns the reference to the input buffer.

Overrides:
getBuffer in class FastByteArrayInputStream
Returns:
the reference to the byte[] input buffer.

getBufferLength

public int getBufferLength()

readFully

public void readFully(byte[] b)
               throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

readFully

public void readFully(byte[] b,
                      int off,
                      int len)
               throws IOException
Specified by:
readFully in interface DataInput
Throws:
IOException

skipBytes

public int skipBytes(int n)
              throws IOException
Specified by:
skipBytes in interface DataInput
Throws:
IOException

readBoolean

public boolean readBoolean()
                    throws IOException
Specified by:
readBoolean in interface DataInput
Throws:
IOException

readByte

public byte readByte()
              throws IOException
Specified by:
readByte in interface DataInput
Throws:
IOException

readUnsignedByte

public int readUnsignedByte()
                     throws IOException
Specified by:
readUnsignedByte in interface DataInput
Throws:
IOException

readShort

public short readShort()
                throws IOException
Specified by:
readShort in interface DataInput
Throws:
IOException

readUnsignedShort

public int readUnsignedShort()
                      throws IOException
Specified by:
readUnsignedShort in interface DataInput
Throws:
IOException

readChar

public char readChar()
              throws IOException
Specified by:
readChar in interface DataInput
Throws:
IOException

readInt

public int readInt()
            throws IOException
Specified by:
readInt in interface DataInput
Throws:
IOException

readLong

public long readLong()
              throws IOException
Specified by:
readLong in interface DataInput
Throws:
IOException

readFloat

public float readFloat()
                throws IOException
Specified by:
readFloat in interface DataInput
Throws:
IOException

readDouble

public double readDouble()
                  throws IOException
Specified by:
readDouble in interface DataInput
Throws:
IOException

readLine

public String readLine()
                throws IOException
Specified by:
readLine in interface DataInput
Throws:
IOException

readUTF

public String readUTF()
               throws IOException
Specified by:
readUTF in interface DataInput
Throws:
IOException


Copyright © 2010. All Rights Reserved.