public class VersionedFile extends Object
| Constructor and Description |
|---|
VersionedFile(String baseDir,
String baseName,
String suffix)
Creates a new instance based on the given name parameters.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
FileChannel |
openNewVersionForNioWriting()
Opens a new version for writing to.
|
FileOutputStream |
openNewVersionForWriting()
Opens a new version for writing to.
|
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.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 IOException
openLastValidVersionForReading() until
discardBackupVersion() is called.IllegalStateException - If called more than once
without a close in between.IOException - If the file cannot be opened for writing.public FileChannel openNewVersionForNioWriting() throws FileNotFoundException
openLastValidVersionForReading() until
discardBackupVersion() is called.IOExceptionIllegalStateException - If called more than once
without a close in between.FileNotFoundException - If the file cannot be opened for writing.IOExceptionpublic 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()
Copyright © 2016. All Rights Reserved.