info.aduna.io
Class CharPosInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by info.aduna.io.CharPosInputStream
All Implemented Interfaces:
Closeable

public class CharPosInputStream
extends InputStream

An InputStream that registers the position of the next character to read. This position can be a character offset or a combination of a line and column number. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r') , or a carriage return followed immediately by a linefeed ('\r\n').

Note: this class is only guaranteed to work correctly when the stream contains US-ASCII characters.


Constructor Summary
CharPosInputStream(InputStream r)
          Creates a new CharPosInputStream.
 
Method Summary
 void close()
           
 int getCharPos()
          Get the character position (1-based) for the next character to read.
 int getColumn()
          Get the column (1-based) for the next character to read.
 int getLineNo()
          Get the line number (1-based) for the next character to read.
 int read()
           
 int read(byte[] buf, int off, int len)
           
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharPosInputStream

public CharPosInputStream(InputStream r)
Creates a new CharPosInputStream.

Method Detail

getLineNo

public int getLineNo()
Get the line number (1-based) for the next character to read.


getColumn

public int getColumn()
Get the column (1-based) for the next character to read.


getCharPos

public int getCharPos()
Get the character position (1-based) for the next character to read.


read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException


Copyright © 2011 Aduna. All Rights Reserved.