com.partnersoft.io
Class TextLineReader

java.lang.Object
  extended by com.partnersoft.io.AbstractIterableInput<java.lang.String>
      extended by com.partnersoft.io.TextLineReader
All Implemented Interfaces:
IterableInput<java.lang.String>, java.lang.Iterable<java.lang.String>

public class TextLineReader
extends AbstractIterableInput<java.lang.String>

A line-oriented text file reader based on IterableInput.

Copyright 2008 Partner Software, Inc.

Version:
$Id$
Author:
Paul Reavis

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.partnersoft.io.IterableInput
IterableInput.Status
 
Constructor Summary
TextLineReader(VfsFile file)
           
 
Method Summary
protected  void closeImp()
          Subclass implementation of guts of close() method.
protected  boolean fetchImp()
          Subclass implementation of guts of fetch() method.
 java.lang.String getFetched()
          Returns the last fetched item (if immutable) or a copy of it (if mutable).
protected  void openImp()
          Subclass implementation of guts of open() method.
 
Methods inherited from class com.partnersoft.io.AbstractIterableInput
close, fetch, getException, getStatus, isFetchValid, iterator, open
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextLineReader

public TextLineReader(VfsFile file)
Method Detail

closeImp

protected void closeImp()
                 throws java.lang.Exception
Description copied from class: AbstractIterableInput
Subclass implementation of guts of close() method.

Subclasses must implement this to do the actual work required by close(). Feel free to throw exceptions; these are caught inside the close() itself and applied to the exception variable. Thus, you can focus on the actual task instead of paperwork.

Specified by:
closeImp in class AbstractIterableInput<java.lang.String>
Throws:
java.lang.Exception

fetchImp

protected boolean fetchImp()
                    throws java.lang.Exception
Description copied from class: AbstractIterableInput
Subclass implementation of guts of fetch() method.

Subclasses must implement this to do the actual work required by fetch(). Feel free to throw exceptions; these are caught inside the fetch() itself and applied to the exception variable. Thus, you can focus on the actual task instead of paperwork.

Specified by:
fetchImp in class AbstractIterableInput<java.lang.String>
Returns:
true if fetch successful
Throws:
java.lang.Exception

openImp

protected void openImp()
                throws java.lang.Exception
Description copied from class: AbstractIterableInput
Subclass implementation of guts of open() method.

Subclasses must implement this to do the actual work required by open(). Feel free to throw exceptions; these are caught inside the open() itself and applied to the exception variable. Thus, you can focus on the actual task instead of paperwork.

Specified by:
openImp in class AbstractIterableInput<java.lang.String>
Throws:
java.lang.Exception

getFetched

public java.lang.String getFetched()
Description copied from interface: IterableInput
Returns the last fetched item (if immutable) or a copy of it (if mutable). Note that this means multiple calls to getFetched() may return different objects for the same fetch, but that the return value is always safe to share since modifying it won't affect the IterableInput's internal state.

The last fetched item is that loaded by the most recent call to fetch().

Implementations may prefer to instantiate this lazily; in other words, the underlying IterableInput may know that it has a valid fetch (e.g. loaded the characters for a String into an internal buffer) but may not have created this object yet (e.g. created a new String with the characters from the buffer). This allows skipping items without instantiating them, or accessing the underlying state without instantiating an actual item.

Implementations may also wish to provide unsafe access to the fetched item via other methods or public variables. The requirement that a safe copy be returned does prevent object reuse or other optimizations with this method, so feel free to use other means to provide a high-performance alternative.

This method may only be called when the input is in the FETCHING status. Calling it from any other status will result in an IllegalStateException.

Returns:
object representing the most recent fetch