public abstract class BackupPolicy
extends java.lang.Object
Constructor and Description |
---|
BackupPolicy() |
Modifier and Type | Method and Description |
---|---|
void |
backup(java.io.File file)
Backup a file by renaming it to have have a new name of
old-name~n where n is chosen to be higher than
any other for which a candidate new filename exists.
|
java.io.OutputStream |
backupAndOpenStream(java.io.File file)
Backup a file and open a new output stream to the file.
|
java.io.Writer |
backupAndOpenWriter(java.io.File file)
Backup a file and open a new Writer to the file.
|
java.io.Writer |
backupAndOpenWriter(java.io.File file,
java.lang.String charsetName)
Backup a file and open a new Writer to the file with specified charset.
|
void |
backupAndRename(java.io.File source,
java.io.File target)
Rename (or move) the source file to the target name.
|
abstract int |
getNumBackupsToKeep(java.io.File file)
Get the number of backup files to keep for a particular file.
|
abstract boolean |
isBackupRequired(java.io.File file)
Determine if backups are enabled for this file.
|
static BackupPolicy |
noBackups()
Get a BackupPolicy object which does no backups for any files.
|
static BackupPolicy |
simpleBackups(int n)
Get a BackupPolicy object which does a set number of backups for all files.
|
public void backup(java.io.File file) throws java.io.IOException, java.lang.SecurityException
file
- the file to be backed upjava.io.IOException
- if there is a problem renaming the filejava.lang.SecurityException
- if the file could not be backed up because
permission was not given by the security managergetNumBackupsToKeep(java.io.File)
,
isBackupRequired(java.io.File)
public void backupAndRename(java.io.File source, java.io.File target) throws java.io.IOException, java.lang.SecurityException
source
- The file to be backed up.
It must be a file (not a directory) which is deleteable.target
- The new name for the file. It must be a file (not a directory)
which is will be at a writable location.java.io.IOException
- if there is a problem renaming the file.
This may happen if the source is a
directory, the source file is not writable, or the rename operation
fails. In all cases, the rename operation was not successful.java.lang.SecurityException
- if the backup operation fails because of a security
constraint.backup(File)
public java.io.Writer backupAndOpenWriter(java.io.File file) throws java.io.IOException, java.lang.SecurityException
file
- the file to be backed up, and for which a new Writer will be openedjava.io.IOException
- if there is a problem backing up the file or creating
the new writer objectjava.lang.SecurityException
- if the operation could not be completed because
of a security constraintpublic java.io.Writer backupAndOpenWriter(java.io.File file, java.lang.String charsetName) throws java.io.IOException, java.lang.SecurityException
file
- the file to be backed up, and for which a new Writer will be openedcharsetName
- Create an OutputStreamWriter that uses the named charsetjava.io.IOException
- if there is a problem backing up the file or creating
the new writer objectjava.lang.SecurityException
- if the operation could not be completed because
of a security constraintpublic java.io.OutputStream backupAndOpenStream(java.io.File file) throws java.io.IOException, java.lang.SecurityException
file
- the file to be backed up, and for which a new output stream will be openedjava.io.IOException
- if there is a problem backing up the file or creating
the new output streamjava.lang.SecurityException
- if the operation could not be completed because
of a security constraintpublic abstract int getNumBackupsToKeep(java.io.File file)
file
- the file for which to check how many backups are requiredbackup(java.io.File)
public abstract boolean isBackupRequired(java.io.File file)
file
- the file for which to check if backups are enabledpublic static BackupPolicy noBackups()
public static BackupPolicy simpleBackups(int n)
n
- The number of backups to kept for each fileCopyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.