ch.javasoft.jbase.util
Class AbstractDataInput

java.lang.Object
  extended by ch.javasoft.jbase.util.AbstractDataInput
All Implemented Interfaces:
DataInput

public abstract class AbstractDataInput
extends Object
implements DataInput

The AbstractDataInput class implements most methods of DataInput, leaving only the following methods for subclasses:

This class is thread safe.


Constructor Summary
AbstractDataInput()
           
 
Method Summary
protected abstract  int peek()
          Like read(), but the value is read again, that is, the position is not moved forward.
protected abstract  int read()
          Reads a byte of data from this file.
protected abstract  int read(byte[] b, int off, int len)
          Reads a sub array as a sequence of bytes.
 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()
          Note that this method throws an i/o exception if the peek() method is not supported.
 long readLong()
           
 short readShort()
           
 int readUnsignedByte()
           
 int readUnsignedShort()
           
 String readUTF()
           
abstract  int skipBytes(int n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDataInput

public AbstractDataInput()
Method Detail

read

protected abstract int read()
                     throws IOException
Reads a byte of data from this file. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff). This method should block if no input is yet available.

Although AbstractDataInput is not a subclass of InputStream, this method behaves in exactly the same way as the InputStream.read() method of InputStream.

Returns:
the next byte of data, or -1 if the end of the input has been reached.
Throws:
IOException - if an I/O error occurs. Not thrown if end-of-file has been reached.

peek

protected abstract int peek()
                     throws IOException
Like read(), but the value is read again, that is, the position is not moved forward. This method is used by readLine(), if subclasses cannot support this method, an i/o exception should be thrown, causing that readLine() will also throw an i/o exception.

Throws:
IOException - if peek operations are not supported

read

protected abstract int read(byte[] b,
                            int off,
                            int len)
                     throws IOException
Reads a sub array as a sequence of bytes.

Parameters:
b - the buffer into which the data is read.
off - the start offset of the data.
len - the number of bytes to read.
Throws:
IOException - If an I/O error has occurred.

skipBytes

public abstract 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

readChar

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

readDouble

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

readFloat

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

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

readInt

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

readLine

public String readLine()
                throws IOException
Note that this method throws an i/o exception if the peek() method is not supported.

Specified by:
readLine in interface DataInput
Throws:
IOException
See Also:
peek(), DataInput.readLine()

readLong

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

readShort

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

readUTF

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

readUnsignedByte

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

readUnsignedShort

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