|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.atomikos.util.VersionedFile
public class VersionedFile
A file with underlying version capabilities to ensure safe overwriting. Unlike regular files, this type of file is safe w.r.t. (over)writing a previous version: a backup version of the original content is kept until the client application explicitly states that a consistent new version has been written.
Constructor Summary | |
---|---|
VersionedFile(String baseDir,
String baseName,
String suffix)
Creates a new instance based on the given name parameters. |
Method Summary | |
---|---|
void |
close()
Closes any open resources and resets the file for reading again. |
void |
discardBackupVersion()
Discards the backup version (if any). |
String |
getBaseDir()
|
String |
getBaseName()
|
String |
getBaseUrl()
|
String |
getCurrentVersionFileName()
|
long |
getSize()
|
String |
getSuffix()
|
FileInputStream |
openLastValidVersionForReading()
Opens the last valid version for reading. |
FileOutputStream |
openNewVersionForWriting()
Opens a new version for writing to. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public VersionedFile(String baseDir, String baseName, String suffix)
baseDir
- The base folder.baseName
- The base name for of the file path/name.suffix
- The suffix to append to the complete file name.Method Detail |
---|
public String getCurrentVersionFileName()
public String getBaseUrl()
public String getBaseDir()
public String getBaseName()
public String getSuffix()
public FileInputStream openLastValidVersionForReading() throws IllegalStateException, FileNotFoundException
IllegalStateException
- If a newer version was opened for writing.
FileNotFoundException
- If no last version was found.public FileOutputStream openNewVersionForWriting() throws FileNotFoundException
openLastValidVersionForReading()
until
discardBackupVersion()
is called.
FileNotFoundException
FileNotFoundException
IllegalStateException
- If called more than once
without a close in between.
FileNotFoundException
- If the file cannot be opened for writing.public void discardBackupVersion() throws IllegalStateException, IOException
openNewVersionForWriting()
becomes valid for reading next time when
openLastValidVersionForReading()
is called.
Note: it is the caller's responsibility to make sure that
all new data has been flushed to disk before calling this method!
IllegalStateException
- If openNewVersionForWriting()
has not been called yet.
IOException
- If the previous version exists but could no be deleted.public void close() throws IOException
IOException
- If the output stream could not be closed.public long getSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |