org.wurbelizer
Class SourceFile

java.lang.Object
  extended by org.wurbelizer.SourceFile

public class SourceFile
extends Object

In-memory file to check for changes before close/flush. Manages a static set of such SourceFiles that can be closed and thus released at one (meant to be attached to a single SourceDocument).


Method Summary
 void close()
          Closes the file.
static void closeAll()
          Closes all files and clears the vector
 void flush()
          Flushs the file (overwrite existing file or create a new one).
 String getNewText()
          Gets the new text/contents of the file.
 String getOrgText()
          Gets the original text (contents) of the file.
 PrintStream getStream()
          Gets a stream for the file to be rewritten.
static void initialize()
          Discard all files in list, if any.
 boolean needsFlush()
          Checks whether the file is changed and needs a flush for persistance.
static SourceFile open(String filename)
          Opens the file and load into memory.
static void resetAll()
          Rewinds all output streams (makes them empty again).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

open

public static SourceFile open(String filename)
                       throws IOException
Opens the file and load into memory.

Parameters:
filename - the filename
Returns:
the open file
Throws:
IOException - if reading the file did fail

getOrgText

public String getOrgText()
Gets the original text (contents) of the file.

Returns:
the original text, null = no such file

getStream

public PrintStream getStream()
Gets a stream for the file to be rewritten. This will only create a memory stream for appending data. It does not physically write to the file!

Returns:
the open stream

getNewText

public String getNewText()
Gets the new text/contents of the file.

Returns:
the new (changed) contents, null = no getStream() invoked.

needsFlush

public boolean needsFlush()
Checks whether the file is changed and needs a flush for persistance.

Returns:
true if newText differs from oldText

flush

public void flush()
           throws FileNotFoundException,
                  IOException
Flushs the file (overwrite existing file or create a new one).

Throws:
FileNotFoundException - if file cannpt be created
IOException - if flush failed

close

public void close()
           throws FileNotFoundException,
                  IOException
Closes the file. Will flush if necessary.

Throws:
FileNotFoundException - if file cannpt be created
IOException - if flush failed

initialize

public static void initialize()
Discard all files in list, if any.


resetAll

public static void resetAll()
Rewinds all output streams (makes them empty again).


closeAll

public static void closeAll()
                     throws FileNotFoundException,
                            IOException
Closes all files and clears the vector

Throws:
FileNotFoundException
IOException


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de