SourceJammer 1.2.0.1 May 20, 2002
Copyright (c) 2001, 2002 Robert MacGrogan

org.sourcejammer.server.source
Class TextLineReader

java.lang.Object
  |
  +--org.sourcejammer.server.source.TextLineIteratorOutput
        |
        +--org.sourcejammer.server.source.TextLineReader
All Implemented Interfaces:
java.io.Serializable, TextLineIterator

public class TextLineReader
extends TextLineIteratorOutput
implements java.io.Serializable

This class reads and outputs lines of text from a binary file passed to it as a byte array. It is not necessary to pass the end of line characters to this class. It can determine the end of a line whether the end of line is represented by line feed or carriage return / line feed.

Note: TextLineReader returns text lines without any end of line characters.

See Also:
Serialized Form

Constructor Summary
TextLineReader(byte[] buf)
          Constructs a TextLineReader from the passed-in byte array.
TextLineReader(byte[] buf, int offset, int length)
          Constructs a TextLineReader from the specified bytes in the passed-in byte array.
TextLineReader(java.io.InputStream st)
          Constructs a TextLineReader to read the bytes from the passed in InputStream.
TextLineReader(java.util.Vector vec)
          Constructs a new NextLineReader explicitly setting the underlying Vector to a Vector of Strings.
 
Method Summary
 boolean equals(java.lang.Object o)
          Returns true if the the object is a TextLineReader and the current line of the object is equal to the current line of this TextLineReader.
 java.lang.String getCurrentLine()
          Returns the current line without adavancing the iterator.
 int getIndex()
           
 java.lang.String getLine(int index)
          Returns the line with the specified index.
 java.lang.String getNextLine()
          Returns the next line and advances the index.
 int getNumLines()
          Returns the number of lines in the TextLineReader.
 java.util.Vector getUnderlyingVector()
           
 boolean hasMoreLines()
          Returns true if the TextLineReader contains additional lines after the current index.
 boolean next()
          Advances the iterator to the next line.
 void setIndex(int index)
          Sets the index to the specified line number.
 int size()
          Returns the total number of characters in all the lines in this TextLineReader.
 void skipLines(int numLines)
          Moves the index ahead by the specified number of lines.
 char[] toCharArray()
           
 char[] toCharArray(java.lang.String eol)
           
 java.lang.String toString()
          Returns contents of this TextLineReader (the entire text file) as a String, the default end of line chars (from AppConfig) as the end of line String.
 java.lang.String toString(java.lang.String eol)
          Returns contents of this TextLineReader (the entire text file) as a String, using the passed in eol as the end of line String.
 java.lang.StringBuffer toStringBuffer(java.lang.String eol)
          Returns contents of this TextLineReader (the entire text file) as a StringBuffer, using the passed in eol as the end of line String.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextLineReader

public TextLineReader(byte[] buf)
               throws java.io.IOException
Constructs a TextLineReader from the passed-in byte array.
Parameters:
buf - -- a byte array that is a binary representation of a text file.

TextLineReader

public TextLineReader(java.util.Vector vec)
Constructs a new NextLineReader explicitly setting the underlying Vector to a Vector of Strings. Used for storing the contents of a TextLineReader object without explicitly serializing this object. Vector is serialized instead.

TextLineReader

public TextLineReader(byte[] buf,
                      int offset,
                      int length)
               throws java.io.IOException
Constructs a TextLineReader from the specified bytes in the passed-in byte array.
Parameters:
buf - -- a byte array that is a binary representation of a text file.
offset - -- byte in the buf at which read should begin.
length - -- number of bytes in buf to read.

TextLineReader

public TextLineReader(java.io.InputStream st)
               throws java.io.IOException
Constructs a TextLineReader to read the bytes from the passed in InputStream.
Parameters:
st - -- an InputStream for streaming in bytes which are a binary representation of a text file.
Method Detail

getNumLines

public int getNumLines()
Returns the number of lines in the TextLineReader.

setIndex

public void setIndex(int index)
              throws EndOfSourceException
Sets the index to the specified line number.
Parameters:
index - -- the line number to set the index to.
Throws:
EndOfSourceException - -- if the TextLineReader does not contain a line with the specified index.

getLine

public java.lang.String getLine(int index)
Returns the line with the specified index.
Parameters:
index - -- a line number.
Returns:
the line at the requested index.

hasMoreLines

public boolean hasMoreLines()
Returns true if the TextLineReader contains additional lines after the current index.
Overrides:
hasMoreLines in class TextLineIteratorOutput

skipLines

public void skipLines(int numLines)
               throws EndOfSourceException
Moves the index ahead by the specified number of lines.
Overrides:
skipLines in class TextLineIteratorOutput
Parameters:
numLines - -- number of lines to skip.

getNextLine

public java.lang.String getNextLine()
                             throws EndOfSourceException
Returns the next line and advances the index.
Overrides:
getNextLine in class TextLineIteratorOutput
Returns:
the next line, as String.
Throws:
EndOfSourceException - if there is no next line.

size

public int size()
Returns the total number of characters in all the lines in this TextLineReader.

getIndex

public int getIndex()

next

public boolean next()
Advances the iterator to the next line. Returns true if this was successful. Returns false when end of file is reached.

getCurrentLine

public java.lang.String getCurrentLine()
                                throws EndOfSourceException
Returns the current line without adavancing the iterator.

equals

public boolean equals(java.lang.Object o)
Returns true if the the object is a TextLineReader and the current line of the object is equal to the current line of this TextLineReader.
Overrides:
equals in class java.lang.Object

toStringBuffer

public java.lang.StringBuffer toStringBuffer(java.lang.String eol)
Returns contents of this TextLineReader (the entire text file) as a StringBuffer, using the passed in eol as the end of line String.
Overrides:
toStringBuffer in class TextLineIteratorOutput

toString

public java.lang.String toString(java.lang.String eol)
Returns contents of this TextLineReader (the entire text file) as a String, using the passed in eol as the end of line String.
Overrides:
toString in class TextLineIteratorOutput

toString

public java.lang.String toString()
Returns contents of this TextLineReader (the entire text file) as a String, the default end of line chars (from AppConfig) as the end of line String.
Overrides:
toString in class TextLineIteratorOutput

toCharArray

public char[] toCharArray(java.lang.String eol)
Overrides:
toCharArray in class TextLineIteratorOutput

toCharArray

public char[] toCharArray()
Overrides:
toCharArray in class TextLineIteratorOutput

getUnderlyingVector

public java.util.Vector getUnderlyingVector()

SourceJammer 1.2.0.1 May 20, 2002
Copyright (c) 2001, 2002 Robert MacGrogan