jAER project on SourceForge

ch.unizh.ini.jaer.projects.robothead
Class WordCount

java.lang.Object
  extended by ch.unizh.ini.jaer.projects.robothead.WordCount

public class WordCount
extends java.lang.Object

Command line program to count lines, words and characters in files or from standard input, similar to the wc utility. Run like that: java WordCount FILE1 FILE2 ... or like that: java WordCount < FILENAME.

Author:
Marco Schmidt

Field Summary
 int numChars
           
 int numLines
           
 int numWords
           
 
Constructor Summary
WordCount()
           
 
Method Summary
 void count(java.lang.String fileName)
          Open file, count its words, lines and characters and print them to standard output.
 void count(java.lang.String name, java.io.BufferedReader in)
          Count lines, words and characters in given input stream and print stream name and those numbers to standard output.
 void count(java.lang.String streamName, java.io.InputStream input)
          Count words, lines and characters of given input stream and print them to standard output.
 long countWords(java.lang.String line)
          Determine the number of words in the argument line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numLines

public int numLines

numWords

public int numWords

numChars

public int numChars
Constructor Detail

WordCount

public WordCount()
Method Detail

count

public void count(java.lang.String name,
                  java.io.BufferedReader in)
           throws java.io.IOException
Count lines, words and characters in given input stream and print stream name and those numbers to standard output.

Parameters:
name - name of input source
in - stream to be processed
Throws:
java.io.IOException - if there were I/O errors

count

public void count(java.lang.String fileName)
Open file, count its words, lines and characters and print them to standard output.

Parameters:
fileName - name of file to be processed

count

public void count(java.lang.String streamName,
                  java.io.InputStream input)
Count words, lines and characters of given input stream and print them to standard output.

Parameters:
streamName - name of input stream (to print it to stdout)
input - InputStream to read from

countWords

public long countWords(java.lang.String line)
Determine the number of words in the argument line.

Parameters:
line - String to be examined, must be non-null
Returns:
number of words, 0 or higher

jAER project on SourceForge