org.nuiton.jrst
Class AdvancedReader

java.lang.Object
  extended by org.nuiton.jrst.AdvancedReader

public class AdvancedReader
extends Object

Le principe est d'avoir dans cette classe le moyen de lire, et de retourner la ou on etait avant la lecture (mark et reset de BufferedReader).

Mais il faut aussi pouvoir dire qu'en fin de compte on ne souhaite pas lire les caracteres que l'on vient de lire (unread(int) a peu pres egal a PushbackReader)

Le pointer nextChar pointe toujours sur le prochain caractere qui sera lu

Lorsque l'on appelle la method mark() on vide aussi le buffer pour liberer de la place, car on a plus le moyen de retourner avant le mark que l'on vient de positionner.

On contraire du mark de BufferedReader ou LineNumberReader il n'y a pas a specifier le nombre de caractere a garder au maximum, seul la memoire nous limite. Du coup si l'on utilise cette classe sans mark, au final on aura dans le buffer tout le contenu du reader, il faut donc utiliser mark avec cette classe buffer

 #########################
 0     ˆ       ˆ
       |       |
       |       + nextChar
       + markChar
 
Created: 27 oct. 06 00:24:57

Version:
$Revision: 334 $ Last update: $Date: 2009-05-16 07:33:16 +0200 (sam., 16 mai 2009) $ by : $Author: tchemit $
Author:
poussin

Field Summary
protected  org.apache.commons.collections.primitives.CharList buffer
           
protected  int charNumber
           
protected  int charNumberMark
           
protected  Reader in
           
protected  int lineNumber
           
protected  int lineNumberMark
           
protected  int markChar
           
protected  int nextChar
           
protected static int READ_AHEAD
          nombre de caractere lu au minimum sur le vrai reader
protected  int readInMark
           
protected static String TAB
          le nombre d'espace pour remplacer les tabulations
 
Constructor Summary
AdvancedReader(Reader in)
           
 
Method Summary
 boolean eof()
           
 int getCharNumber()
           
 int getLineNumber()
           
 void mark()
           
 int read()
          read one char in buffer
 String readLine()
          read one line
 String[] readLines(int count)
          lit un certain nombre de lignes
 int readSinceMark()
           
 String[] readUntil(String pattern)
          lit les lignes jusqu'a la ligne qui correspond pas au pattern, cette ligne n'est pas mise dans le resultat retourne
 String[] readUntilBlank()
          lit les lignes jusqu'a la premiere ligne blanche (non retournée)
 String[] readWhile(String pattern)
          lit les lignes tant que les lignes correspondent au pattern
 void reset()
           
 int skip(int number)
           
 void skipBlankLines()
          passe les lignes blanches
 int unread(int number)
          go left in reading char buffer
 int unread(String[] lines, boolean addNewLine)
          Unread the line length
 int unread(String line, boolean addNewLine)
          Unread the line length
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAB

protected static final String TAB
le nombre d'espace pour remplacer les tabulations

See Also:
Constant Field Values

READ_AHEAD

protected static final int READ_AHEAD
nombre de caractere lu au minimum sur le vrai reader

See Also:
Constant Field Values

in

protected Reader in

buffer

protected org.apache.commons.collections.primitives.CharList buffer

charNumber

protected int charNumber

charNumberMark

protected int charNumberMark

lineNumber

protected int lineNumber

lineNumberMark

protected int lineNumberMark

nextChar

protected int nextChar

markChar

protected int markChar

readInMark

protected int readInMark
Constructor Detail

AdvancedReader

public AdvancedReader(Reader in)
Parameters:
in - the io reader
Method Detail

mark

public void mark()
          throws IOException
Throws:
IOException

reset

public void reset()
           throws IOException
Throws:
IOException

readSinceMark

public int readSinceMark()

getCharNumber

public int getCharNumber()
Returns:
the charNumber

getLineNumber

public int getLineNumber()
Returns:
the lineNumber

eof

public boolean eof()
            throws IOException
Throws:
IOException

skip

public int skip(int number)
         throws IOException
Throws:
IOException

unread

public int unread(int number)
go left in reading char buffer

Parameters:
number -
Returns:
realy unread char number

unread

public int unread(String line,
                  boolean addNewLine)
Unread the line length

Parameters:
line - line used to know the length to unread
addNewLine - if true then add +1 to unread lenght for not present '\n'
Returns:
number of unread char

unread

public int unread(String[] lines,
                  boolean addNewLine)
Unread the line length

Parameters:
lines - lines used to know the length to unread
addNewLine - if true then add +1 for each line to unread lenght for not present '\n'
Returns:
number of unread char

read

public int read()
         throws IOException
read one char in buffer

Returns:
the next car
Throws:
IOException - pour tout pb de lecture

readLine

public String readLine()
                throws IOException
read one line

Returns:
one line without '\n' or null if end of file
Throws:
IOException - pour tout pb de lecture

skipBlankLines

public void skipBlankLines()
                    throws IOException
passe les lignes blanches

Throws:
IOException

readLines

public String[] readLines(int count)
                   throws IOException
lit un certain nombre de lignes

Parameters:
count - si negatif lit toutes les lignes
Returns:
un certain nombre de lignes
Throws:
IOException - pour tout pb de lecture

readUntilBlank

public String[] readUntilBlank()
                        throws IOException
lit les lignes jusqu'a la premiere ligne blanche (non retournée)

Returns:
toutes les ligne jusqu'à la première ligne blanche (non incluse)
Throws:
IOException - pour tout pb de lecture

readUntil

public String[] readUntil(String pattern)
                   throws IOException
lit les lignes jusqu'a la ligne qui correspond pas au pattern, cette ligne n'est pas mise dans le resultat retourne

Parameters:
pattern - ?
Returns:
les lignes jusqu'a la ligne qui correspond pas au pattern, cette ligne n'est pas mise dans le resultat retourne
Throws:
IOException - pour tout pb de lecture

readWhile

public String[] readWhile(String pattern)
                   throws IOException
lit les lignes tant que les lignes correspondent au pattern

Parameters:
pattern - ?
Returns:
les lignes tant que les lignes correspondent au pattern
Throws:
IOException - pour tout pb de lecture


Copyright © 2004-2010 CodeLutin. All Rights Reserved.