Source Code Cross Referenced for DirectoryWalker.java in  » Test-Coverage » NoUnit » net » firstpartners » nounit » utility » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Test Coverage » NoUnit » net.firstpartners.nounit.utility 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.firstpartners.nounit.utility;
002:
003:        /**
004:         * Title:        NoUnit - Identify Classes that are not being unit Tested
005:         *
006:         * Copyright (C) 2001  Paul Browne , FirstPartners.net
007:         *
008:         *
009:         * This program is free software; you can redistribute it and/or 
010:         * modify it under the terms of the GNU General Public License
011:         * as published by the Free Software Foundation; either version 2
012:         * of the License, or (at your option) any later version.
013:         *
014:         * This program is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017:         * GNU General Public License for more details.
018:         *
019:         * You should have received a copy of the GNU General Public License
020:         * along with this program; if not, write to the Free Software
021:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
022:         *
023:         * @author Paul Browne
024:         * @version 0.7
025:         */
026:
027:        import java.io.File;
028:        import java.io.IOException;
029:        import java.util.HashSet;
030:
031:        /**
032:         * 'Walks' the directory structure and returns files found 
033:         * (including those in sub folders)
034:         */
035:        public class DirectoryWalker {
036:
037:            /**
038:             * Get all the files in the starting directory (and sub dirs)
039:             * No filter
040:             * @param startingDirectory
041:             * @return filesFound (as HashSet)
042:             * @exception java.io.IOException
043:             */
044:            public static HashSet getFiles(String startDir) throws IOException {
045:                return getFiles(startDir, null);
046:            }
047:
048:            /**
049:             * Get all the files in the starting directory (but NOT sub dirs).
050:             * returns only files whose names end with the mask passed in
051:             * @param startingDirectory
052:             * @return filesFound (as HashSet)
053:             * @exception java.io.IOException
054:             */
055:            public static HashSet getFiles(String startingDirectory, String mask)
056:                    throws java.io.IOException {
057:
058:                HashSet filesFound = new HashSet();
059:
060:                //Check that this is a valid directory
061:                File startDir = new File(startingDirectory);
062:                if (!startDir.isDirectory()) {
063:                    String msg = startingDirectory
064:                            + " was not a valid directory";
065:                    throw new java.io.IOException(msg);
066:                }
067:
068:                //Get the contents of the current directory
069:                String[] this DirContents = startDir.list();
070:
071:                if (this DirContents != null) {
072:
073:                    //Now loop through , apply filter , or adding them to list of 
074:                    //sub dirs
075:                    for (int a = 0; a < this DirContents.length; a++) {
076:
077:                        File tmp = new File(startingDirectory,
078:                                this DirContents[a]);
079:
080:                        //Skip directories
081:                        if (tmp.isFile()) {
082:                            if ((null == mask)
083:                                    || (tmp.toString().endsWith(mask))) {
084:                                filesFound.add(tmp.toString());
085:                            }
086:                        }
087:                    }
088:                }
089:                return filesFound;
090:            }
091:
092:            /**
093:             * Get all the Directories in the starting directory (and sub dirs)
094:             * returns only files ending this the filename
095:             * @param startingDirectory
096:             * @return filesFound (as HashSet)
097:             * @exception java.io.IOException
098:             */
099:            public static HashSet getDirs(String startingDirectory)
100:                    throws java.io.IOException {
101:
102:                //Check that this is a valid directory
103:                File startDir = new File(startingDirectory);
104:                if (!startDir.isDirectory()) {
105:                    throw new java.io.IOException(startingDirectory
106:                            + " was not a valid directory");
107:                }
108:
109:                //Add the current directory to the output list
110:                HashSet dirsFound = new HashSet();
111:                dirsFound.add(startingDirectory);
112:
113:                //Get the contents of the current directory
114:                String[] this DirContents = startDir.list();
115:
116:                if (this DirContents != null) {
117:                    //Now loop through , apply filter , or adding them to list of sub dirs
118:                    for (int a = 0; a < this DirContents.length; a++) {
119:
120:                        //Get Handle to (full) file (inc path)  
121:                        File tmpFile = new File(startingDirectory,
122:                                this DirContents[a]);
123:
124:                        //We're only interested in directories
125:                        if (tmpFile.isDirectory()) {
126:
127:                            //Add this to the directory list
128:                            dirsFound.add(tmpFile.toString());
129:
130:                            //Now Do Recursive Call (to this method)if Directory
131:                            File tmpSubDir = new File(startingDirectory,
132:                                    this DirContents[a]);
133:                            HashSet subDirFilesFound = DirectoryWalker
134:                                    .getDirs(tmpSubDir.toString());
135:                            dirsFound.addAll(subDirFilesFound);
136:                        }
137:                    }
138:                }
139:                return dirsFound;
140:            }
141:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.