uk.me.parabola.imgfmt.app
Class BufferedImgFileReader

java.lang.Object
  extended by uk.me.parabola.imgfmt.app.BufferedImgFileReader
All Implemented Interfaces:
java.io.Closeable, ImgFileReader

public class BufferedImgFileReader
extends java.lang.Object
implements ImgFileReader

Read from an img file via a buffer.

Author:
Steve Ratcliffe

Constructor Summary
BufferedImgFileReader(ImgChannel chan)
           
 
Method Summary
 void close()
          Called when the stream is closed.
 byte get()
          Read in a single byte from the current position.
 byte[] get(int len)
          Read in an arbitrary length sequence of bytes.
 int get3()
          Read a three byte signed quantity.
 java.lang.String getBase11str(byte firstChar, char delimiter)
          Read in a string of digits in the compressed base 11 format that is used for phone numbers in the POI section.
 char getChar()
          Read in two bytes.
 int getInt()
          Read in a 4 byte value.
 int getu3()
          Get a 3byte unsigned quantity.
 java.lang.String getZString()
          Read a zero terminated string from the file.
 long position()
          Get the position.
 void position(long pos)
          Set the position of the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedImgFileReader

public BufferedImgFileReader(ImgChannel chan)
Method Detail

close

public void close()
           throws java.io.IOException
Called when the stream is closed. Any resources can be freed.

Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException - When there is an error in closing.

position

public long position()
Get the position. Needed because may not be reflected in the underlying file if being buffered.

Specified by:
position in interface ImgFileReader
Returns:
The logical position within the file.

position

public void position(long pos)
Set the position of the file.

Specified by:
position in interface ImgFileReader
Parameters:
pos - The new position in the file.

get

public byte get()
         throws ReadFailedException
Read in a single byte from the current position.

Specified by:
get in interface ImgFileReader
Returns:
The byte that was read.
Throws:
ReadFailedException

getChar

public char getChar()
             throws ReadFailedException
Read in two bytes. Done in the correct byte order.

Specified by:
getChar in interface ImgFileReader
Returns:
The 2 byte integer that was read.
Throws:
ReadFailedException

get3

public int get3()
         throws ReadFailedException
Read a three byte signed quantity.

Specified by:
get3 in interface ImgFileReader
Returns:
The read value.
Throws:
ReadFailedException

getu3

public int getu3()
          throws ReadFailedException
Description copied from interface: ImgFileReader
Get a 3byte unsigned quantity.

Specified by:
getu3 in interface ImgFileReader
Returns:
The value read.
Throws:
ReadFailedException - When the file cannot be read.

getInt

public int getInt()
           throws ReadFailedException
Read in a 4 byte value.

Specified by:
getInt in interface ImgFileReader
Returns:
A 4 byte integer.
Throws:
ReadFailedException

get

public byte[] get(int len)
           throws ReadFailedException
Read in an arbitrary length sequence of bytes.

Specified by:
get in interface ImgFileReader
Parameters:
len - The number of bytes to read.
Throws:
ReadFailedException

getZString

public java.lang.String getZString()
                            throws ReadFailedException
Read a zero terminated string from the file.

Specified by:
getZString in interface ImgFileReader
Returns:
A string
Throws:
ReadFailedException - For failures.

getBase11str

public java.lang.String getBase11str(byte firstChar,
                                     char delimiter)
Read in a string of digits in the compressed base 11 format that is used for phone numbers in the POI section.

Specified by:
getBase11str in interface ImgFileReader
Parameters:
delimiter - This will replace all digit 11 characters. Usually a '-' to separate numbers in a telephone. No doubt there is a different standard in each country.
Returns:
A phone number possibly containing the delimiter character.