java.io

Class LineNumberReader

Implemented Interfaces:
Closeable, Readable
Known Direct Subclasses:
PropertiesConfiguration.PropertiesReader

public class LineNumberReader
extends BufferedReader

A buffered character-input stream that keeps track of line numbers. This class defines methods void setLineNumber(int) and int getLineNumber() for setting and getting the current line number respectively.

By default, line numbering begins at 0. This number increments as data is read, and can be changed with a call to setLineNumber(int). Note however, that setLineNumber(int) does not actually change the current position in the stream; it only changes the value that will be returned by getLineNumber().

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.

Since:
JDK1.1

Field Summary

Fields inherited from class java.io.Reader

lock

Constructor Summary

LineNumberReader(Reader in)
Create a new line-numbering reader, using the default input-buffer size.
LineNumberReader(Reader in, int sz)
Create a new line-numbering reader, reading characters into a buffer of the given size.

Method Summary

int
getLineNumber()
Get the current line number.
void
mark(int readAheadLimit)
Mark the present position in the stream.
int
read()
Read a single character.
int
read(cbuf[] , int off, int len)
Read characters into a portion of an array.
String
readLine()
Read a line of text.
void
reset()
Reset the stream to the most recent mark.
void
setLineNumber(int lineNumber)
Set the current line number.
long
skip(long n)
Skip characters.

Methods inherited from class java.io.BufferedReader

close, mark, markSupported, read, read, readLine, ready, reset, skip

Methods inherited from class java.io.Reader

close, mark, markSupported, read, read, read, read, ready, reset, skip

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

LineNumberReader

public LineNumberReader(Reader in)
Create a new line-numbering reader, using the default input-buffer size.
Parameters:
in - a Reader object to provide the underlying stream.
Usages and Demos :

View More Examples of LineNumberReader(Reader in)
   1:       fr = new FileReader( "LineNumberReaderDemo.java" );
   2:       LineNumberReader lnr = new LineNumberReader( fr );
   3: 
   4:       for ( String line; (line = lnr.readLine()) != null; )
   5:         System.out.println( lnr.getLineNumber() + ": " + line );

View Full Code Here
   1:     InputStreamReader streamReader = new InputStreamReader(stream);
   2:     AsmFile file = new AsmFile(new LineNumberReader(streamReader));
   3:     
   4:     assertEquals(152, file.numBasicBlocks());
   5:     

View Full Code Here
   1:         InputStreamReader isr = new InputStreamReader(is);
   2:         LineNumberReader r = new LineNumberReader(isr);
   3: 
   4:         String s = r.readLine();
   5:         if (s == null)

View Full Code Here
   1:         else
   2:             is = new LineNumberReader(rdr);
   3:     }
   4: 
   5:     protected void process() {

View Full Code Here
   1:             Reader reader        = new FileReader(file);
   2:             LineNumberReader lnr = new LineNumberReader(reader);
   3:             String line;
   4: 
   5:             while ((line = lnr.readLine()) != null) {

View Full Code Here

LineNumberReader

public LineNumberReader(Reader in,
                        int sz)
Create a new line-numbering reader, reading characters into a buffer of the given size.
Parameters:
in - a Reader object to provide the underlying stream.
sz - an int specifying the size of the buffer.
Usages and Demos :

View More Examples of LineNumberReader(Reader in,int sz)
   1:       if (taille > 6553600) {
   2:         read_ = new LineNumberReader(fr,655360);
   3:       }
   4:         ...
   5:       else if (taille > 655360) {
   6:         read_ = new LineNumberReader(fr,65536);
   7:       }
   8:         ...
   9:       else {
  10:         read_ = new LineNumberReader(fr,8192);
  11:       }

View Full Code Here
   1:   public FortranReader(Reader _reader, int _sz) {
   2:     this(new LineNumberReader(_reader, _sz));
   3:   }
   4: 
   5:   public void analyzeCurrentLine(int[] _fmt) throws IOException{

View Full Code Here
   1:       StringReader sr = new StringReader(" ");
   2:       LineNumberReader lnr = new LineNumberReader(sr, 0);
   3:       success(this.getClass());
   4:         ...
   5:       StringReader sr = new StringReader("X");
   6:       LineNumberReader lnr = new LineNumberReader(sr, -5);
   7:       success(this.getClass());
   8:     }
   9:     catch (Exception e) {

View Full Code Here
   1:                 InputStreamCounter streamPeeker = new InputStreamCounter(new FileInputStream(m_file));
   2:                 reader = new LineNumberReader(streamPeeker, 1);
   3:                 while (reader.readLine() != null) {
   4:                     CmsRfsFileLineIndexInfo.this.addLineBreakPosition(streamPeeker.position());
   5:                     synchronized (CmsRfsFileLineIndexInfo.this) {

View Full Code Here

Method Details

getLineNumber

public int getLineNumber()
Get the current line number.
Returns:
The current line number.
Usages and Demos :

View More Examples of getLineNumber()
   1: import java.io.IOException;
   2: import java.io.LineNumberReader;
   3: import java.io.Reader;
   4:         ...
   5:     {
   6:         LineNumberReader reader1 = new LineNumberReader(r1);
   7:         LineNumberReader reader2 = new LineNumberReader(r2);
   8:         ...
   9:                 diffs.add("File \"" + name1 + "\" and file \"" +
  10:                     name2 + "\" differ at line " + reader1.getLineNumber() +
  11:                     ":" + "\n" + line1 + "\n========\n" + line2);
  12:         ...
  13:             diffs.add("File \"" + name2 + "\" has extra lines at line " +
  14:                 reader2.getLineNumber() + ":\n" + line2);

View Full Code Here
   1:         try {
   2:             LineNumberReader reader = new LineNumberReader( new FileReader( file ) );
   3:             while( reader.readLine() != null);                    
   4:         ...
   5:             return reader.getLineNumber() -1;   
   6:         }
   7:         catch( IOException e){
   8:             return -1;

View Full Code Here
   1:     public void read(String fname) {
   2:         LineNumberReader is = null;
   3:         try {
   4:         ...
   5:             is = new LineNumberReader(new FileReader(fname));
   6: 
   7:         ...
   8:                     System.err.println("Invalid number on line " +
   9:                         is.getLineNumber());
  10:             }
  11:         ...
  12:         } catch (IOException e) {
  13:             System.err.println("I/O error on line " + is.getLineNumber());

View Full Code Here
   1:     public void read(String fname) {
   2:         LineNumberReader is = null;
   3:         try {
   4:         ...
   5:             is = new LineNumberReader(new FileReader(fname));
   6: 
   7:         ...
   8:                     System.err.println("Nombre invalide dans la ligne " +
   9:                         is.getLineNumber());
  10:             }
  11:         ...
  12:             System.err.println("Erreur d?E/S ? la ligne " + 
  13:                                is.getLineNumber());

View Full Code Here
   1: 
   2:   private LineNumberReader currentReader;
   3:   private String currentInclude;
   4:         ...
   5:   {
   6:     return currentReader.getLineNumber();
   7:   }
   8:         ...
   9:     return new Pos(getCurrentInclude().toString(), 
  10:            currentReader.getLineNumber()+1);
  11:   }
  12:         ...
  13:       }
  14:     currentReader = (r instanceof LineNumberReader) ? (LineNumberReader) r : new LineNumberReader(r);

View Full Code Here

mark

public void mark(int readAheadLimit)
            throws IOException
Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point, and will also reset the line number appropriately.
Overrides:
mark in interface BufferedReader
Parameters:
readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail.
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of mark(int readAheadLimit)
   1: import java.io.BufferedReader;
   2: import java.io.LineNumberReader;
   3: 
   4:         ...
   5: 
   6:   private static LineNumberReader reader = null;
   7: 
   8:         ...
   9:  
  10:     reader = new LineNumberReader(new BufferedReader(new FileReader(filename)));
  11:     
  12:         ...
  13:     boolean ret = true; 
  14:     reader.mark(4096);

View Full Code Here
   1: import java.io.BufferedReader;
   2: import java.io.LineNumberReader;
   3: 
   4:         ...
   5: 
   6:   private static LineNumberReader reader = null;
   7: 
   8:         ...
   9:  
  10:     reader = new LineNumberReader(new BufferedReader(new FileReader(filename)));
  11:     
  12:         ...
  13:     boolean ret = true; 
  14:     reader.mark(4096);

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.LineNumberReader;
   3: import java.util.ArrayList;
   4:         ...
   5:             FileReader fileReader = new FileReader(fileName);
   6:             LineNumberReader reader = new LineNumberReader(fileReader);
   7:             return new AsmFile(reader);
   8:         } catch (IOException e) {
   9:             System.out.println("I/O error while reading assemblies.");

View Full Code Here
   1: 
   2:   private LineNumberReader currentReader;
   3:   private String currentInclude;
   4:         ...
   5:       }
   6:     currentReader = (r instanceof LineNumberReader) ? (LineNumberReader) r : new LineNumberReader(r);
   7:     if (o != null) 
   8:         ...
   9:   {
  10:     currentReader.mark(readAheadLimit);
  11:   }

View Full Code Here
   1: import java.io.ByteArrayOutputStream;
   2: import java.io.LineNumberReader;
   3: import java.io.IOException;
   4:         ...
   5: 
   6:   protected void readHeaderInfo(LineNumberReader lnr) throws ParseException, IOException {
   7:     String line = readLine(lnr);
   8:         ...
   9:     
  10:   protected void readResourceInfo(LineNumberReader lnr) throws ParseException, IOException {
  11:     String line = readLine(lnr);
  12:         ...
  13:     certHash = parse("CERT_HASH", line, lnr.getLineNumber());
  14:     lnr.mark(80);

View Full Code Here

read

public int read()
            throws IOException
Read a single character. Line terminators are compressed into single newline ('\n') characters.
Overrides:
read in interface BufferedReader
Returns:
The character read, or -1 if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of read()
   1: import java.io.IOException;
   2: import java.io.LineNumberReader;
   3: 
   4:         ...
   5:       Rubens1DPermReader reader = new Rubens1DPermReader(file_);
   6:       return reader.read();
   7:     } else {
   8:         ...
   9:       Rubens1DNonPermReader reader = new Rubens1DNonPermReader(file_);
  10:       return reader.read();
  11:     }
  12:         ...
  13:     try {
  14:       LineNumberReader reader = new LineNumberReader(new FileReader(file_));

View Full Code Here

read

public int read(cbuf[] ,
                int off,
                int len)
            throws IOException
Read characters into a portion of an array.
Overrides:
read in interface BufferedReader
Parameters:
off - Offset at which to start storing characters
len - Maximum number of characters to read
Returns:
The number of bytes read, or -1 if the end of the stream has already been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of read(cbuf[] ,int off,int len)
   1: 
   2:   private LineNumberReader currentReader;
   3:   private String currentInclude;
   4:         ...
   5:       }
   6:     currentReader = (r instanceof LineNumberReader) ? (LineNumberReader) r : new LineNumberReader(r);
   7:     if (o != null) 
   8:         ...
   9:   {
  10:     int ret = currentReader.read(buf, off, len);

View Full Code Here
   1:   {
   2:     LineNumberReader in;
   3:     BufferedReader in2;
   4:         ...
   5:       {
   6:     in = new LineNumberReader(new FileReader(javaFile));
   7:     in.setLineNumber(1);
   8:         ...
   9:           {
  10:         in.read(buffer, 0, qtite);
  11:         if (_out != null)
  12:         ...
  13:           {
  14:         err.read(buffer, 0, qtite);

View Full Code Here

readLine

public String readLine()
            throws IOException
Read a line of text. 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.
Overrides:
readLine in interface BufferedReader
Returns:
A String containing the contents of the line, not including any line-termination characters, or null if the end of the stream has been reached
Throws:
IOException - If an I/O error occurs
Usages and Demos :

View More Examples of readLine()
   1:       fr = new FileReader( "LineNumberReaderDemo.java" );
   2:       LineNumberReader lnr = new LineNumberReader( fr );
   3: 
   4:         ...
   5:       for ( String line; (line = lnr.readLine()) != null; )
   6:         System.out.println( lnr.getLineNumber() + ": " + line );
   7:     }
   8:     catch ( IOException e ) {

View Full Code Here
   1: import java.io.InputStreamReader;
   2: import java.io.LineNumberReader;
   3: import java.net.ContentHandler;
   4:         ...
   5:         List<String> list = new LinkedList<String>();
   6:         LineNumberReader reader = new LineNumberReader(new InputStreamReader(urlc.getInputStream()));
   7: 
   8:         ...
   9:         for (String line = reader.readLine(); line != null; line = reader.readLine()) {
  10:             line.trim();

View Full Code Here
   1:       r=0;
   2:       LineNumberReader lnr=null;
   3:       try
   4:         ...
   5:           {
   6:         lnr=new LineNumberReader(new FileReader("/proc/loadavg"));
   7:         ...
   8:         String s=lnr.readLine();
   9:         s=s.substring(0,s.indexOf(' '));

View Full Code Here
   1:       r=0;
   2:       LineNumberReader lnr=null;
   3:       try
   4:         ...
   5:       {
   6:         lnr=new LineNumberReader(new FileReader("/proc/meminfo"));
   7: 
   8:         ...
   9:         {
  10:           String s=lnr.readLine();
  11:           if(s==null)

View Full Code Here
   1:       r=0;
   2:       LineNumberReader lnr=null;
   3:       try
   4:         ...
   5:       {
   6:         lnr=new LineNumberReader
   7:           (new FileReader("/proc/meminfo"));
   8:         ...
   9:         {
  10:           String s=lnr.readLine();

View Full Code Here

reset

public void reset()
            throws IOException
Reset the stream to the most recent mark.
Overrides:
reset in interface BufferedReader
Throws:
IOException - If the stream has not been marked, or if the mark has been invalidated
Usages and Demos :

View More Examples of reset()
   1: import java.io.BufferedReader;
   2: import java.io.LineNumberReader;
   3: 
   4:         ...
   5: 
   6:   private static LineNumberReader reader = null;
   7: 
   8:         ...
   9:  
  10:     reader = new LineNumberReader(new BufferedReader(new FileReader(filename)));
  11:     
  12:         ...
  13:     String line = reader.readLine();
  14:     reader.reset();

View Full Code Here
   1: import java.io.BufferedReader;
   2: import java.io.LineNumberReader;
   3: 
   4:         ...
   5: 
   6:   private static LineNumberReader reader = null;
   7: 
   8:         ...
   9:  
  10:     reader = new LineNumberReader(new BufferedReader(new FileReader(filename)));
  11:     
  12:         ...
  13:     String line = reader.readLine();
  14:     reader.reset();

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.LineNumberReader;
   3: import java.util.ArrayList;
   4:         ...
   5:             FileReader fileReader = new FileReader(fileName);
   6:             LineNumberReader reader = new LineNumberReader(fileReader);
   7:             return new AsmFile(reader);
   8:         ...
   9:                 continue;
  10:             reader.reset();
  11:             return true;

View Full Code Here
   1: 
   2:   private LineNumberReader currentReader;
   3:   private String currentInclude;
   4:         ...
   5:       }
   6:     currentReader = (r instanceof LineNumberReader) ? (LineNumberReader) r : new LineNumberReader(r);
   7:     if (o != null) 
   8:         ...
   9:   {
  10:     currentReader.reset();
  11:   }

View Full Code Here
   1: import java.io.ByteArrayOutputStream;
   2: import java.io.LineNumberReader;
   3: import java.io.IOException;
   4:         ...
   5: 
   6:   protected void readHeaderInfo(LineNumberReader lnr) throws ParseException, IOException {
   7:     String line = readLine(lnr);
   8:         ...
   9:     
  10:   protected void readResourceInfo(LineNumberReader lnr) throws ParseException, IOException {
  11:     String line = readLine(lnr);
  12:         ...
  13:       dirName = "";
  14:       lnr.reset();

View Full Code Here

setLineNumber

public void setLineNumber(int lineNumber)
Set the current line number.
Parameters:
lineNumber - an int specifying the line number.
Usages and Demos :

View More Examples of setLineNumber(int lineNumber)
   1:   {
   2:     LineNumberReader in;
   3:     BufferedReader in2;
   4:         ...
   5:       {
   6:     in = new LineNumberReader(new FileReader(javaFile));
   7:         ...
   8:     in.setLineNumber(1);
   9:     map = new Vector();

View Full Code Here

skip

public long skip(long n)
            throws IOException
Skip characters.
Overrides:
skip in interface BufferedReader
Parameters:
n - The number of characters to skip
Returns:
The number of characters actually skipped
Throws:
IOException - If an I/O error occurs
IllegalArgumentException - if n is negative
Usages and Demos :

View More Examples of skip(long n)
   1: import java.io.FileReader;
   2: import java.io.LineNumberReader;
   3: import java.util.Hashtable;
   4:         ...
   5:                 FileReader reader = new FileReader(file);
   6:                 LineNumberReader lnr = new LineNumberReader(reader);
   7:                 if(toSkip > 0) {
   8:         ...
   9:                     lnr.skip(toSkip);
  10:                     lnr.readLine();

View Full Code Here
   1: 
   2:   private LineNumberReader currentReader;
   3:   private String currentInclude;
   4:         ...
   5:       }
   6:     currentReader = (r instanceof LineNumberReader) ? (LineNumberReader) r : new LineNumberReader(r);
   7:     if (o != null) 
   8:         ...
   9:   {
  10:     long skipped = currentReader.skip(n);
  11: 
  12:         ...
  13:         pop();
  14:         return currentReader.skip(n - skipped);

View Full Code Here
   1: 
   2:       LineNumberReader lnr = new LineNumberReader(new FileReader(getIndexedPath(doc_list)));
   3:       while(lnr.ready())
   4:         ...
   5:     FileInputStream fis = new FileInputStream(file);
   6:     LineNumberReader lnr = new LineNumberReader(new InputStreamReader(fis));
   7: 
   8:         ...
   9:     lnr.skip(fis.available());

View Full Code Here
   1: import java.io.IOException;
   2: import java.io.LineNumberReader;
   3: import java.io.Reader;
   4:         ...
   5:   String commentChar_;
   6:   LineNumberReader in_;
   7:   CtuluGNULineNumberReader inGnu_;
   8:         ...
   9: 
  10:   public FortranReader(LineNumberReader _reader) {
  11:     if (_reader == null)
  12:         ...
  13:     if (inGnu_ != null)
  14:       return inGnu_.skip(_n);

View Full Code Here
   1: import java.io.InputStreamReader;
   2: import java.io.LineNumberReader;
   3: import java.io.OutputStreamWriter;
   4:         ...
   5:             addLineBreakPosition(0);
   6:             LineNumberReader reader = null;
   7:             m_creationTime = System.currentTimeMillis();
   8:         ...
   9:                 InputStreamCounter streamPeeker = new InputStreamCounter(new FileInputStream(m_file));
  10:                 reader = new LineNumberReader(streamPeeker, 1);
  11:                 while (reader.readLine() != null) {
  12:         ...
  13: 
  14:             long result = m_delegate.skip(n);

View Full Code Here