se.biltmore.tools.fileeditor
Class TextFileBuffer

java.lang.Object
  extended by se.biltmore.tools.fileeditor.TextFileBuffer
All Implemented Interfaces:
TextBuffer

public class TextFileBuffer
extends Object
implements TextBuffer


Constructor Summary
TextFileBuffer()
          Creates a new instance of TextFileBuffer.
 
Method Summary
 void addLine(String text)
          Adds a line of text to the end of the buffer.
 void appendToLine(int line, String text)
          Appends text to the specified line.
 void clear()
          Clears the buffer.
 String getLine(int line)
          Gets a specific line from the buffer.
 int getSize()
          Returns the number of lines in the buffer.
 void insertLine(int line, String text)
          Inserts a new line at the specified position.
 void load(File file)
          Loads a text file into the buffer.
 void load(String path)
          Loads a text file into the buffer.
 TextBuffer newInstance()
          Returns a new instance of the buffer.
 void removeLine(int line)
          Removes the specified line.
 void save()
          Saves the buffer back to disk again.
 void saveAs(File file)
          Saves the buffer to another file.
 void saveAs(String path)
          Saves the buffer to another file.
 void setLine(int line, String text)
          Replaces a specific line in the buffer.
 void setReadOnly(boolean readOnly)
          If true makes the buffer read only.
 String toString()
          Returns the buffer as a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextFileBuffer

public TextFileBuffer()
Creates a new instance of TextFileBuffer.

Method Detail

setReadOnly

public void setReadOnly(boolean readOnly)
                 throws UnsupportedOperationException
If true makes the buffer read only.

Specified by:
setReadOnly in interface TextBuffer
Parameters:
readOnly - Set to true to make buffer read only. Defaults to false.
Throws:
UnsupportedOperationException

load

public void load(File file)
          throws IOException
Loads a text file into the buffer.

Parameters:
file - The file to load.
Throws:
IOException

load

public void load(String path)
          throws IOException
Loads a text file into the buffer.

Specified by:
load in interface TextBuffer
Parameters:
path - The path to the file to load.
Throws:
IOException

save

public void save()
          throws IOException
Saves the buffer back to disk again.

Specified by:
save in interface TextBuffer
Throws:
IOException

saveAs

public void saveAs(File file)
            throws IOException
Saves the buffer to another file.

Parameters:
file - The file to save to.
Throws:
IOException

saveAs

public void saveAs(String path)
            throws IOException
Saves the buffer to another file.

Specified by:
saveAs in interface TextBuffer
Parameters:
path - The path to the file to save to.
Throws:
IOException

clear

public void clear()
Clears the buffer.

Specified by:
clear in interface TextBuffer

getSize

public int getSize()
Returns the number of lines in the buffer.

Specified by:
getSize in interface TextBuffer

getLine

public String getLine(int line)
Gets a specific line from the buffer.

Specified by:
getLine in interface TextBuffer
Parameters:
line - The line to get.

setLine

public void setLine(int line,
                    String text)
Replaces a specific line in the buffer.

Specified by:
setLine in interface TextBuffer
Parameters:
line - The line to replace.
text - The new text for the line.

removeLine

public void removeLine(int line)
Removes the specified line.

Specified by:
removeLine in interface TextBuffer
Parameters:
line - The line to remove.

insertLine

public void insertLine(int line,
                       String text)
Inserts a new line at the specified position.

Specified by:
insertLine in interface TextBuffer
Parameters:
line - the poistion to insert at.
text - The text to insert.

appendToLine

public void appendToLine(int line,
                         String text)
Appends text to the specified line.

Parameters:
line - The line to add text to.
text - The text to add.

addLine

public void addLine(String text)
Adds a line of text to the end of the buffer.

Specified by:
addLine in interface TextBuffer
Parameters:
text - The text to add.

newInstance

public TextBuffer newInstance()
Returns a new instance of the buffer.

Specified by:
newInstance in interface TextBuffer

toString

public String toString()
Returns the buffer as a String.

Overrides:
toString in class Object


Copyright © 2009-2010 Biltmore Group AB. All Rights Reserved.