org.eclipse.osgi.framework.internal.reliablefile
Class ReliableFile

java.lang.Object
  extended by org.eclipse.osgi.framework.internal.reliablefile.ReliableFile

public class ReliableFile
extends java.lang.Object

ReliableFile class used by ReliableFileInputStream and ReliableOutputStream. This class encapsulates all the logic for reliable file support.


Field Summary
static int GENERATION_LATEST
          Use the last generation of the file
static int GENERATIONS_INFINITE
          Keep infinite backup files
static int OPEN_BEST_AVAILABLE
          Open mask.
static int OPEN_FAIL_ON_PRIMARY
          Open mask.
static java.lang.String PROP_MAX_BUFFER
          Property to set the maximum size of a file that will be buffered.
static java.lang.String PROP_MAX_GENERATIONS
          The maximum number of generations to keep as backup files in case last generation file is determined to be invalid.
static java.lang.String PROP_OSGI_LOCKING
           
static java.lang.String tmpExt
          Extension of tmp file used during writing.
 
Method Summary
static void cleanupGenerations(java.io.File base)
          Delete any old excess generations of a given reliable file.
static boolean delete(java.io.File deleteFile)
          Delete the specified reliable file on the underlying file system.
static boolean exists(java.io.File file)
          Answers a boolean indicating whether or not the specified reliable file exists on the underlying file system.
static void fileUpdated(java.io.File file)
          Inform ReliableFile that a file has been updated outside of ReliableFile.
static java.lang.String[] getBaseFiles(java.io.File directory)
          Get a list of ReliableFile base names in a given directory.
 long lastModified()
          Returns the time that this ReliableFile was last modified.
static long lastModified(java.io.File file)
          Returns the time that the reliable file was last modified.
static int lastModifiedVersion(java.io.File file)
          Returns the a version number of a reliable managed file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN_BEST_AVAILABLE

public static final int OPEN_BEST_AVAILABLE
Open mask. Obtain the best data stream available. If the primary data contents are invalid (corrupt, missing, etc.), the data for a prior version may be used. An IOException will be thrown if a valid data content can not be determined. This is mutually exclusive with OPEN_FAIL_ON_PRIMARY.

See Also:
Constant Field Values

OPEN_FAIL_ON_PRIMARY

public static final int OPEN_FAIL_ON_PRIMARY
Open mask. Obtain only the data stream for the primary file where any other version will not be valid. This should be used for data streams that are managed as a group as a prior contents may not match the other group data. If the primary data is not invalid, a IOException will be thrown. This is mutually exclusive with OPEN_BEST_AVAILABLE.

See Also:
Constant Field Values

GENERATION_LATEST

public static final int GENERATION_LATEST
Use the last generation of the file

See Also:
Constant Field Values

GENERATIONS_INFINITE

public static final int GENERATIONS_INFINITE
Keep infinite backup files

See Also:
Constant Field Values

tmpExt

public static final java.lang.String tmpExt
Extension of tmp file used during writing. A reliable file with this extension should never be directly used.

See Also:
Constant Field Values

PROP_MAX_BUFFER

public static final java.lang.String PROP_MAX_BUFFER
Property to set the maximum size of a file that will be buffered. When calculating a ReliableFile checksum, if the file is this size or small, ReliableFile will read the file contents into a BufferedInputStream and reset the buffer to avoid having to read the data from the media twice. Since this method require memory for storage, it is limited to this size. The default maximum is 128-KBytes.

See Also:
Constant Field Values

PROP_MAX_GENERATIONS

public static final java.lang.String PROP_MAX_GENERATIONS
The maximum number of generations to keep as backup files in case last generation file is determined to be invalid.

See Also:
Constant Field Values

PROP_OSGI_LOCKING

public static final java.lang.String PROP_OSGI_LOCKING
See Also:
BasicLocation.PROP_OSGI_LOCKING, Constant Field Values
Method Detail

exists

public static boolean exists(java.io.File file)
Answers a boolean indicating whether or not the specified reliable file exists on the underlying file system. This call only returns if a file exists and not if the file contents are valid.

Parameters:
file - returns true if the specified reliable file exists; otherwise false is returned
Returns:
true if the specified reliable file exists, false otherwise.

lastModified

public static long lastModified(java.io.File file)
Returns the time that the reliable file was last modified. Only the time of the last file generation is returned.

Parameters:
file - the file to determine the time of.
Returns:
time the file was last modified (see java.io.File.lastModified()).

lastModified

public long lastModified()
Returns the time that this ReliableFile was last modified. This method is only valid after requesting an input stream and the time of the actual input file is returned.

Returns:
time the file was last modified (see java.io.File.lastModified()) or 0L if an input stream is not open.

lastModifiedVersion

public static int lastModifiedVersion(java.io.File file)
Returns the a version number of a reliable managed file. The version can be expected to be unique for each successful file update.

Parameters:
file - the file to determine the version of.
Returns:
a unique version of this current file. A value of -1 indicates the file does not exist or an error occurred.

delete

public static boolean delete(java.io.File deleteFile)
Delete the specified reliable file on the underlying file system.

Parameters:
deleteFile - the reliable file to delete
Returns:
true if the specified reliable file was deleted, false otherwise.

getBaseFiles

public static java.lang.String[] getBaseFiles(java.io.File directory)
                                       throws java.io.IOException
Get a list of ReliableFile base names in a given directory. Only files with a valid ReliableFile generation are included.

Parameters:
directory - the directory to inquire.
Returns:
an array of ReliableFile names in the directory.
Throws:
java.io.IOException - if an error occurs.

cleanupGenerations

public static void cleanupGenerations(java.io.File base)
Delete any old excess generations of a given reliable file.

Parameters:
base - realible file.

fileUpdated

public static void fileUpdated(java.io.File file)
Inform ReliableFile that a file has been updated outside of ReliableFile.

Parameters:
file -


Copyright © 2007-2012 FuseSource, Corp.. All Rights Reserved.