cds.util
Class TextBuffer

java.lang.Object
  extended bycds.util.TextBuffer

public class TextBuffer
extends java.lang.Object

Utility class managing a text, made of lines, in a buffer. It can be loaded from a file. Lines can be added with a 'add' method. Lines can be returned by line number.

Version:
1.0 Dec 2003
Author:
Marc Wenger/CDS

Field Summary
(package private)  java.lang.StringBuffer buff
           
(package private)  java.util.ArrayList lineBegin
           
(package private)  java.util.ArrayList lineEnd
           
(package private)  int nbline
           
 
Constructor Summary
TextBuffer()
          Constructor.
TextBuffer(java.io.File in)
          Constructor from a file object
 
Method Summary
 TextBuffer addFile(java.io.File f)
          Add the content of a file to the TextBuffer
 TextBuffer addLine(java.lang.String s)
          Add a line.
 TextBuffer clear()
          Clear the TextBuffer object, so it can be reused without recreation
 java.lang.String getLine(int num)
          Get a line from its position in the text
 int getSize()
          Get the number of lines in the TextBuffer
static void main(java.lang.String[] args)
           
 java.lang.String toString()
          Return the buffer as a String
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buff

java.lang.StringBuffer buff

nbline

int nbline

lineBegin

java.util.ArrayList lineBegin

lineEnd

java.util.ArrayList lineEnd
Constructor Detail

TextBuffer

public TextBuffer()
Constructor.


TextBuffer

public TextBuffer(java.io.File in)
           throws java.io.FileNotFoundException,
                  java.io.IOException
Constructor from a file object

Parameters:
in - File to load in the textBuffer
Throws:
java.io.FileNotFoundException - if the file is not found
java.io.IOException - if an IO Error occurs
Method Detail

addFile

public TextBuffer addFile(java.io.File f)
                   throws java.io.FileNotFoundException,
                          java.io.IOException
Add the content of a file to the TextBuffer

Parameters:
f - File to add
Returns:
the TextBuffer itself
Throws:
java.io.FileNotFoundException - if the file is not found
java.io.IOException - if an IO Error occurs

addLine

public TextBuffer addLine(java.lang.String s)
Add a line. It can be used to fill completely the TextBuffer object or to append lines after creation from a File.

Parameters:
s - new line to add to the TextBuffer
Returns:
the TextBuffer itself

getLine

public java.lang.String getLine(int num)
Get a line from its position in the text

Parameters:
num - number of the line
Returns:
the line as a String or null if the corresponding line does not exist

getSize

public int getSize()
Get the number of lines in the TextBuffer

Returns:
the number of lines (0 if the TextBuffer is empty).

clear

public TextBuffer clear()
Clear the TextBuffer object, so it can be reused without recreation

Returns:
the TextBuffer object.

toString

public java.lang.String toString()
Return the buffer as a String

Returns:
the String containing the whole text

main

public static void main(java.lang.String[] args)