Source Code Cross Referenced for FileUtils.java in  » Test-Coverage » GroboUtils » net » sourceforge » groboutils » util » io » v1 » 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 » GroboUtils » net.sourceforge.groboutils.util.io.v1 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FileUtils.java - 0.9.0     12/13/2000 - 15:41:52
003:         *
004:         * Copyright (C) 2000,,2003 2002 Matt Albrecht
005:         * groboclown@users.sourceforge.net
006:         * http://groboutils.sourceforge.net
007:         *
008:         *  Permission is hereby granted, free of charge, to any person obtaining a
009:         *  copy of this software and associated documentation files (the "Software"),
010:         *  to deal in the Software without restriction, including without limitation
011:         *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
012:         *  and/or sell copies of the Software, and to permit persons to whom the
013:         *  Software is furnished to do so, subject to the following conditions:
014:         *
015:         *  The above copyright notice and this permission notice shall be included in
016:         *  all copies or substantial portions of the Software.
017:         *
018:         *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019:         *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020:         *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
021:         *  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022:         *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023:         *  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024:         *  DEALINGS IN THE SOFTWARE.
025:         */
026:
027:        package net.sourceforge.groboutils.util.io.v1;
028:
029:        import java.util.Hashtable;
030:        import java.util.Vector;
031:        import java.util.Stack;
032:
033:        import java.io.IOException;
034:        import java.io.FileNotFoundException;
035:        import java.io.File;
036:        import java.io.FilenameFilter;
037:        import java.io.BufferedOutputStream;
038:        import java.io.BufferedInputStream;
039:        import java.io.FileOutputStream;
040:        import java.io.FileInputStream;
041:
042:        /**
043:         * Simple and common file operations in a Utility class.
044:         *
045:         *
046:         * @author   Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
047:         * @since    December 13, 2000
048:         * @version  $Date: 2003/05/19 20:31:47 $
049:         */
050:        public class FileUtils {
051:            //---------------------------------------------------------------------
052:            // Public Static Fields
053:
054:            //---------------------------------------------------------------------
055:            // Protected Static Fields
056:
057:            protected static FileUtils s_instance = new FileUtils();
058:
059:            //---------------------------------------------------------------------
060:            // Private Static Fields
061:
062:            //---------------------------------------------------------------------
063:            // Public Fields
064:
065:            //---------------------------------------------------------------------
066:            // Protected Fields
067:
068:            //---------------------------------------------------------------------
069:            // Private Fields
070:
071:            //---------------------------------------------------------------------
072:            // Constructors
073:
074:            /**
075:             * Default Constructor
076:             */
077:            protected FileUtils() {
078:                // do nothing
079:            }
080:
081:            //---------------------------------------------------------------------
082:            // Public Static Methods
083:
084:            public static FileUtils getInstance() {
085:                return s_instance;
086:            }
087:
088:            //---------------------------------------------------------------------
089:            // Public Methods
090:
091:            /**
092:             * @param source the source file to copy
093:             * @param dir the target directory to copy the sourcefile into: the
094:             *     name will remain the same.
095:             */
096:            public void copyFileToDirectory(File source, File dir)
097:                    throws IOException {
098:                copyFileToFile(source, new File(dir, source.getName()));
099:            }
100:
101:            /**
102:             * @param source the source file to copy from.
103:             * @param target the target file to copy to.
104:             */
105:            public void copyFileToFile(File source, File target)
106:                    throws IOException {
107:                FileInputStream fis = null;
108:                FileOutputStream fos = null;
109:                BufferedInputStream bis = null;
110:                BufferedOutputStream bos = null;
111:
112:                try {
113:                    fis = new FileInputStream(source);
114:                    fos = new FileOutputStream(target);
115:                    bis = new BufferedInputStream(fis);
116:                    bos = new BufferedOutputStream(fos);
117:
118:                    byte buffer[] = new byte[4096];
119:                    int size = bis.read(buffer, 0, 4096);
120:                    while (size > 0) {
121:                        bos.write(buffer, 0, size);
122:                        size = bis.read(buffer, 0, 4096);
123:                    }
124:                } finally {
125:                    if (bis != null)
126:                        bis.close();
127:                    if (bos != null)
128:                        bos.close();
129:                    if (fis != null)
130:                        fis.close();
131:                    if (fos != null)
132:                        fos.close();
133:                }
134:            }
135:
136:            /**
137:             * Recursively descends into the base directory, looking for all files
138:             * that pass the filter.
139:             *
140:             * @param baseDir the base directory to start the search.
141:             * @param filter the filename filter to search. If <tt>null</tt>, then
142:             *      all files are allowed.
143:             */
144:            public File[] findFileRecurse(File baseDir, FilenameFilter filter)
145:            //            throws IOException
146:            {
147:                if (baseDir == null) {
148:                    throw new IllegalArgumentException("no null arguments");
149:                }
150:                if (filter == null) {
151:                    filter = new AllFilenameFilter();
152:                }
153:
154:                Stack dirStack = new Stack();
155:                Vector files = new Vector();
156:
157:                dirStack.push(baseDir);
158:
159:                while (!dirStack.empty()) {
160:                    baseDir = (File) dirStack.pop();
161:                    String[] list = baseDir.list(filter);
162:                    for (int i = list.length; --i >= 0;) {
163:                        File f = new File(baseDir, list[i]);
164:                        if (f.isDirectory()) {
165:                            dirStack.push(f);
166:                        } else if (f.isFile()) {
167:                            files.addElement(f);
168:                        }
169:                    }
170:                }
171:
172:                File[] flist = new File[files.size()];
173:                files.copyInto(flist);
174:                return flist;
175:            }
176:
177:            //---------------------------------------------------------------------
178:            // Protected Methods
179:
180:            //---------------------------------------------------------------------
181:            // Private Methods
182:
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.