5 public class BackupFilenameParts
21 public BackupFilenameParts(File file, String base, String template, int digits,
24 this(file.getName(), base, template, digits, extension);
27 public BackupFilenameParts(String filename, String base, String template,
28 int digits, String extension)
30 this.isBackupFile = false;
32 // calculate minimum length of a backup filename
33 int minlength = base.length() + template.length()
34 - BackupFiles.NUM_PLACEHOLDER.length() + digits
37 if (!(filename.startsWith(base) && filename.endsWith(extension)
38 && filename.length() >= minlength))
44 int numcharstart = template.indexOf(BackupFiles.NUM_PLACEHOLDER);
45 String templateStart = template;
46 String templateEnd = "";
47 if (numcharstart > -1)
49 templateStart = template.substring(0, numcharstart);
50 templateEnd = template.substring(
51 numcharstart + BackupFiles.NUM_PLACEHOLDER.length());
54 int startLength = base.length() + templateStart.length();
55 int endLength = templateEnd.length() + extension.length();
56 String numString = filename.substring(startLength,
57 filename.length() - endLength);
59 if (filename.length() >= startLength + digits + endLength
60 && filename.startsWith(base + templateStart)
61 && filename.endsWith(templateEnd + extension)
62 && numString.matches("[0-9]+"))
65 this.templateStart = templateStart;
66 this.num = Integer.parseInt(numString);
68 this.templateStart = templateStart;
69 this.templateEnd = templateEnd;
70 this.isBackupFile = true;
75 public boolean isBackupFile()
77 return this.isBackupFile;