KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: InfoFileFilter.java,v 1.11 2006/10/30 21:14:54 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 InfoFileFilter implements FilenameFilter JavaDoc {
16
17     /**
18      * Accept files of this format:
19      * je.info.#
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 filePrefix = tokenizer.nextToken();
27             String JavaDoc fileSuffix = tokenizer.nextToken();
28             String JavaDoc repeat = tokenizer.nextToken();
29
30             // check the length and the suffix
31
if (filePrefix.equals("je") && fileSuffix.equals("info")) {
32                 // The last part should be a number
33
try {
34                     Integer.parseInt(repeat);
35                     ok = true;
36                 } catch (NumberFormatException JavaDoc e) {
37                     ok = false;
38                 }
39             }
40         }
41
42         return ok;
43     }
44 }
45
46
Popular Tags