public class VersionedFile
extends java.lang.Object
| Constructor and Description |
|---|
VersionedFile(java.lang.String baseDir,
java.lang.String baseName,
java.lang.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).
|
java.lang.String |
getBaseDir() |
java.lang.String |
getBaseName() |
java.lang.String |
getBaseUrl() |
java.lang.String |
getCurrentVersionFileName() |
long |
getSize() |
java.lang.String |
getSuffix() |
java.io.FileInputStream |
openLastValidVersionForReading()
Opens the last valid version for reading.
|
java.nio.channels.FileChannel |
openNewVersionForNioWriting()
Opens a new version for writing to.
|
java.io.FileOutputStream |
openNewVersionForWriting()
Opens a new version for writing to.
|
public VersionedFile(java.lang.String baseDir,
java.lang.String baseName,
java.lang.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 java.lang.String getCurrentVersionFileName()
public java.lang.String getBaseUrl()
public java.lang.String getBaseDir()
public java.lang.String getBaseName()
public java.lang.String getSuffix()
public java.io.FileInputStream openLastValidVersionForReading()
throws java.lang.IllegalStateException,
java.io.FileNotFoundException
java.lang.IllegalStateException - If a newer version was opened for writing.java.io.FileNotFoundException - If no last version was found.public java.io.FileOutputStream openNewVersionForWriting()
throws java.io.IOException
openLastValidVersionForReading() until
discardBackupVersion() is called.java.lang.IllegalStateException - If called more than once
without a close in between.java.io.IOException - If the file cannot be opened for writing.public java.nio.channels.FileChannel openNewVersionForNioWriting()
throws java.io.FileNotFoundException
openLastValidVersionForReading() until
discardBackupVersion() is called.java.io.IOExceptionjava.lang.IllegalStateException - If called more than once
without a close in between.java.io.FileNotFoundException - If the file cannot be opened for writing.java.io.IOExceptionpublic void discardBackupVersion()
throws java.lang.IllegalStateException,
java.io.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!java.lang.IllegalStateException - If openNewVersionForWriting() has not been called yet.java.io.IOException - If the previous version exists but could no be deleted.public void close()
throws java.io.IOException
java.io.IOException - If the output stream could not be closed.public long getSize()
Copyright © 2018. All Rights Reserved.