cs1705.weblog
Class LogScanner

java.lang.Object
  extended by cs1705.weblog.LogScanner
All Implemented Interfaces:
Iterable<LogEntry>, Iterator<LogEntry>

public class LogScanner
extends Object
implements Iterator<LogEntry>, Iterable<LogEntry>

A class to scan information from a web server access log. It currently supports log files from the Virginia Tech CS department's server proxy, which are in Apache's log format.

Version:
2003.10.31
Author:
Dwight Barnette (based on Stephen Edwards' LogReader class)

Constructor Summary
LogScanner(File file)
          Create a LogScanner that reads access log data from the given file.
LogScanner(Scanner inStream)
          Create a LogScanner that reads access log data from the given stream.
LogScanner(String file)
          Create a LogScanner that reads access log data from the given file.
 
Method Summary
 boolean hasMoreEntries()
          A synonym for hasNext() provided for backward compatibility with the older Java 1.4-style LogReader class.
 boolean hasNext()
          Does the scanner have more data to supply?
 Iterator<LogEntry> iterator()
          Return this object, unchanged, to provide support for foreach-style loops.
 LogEntry next()
          Analyze the next line from the log file and make it available via a LogEntry object.
 LogEntry nextEntry()
          A synonym for hasNext() provided for backward compatibility with the older Java 1.4-style LogReader class.
 void remove()
          Provided for compliance with the Iterator interface, but this method is not supported.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogScanner

public LogScanner(File file)
Create a LogScanner that reads access log data from the given file. This constructor is provided for convenience only--it simply creates a scanner connected to the file.


LogScanner

public LogScanner(Scanner inStream)
Create a LogScanner that reads access log data from the given stream.


LogScanner

public LogScanner(String file)
Create a LogScanner that reads access log data from the given file. This constructor is provided for convenience only--it opens the named file and creates a scanner connected to it.

Method Detail

hasMoreEntries

public boolean hasMoreEntries()
A synonym for hasNext() provided for backward compatibility with the older Java 1.4-style LogReader class.

Returns:
true if there is more data available, false otherwise.

hasNext

public boolean hasNext()
Does the scanner have more data to supply?

Specified by:
hasNext in interface Iterator<LogEntry>
Returns:
true if there is more data available, false otherwise.

iterator

public Iterator<LogEntry> iterator()
Return this object, unchanged, to provide support for foreach-style loops. Note that this object's log entries can only be iterated over once, since the collection is directly bound to the source lines in the Scanner (possibly attached to a file) that was used to create this LogScanner.

Specified by:
iterator in interface Iterable<LogEntry>
Returns:
this object, unchanged (since it already implements Iterator)

next

public LogEntry next()
Analyze the next line from the log file and make it available via a LogEntry object.

Specified by:
next in interface Iterator<LogEntry>
Returns:
A LogEntry containing the data from the next log line
Throws:
NoSuchElementException - if there are no more log entries (call hasNext() first if you want to avoid the exception)

nextEntry

public LogEntry nextEntry()
A synonym for hasNext() provided for backward compatibility with the older Java 1.4-style LogReader class. This one silently converts NoSuchElementExceptions into null return values for backward compatibility.

Returns:
A LogEntry containing the data from the next log line, or null if there are no more lines.

remove

public void remove()
Provided for compliance with the Iterator interface, but this method is not supported.

Specified by:
remove in interface Iterator<LogEntry>
Throws:
UnsupportedOperationException - if you call it, since this operation is not supported on LogScanners