misc
Class LineReader

java.lang.Object
  extended bymisc.LineReader

public class LineReader
extends java.lang.Object

Small class demostrating the use of the java.io.LineNumberReader class and it's usefulness in searching text files.
TODO At some point consider the following enhancements


Nested Class Summary
 class LineReader.RetList
          Use a public inner class as the return for the searching.
 
Field Summary
private static boolean bCommandLine
          true when called the class is used via a command line
(package private)  java.util.List fileList
          A list of files to process
(package private)  java.lang.String strSearchText
          The text to search for in the file
 
Constructor Summary
LineReader(java.lang.String[] args)
          Constructor that processes the command line arguments
The minimum number of args is 2.
 
Method Summary
static void main(java.lang.String[] args)
          Main function - runs the show
private  java.util.List search(java.lang.String fileName, java.io.LineNumberReader lnr)
          Get hold of each line and search it for the first instance of the search string
 java.util.List searchFiles()
          Search the file list a line at a time for the search string
private  void usage()
          Display the usage details for this class - if called from the command line
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bCommandLine

private static boolean bCommandLine
true when called the class is used via a command line


strSearchText

java.lang.String strSearchText
The text to search for in the file


fileList

java.util.List fileList
A list of files to process

Constructor Detail

LineReader

public LineReader(java.lang.String[] args)
Constructor that processes the command line arguments
The minimum number of args is 2. args[0] = search string and args[1] = file to search

Method Detail

main

public static void main(java.lang.String[] args)
Main function - runs the show


searchFiles

public java.util.List searchFiles()
Search the file list a line at a time for the search string


search

private java.util.List search(java.lang.String fileName,
                              java.io.LineNumberReader lnr)
                       throws java.io.IOException
Get hold of each line and search it for the first instance of the search string

Throws:
java.io.IOException

usage

private void usage()
Display the usage details for this class - if called from the command line