1 8 9 package com.sleepycat.je.log; 10 11 import java.io.File ; 12 import java.io.FilenameFilter ; 13 import java.util.StringTokenizer ; 14 15 18 class JEFileFilter implements FilenameFilter { 19 String [] suffix; 20 long minFileNumber = 0; 21 long maxFileNumber = -1; 22 23 JEFileFilter(String [] suffix) { 24 this.suffix = suffix; 25 } 26 27 31 JEFileFilter(String [] suffix, long maxFileNumber) { 32 this.suffix = suffix; 33 this.maxFileNumber = maxFileNumber; 34 } 35 36 42 JEFileFilter(String [] suffix, long minFileNumber, long maxFileNumber) { 43 this.suffix = suffix; 44 this.minFileNumber = minFileNumber; 45 this.maxFileNumber = maxFileNumber; 46 } 47 48 private boolean matches(String fileSuffix) { 49 for (int i = 0; i < suffix.length; i++) { 50 if (fileSuffix.equalsIgnoreCase(suffix[i])) { 51 return true; 52 } 53 } 54 return false; 55 } 56 57 60 public boolean accept(File dir, String name) { 61 boolean ok = false; 62 StringTokenizer tokenizer = new StringTokenizer (name, "."); 63 64 int nTokens = tokenizer.countTokens(); 65 if (nTokens == 2 || nTokens == 3) { 66 boolean hasVersion = (nTokens == 3); 67 String fileNumber = tokenizer.nextToken(); 68 String fileSuffix = "." + tokenizer.nextToken(); 69 String fileVersion = (hasVersion ? tokenizer.nextToken() : null); 70 71 72 if ((fileNumber.length() == 8) && 73 matches(fileSuffix)) { 74 76 77 try { 78 long fileNum = Long.parseLong(fileNumber, 16); 79 if (fileNum < minFileNumber) { 80 ok = false; 81 } else if ((fileNum <= maxFileNumber) || 82 (maxFileNumber == -1)) { 83 ok = true; 84 } 85 } catch (NumberFormatException e) { 86 ok = false; 87 } 88 if (hasVersion) { 89 try { 90 Integer.parseInt(fileVersion); 91 ok = true; 92 } catch (NumberFormatException e) { 93 ok = false; 94 } 95 } 96 } 97 } 98 99 return ok; 100 } 101 } 102 103 | Popular Tags |