Methods Summary |
---|
private void | findLatest()Looks through the list of zips and sets the one with the biggest version number
int biggest = 0;
for(int i = 0; i < zipsAndNumbers.length; i++)
{
int curr = zipsAndNumbers[i].num;
if(curr > biggest)
{
biggest = curr;
latestVersion = zipsAndNumbers[i];
LoggerHelper.fine(zipsAndNumbers[i].zip.toString() + " newest backup so far...");
}
}
|
private void | findZips()Looks through the backups directory and assembles
a list of all backup files found.
File[] zips = dir.listFiles(new ZipFilenameFilter());
int len = 0;
if(zips != null)
len = zips.length;
zipsAndNumbers = new ZipFileAndNumber[len];
for(int i = 0; i < len; i++)
{
zipsAndNumbers[i] = new ZipFileAndNumber(zips[i]);
}
|
java.io.File | latest()
if(latestVersion == null)
throw new BackupWarningException("backup-res.NoBackupFiles", dir);
return latestVersion.zip;
|
public static void | main(java.lang.String[] args)
///////////////////////////////////////////////////////////////////////////////
try
{
File f = new File("c:/tmp/test");
BackupFilenameManager mgr = new BackupFilenameManager(f);
File fnew = mgr.next();
System.out.println("Next backup file: " + fnew);
File fold = mgr.latest();
System.out.println("Latest backup file: " + fold);
}
catch(Exception e)
{
e.printStackTrace();
}
|
java.io.File | next()
int newVersionNum = 1;
if(latestVersion != null)
newVersionNum = latestVersion.num + 1;
String suffix = padWithLeadingZeroes(newVersionNum);
return new File(dir, Constants.BACKUP_FILENAME_ROOT + suffix + ".zip");
|
private java.lang.String | padWithLeadingZeroes(int num)Convert the array of zip filenames into an array of the number suffixes.
if(num < 10)
return "0000" + num;
if(num < 100)
return "000" + num;
if(num < 1000)
return "00" + num;
if(num < 10000)
return "0" + num;
if(num < 100000)
return "" + num;
throw new BackupException("Latest version >= 100,000. Delete some backup files.");
|