KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > je > util > BadFileFilter


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: BadFileFilter.java,v 1.12 2006/10/30 21:14:53 bostic Exp $
7  */

8
9 package com.sleepycat.je.util;
10
11 import java.io.File JavaDoc;
12 import java.io.FilenameFilter JavaDoc;
13 import java.util.StringTokenizer JavaDoc;
14
15 public class BadFileFilter implements FilenameFilter JavaDoc {
16
17     /**
18      * Accept files of this format:
19      * <nnnnnnnn>.bad.<n>
20      */

21     public boolean accept(File JavaDoc dir, String JavaDoc name) {
22         boolean ok = false;
23         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(name, ".");
24         /* There should be two parts. */
25         if (tokenizer.countTokens() == 3) {
26             String JavaDoc fileNumber = tokenizer.nextToken();
27             String JavaDoc fileSuffix = tokenizer.nextToken();
28             String JavaDoc repeat = tokenizer.nextToken();
29
30             /* Check the length and the suffix. */
31             if ((fileNumber.length() == 8) &&
32                 (fileSuffix.equals("bad"))) {
33
34                 /* The first and third parts should be a numbers. */
35                 try {
36                     Integer.parseInt(fileNumber);
37                     Integer.parseInt(repeat);
38                     ok = true;
39                 } catch (NumberFormatException JavaDoc e) {
40                     ok = false;
41                 }
42             }
43         }
44
45         return ok;
46     }
47 }
48
49
Popular Tags