messageServerP
Class FileBackupper

java.lang.Object
  extended by messageServerP.FileBackupper
All Implemented Interfaces:
BackupperInterface

public class FileBackupper
extends java.lang.Object
implements BackupperInterface


Field Summary
private  java.io.File bkFile
           
 
Constructor Summary
FileBackupper(java.lang.String backupFilePath)
          Creates a backupper that writes on a single file.
 
Method Summary
private  void backupSingleData(ManagedUser usr, boolean remove)
          Adds or removes a single managed user from the backup.
 void backupUser(ManagedUser usr)
          Backups a new user adding it to the backup.
 void backupWholeData(java.util.List<ManagedUser> users)
          Backups the whole data given as arguments.
 java.lang.String getFilename()
           
 void removeBackuppedUser(ManagedUser usr)
          Removes a user from the backup.
 int restoreData(java.util.List<ManagedUser> restoredUsers)
           
 void updateUser(ManagedUser newUserStatus)
          Replaces the status of a user in the backup or adds the user if it is not backupped.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bkFile

private java.io.File bkFile
Constructor Detail

FileBackupper

public FileBackupper(java.lang.String backupFilePath)
Creates a backupper that writes on a single file.

Parameters:
backupFilePath - the backup file path.
Method Detail

getFilename

public java.lang.String getFilename()
Returns:
the name of the file this backup is using.

backupWholeData

public void backupWholeData(java.util.List<ManagedUser> users)
                     throws java.io.IOException
Description copied from interface: BackupperInterface
Backups the whole data given as arguments.

Specified by:
backupWholeData in interface BackupperInterface
Parameters:
users - the managed users to backup list.
Throws:
java.io.IOException - if a problem occurred while writing the backup.

backupSingleData

private void backupSingleData(ManagedUser usr,
                              boolean remove)
                       throws java.io.IOException
Adds or removes a single managed user from the backup.

Parameters:
usr - the user to add or remove (in the latter case, only the nickname is considered).
remove - true if the user must be removed, false otherwise.
Throws:
java.io.IOException - if the file could not be modified or read.

backupUser

public void backupUser(ManagedUser usr)
                throws java.io.IOException
Description copied from interface: BackupperInterface
Backups a new user adding it to the backup.

Specified by:
backupUser in interface BackupperInterface
Parameters:
usr - the user to backup
Throws:
java.io.IOException - if the user addition failed (broken old backup, not enought space left, ...).

removeBackuppedUser

public void removeBackuppedUser(ManagedUser usr)
                         throws java.io.IOException
Description copied from interface: BackupperInterface
Removes a user from the backup.

Specified by:
removeBackuppedUser in interface BackupperInterface
Parameters:
usr - the user to delete (only the nickname is considered).
Throws:
java.io.IOException - if the user deletion failed (user was not present, i/o error, ...)

restoreData

public int restoreData(java.util.List<ManagedUser> restoredUsers)
                throws java.io.IOException,
                       java.lang.ClassNotFoundException,
                       java.lang.IllegalArgumentException
Specified by:
restoreData in interface BackupperInterface
Parameters:
restoredUsers - an empty list where restored users will be stored.
Returns:
the number of restored users.
Throws:
java.io.IOException - if a problem occurred while reading the backup.
java.lang.ClassNotFoundException - if the read object class is not recognized.
java.lang.IllegalArgumentException - if the list given as argument is not empty or is null.

updateUser

public void updateUser(ManagedUser newUserStatus)
                throws java.io.IOException
Description copied from interface: BackupperInterface
Replaces the status of a user in the backup or adds the user if it is not backupped.

Specified by:
updateUser in interface BackupperInterface
Parameters:
newUserStatus - the new user status.
Throws:
java.io.IOException - if a problem occurred while reading or writing the backup (broken data, incorrect version).