KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdo > tools > enhancer > GrepFile


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdo.tools.enhancer;
13
14 import java.io.*;
15 import java.util.*;
16
17
18 public class GrepFile {
19     private FileFilter fileFilter;
20
21     private HashMap jdoFiles = new HashMap();
22
23
24     public GrepFile(ArrayList dirs) throws IOException{
25         for (Iterator iterator = dirs.iterator();iterator.hasNext();) {
26             File file = (File) iterator.next();
27             searchInDir(file.toString(),true);
28         }
29     }
30
31     public Set getJdoFiles(){
32         return jdoFiles.keySet();
33     }
34
35
36
37     private void searchInDir(String JavaDoc startDir, boolean recurse) throws IOException {
38         fileFilter = new FileFilter() {
39             public boolean accept(File f) {
40                 if (f.isDirectory()){
41                     return true;
42                 } else if (f.getName().endsWith(".class")){
43                     return true;
44                 } else {
45                     return false;
46                 }
47             }
48         };
49
50         searchInDir_aux(new File(startDir), recurse);
51     }
52
53     private void searchInDir_aux(File dir, boolean recurse) throws IOException {
54         File[] contents = dir.listFiles(fileFilter);
55         for (int i=0; i<contents.length; i++) {
56             File fileToCheck = contents[i];
57             if (fileToCheck.toString().endsWith(".class")){
58                 jdoFiles.put(fileToCheck.toString(),"");
59             } else if (recurse) {
60                 searchInDir_aux(fileToCheck, recurse);
61             }
62         }
63     }
64 }
65
66
67
68
69
70
71
Popular Tags