5 public class BackupFilenameParts
19 public BackupFilenameParts(File file, String base, String template, int digits)
21 this(file.getName(), base, template, digits);
24 public BackupFilenameParts(String filename, String base, String template,
27 this.isBackupFile = false;
29 // calculate minimum length of a backup filename
30 int minlength = base.length() + template.length()
31 - BackupFiles.NUM_PLACEHOLDER.length() + digits ;
33 if (!(filename.startsWith(base) && filename.length() >= minlength))
39 int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
40 String templateStart = template;
41 String templateEnd = "";
42 if (numcharstart > -1)
44 templateStart = template.substring(0, numcharstart);
45 templateEnd = template.substring(
46 numcharstart + BackupFiles.NUM_PLACEHOLDER.length());
49 int startLength = base.length() + templateStart.length();
50 int endLength = templateEnd.length();
51 String numString = filename.substring(startLength,
52 filename.length() - endLength);
54 if (filename.length() >= startLength + digits + endLength
55 && filename.startsWith(base + templateStart)
56 && filename.endsWith(templateEnd)
57 && numString.matches("[0-9]+"))
60 this.templateStart = templateStart;
61 this.num = Integer.parseInt(numString);
63 this.templateStart = templateStart;
64 this.templateEnd = templateEnd;
65 this.isBackupFile = true;
70 public boolean isBackupFile()
72 return this.isBackupFile;