Source Code Cross Referenced for FileUtil.java in  » Installer » IzPack » com » izforge » izpack » util » 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 » Installer » IzPack » com.izforge.izpack.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         *
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         *
007:         * Copyright 2005 Marc Eppelmann
008:         *
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         *
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:        package com.izforge.izpack.util;
022:
023:        import java.io.BufferedReader;
024:        import java.io.File;
025:        import java.io.FileNotFoundException;
026:        import java.io.FileReader;
027:        import java.io.FilenameFilter;
028:        import java.io.IOException;
029:
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:
033:        import java.net.URL;
034:
035:        /**
036:         * Provides general global file utility methods
037:         *
038:         * @author marc.eppelmann
039:         */
040:        public class FileUtil {
041:            //~ Constructors ***********************************************************************
042:
043:            /**
044:             * Creates a new FileUtil object.
045:             */
046:            public FileUtil() {
047:            }
048:
049:            //~ Methods ****************************************************************************
050:
051:            /** 
052:             * Gets the content from a File as StringArray List.
053:             *
054:             * @param fileName A file to read from.
055:             *
056:             * @return List of individual line of the specified file. List may be empty but not
057:             *         null.
058:             *
059:             * @throws IOException
060:             */
061:            public static ArrayList getFileContent(String fileName)
062:                    throws IOException {
063:                ArrayList result = new ArrayList();
064:
065:                File aFile = new File(fileName);
066:
067:                if (!aFile.isFile()) {
068:                    //throw new IOException( fileName + " is not a regular File" );
069:                    return result; // None
070:                }
071:
072:                BufferedReader reader = null;
073:
074:                try {
075:                    reader = new BufferedReader(new FileReader(aFile));
076:                } catch (FileNotFoundException e1) {
077:                    // TODO handle Exception
078:                    e1.printStackTrace();
079:
080:                    return result;
081:                }
082:
083:                String aLine = null;
084:
085:                while ((aLine = reader.readLine()) != null) {
086:                    result.add(aLine + "\n");
087:                }
088:
089:                reader.close();
090:
091:                return result;
092:            }
093:
094:            /** 
095:             * Searches case sensitively, and returns true if the given SearchString occurs in the
096:             * first File with the given Filename.
097:             *
098:             * @param aFileName A files name
099:             * @param aSearchString the string search for
100:             *
101:             * @return true if found in the file otherwise false
102:             */
103:            public static boolean fileContains(String aFileName,
104:                    String aSearchString) {
105:                return (fileContains(aFileName, aSearchString, false));
106:            }
107:
108:            /** 
109:             * Tests if the given File contains the given Search String
110:             *
111:             * @param aFileName A files name
112:             * @param aSearchString the String to search for
113:             * @param caseInSensitiveSearch If false the Search is casesensitive
114:             *
115:             * @return true if found in the file otherwise false
116:             */
117:            public static boolean fileContains(String aFileName,
118:                    String aSearchString, boolean caseInSensitiveSearch) {
119:                boolean result = false;
120:
121:                String searchString = caseInSensitiveSearch ? aSearchString
122:                        .toLowerCase() : aSearchString;
123:
124:                ArrayList fileContent = new ArrayList();
125:
126:                try {
127:                    fileContent = getFileContent(aFileName);
128:                } catch (IOException e) {
129:                    // TODO handle Exception
130:                    e.printStackTrace();
131:                }
132:
133:                Iterator linesIter = fileContent.iterator();
134:
135:                while (linesIter.hasNext()) {
136:                    String currentline = (String) linesIter.next();
137:
138:                    if (caseInSensitiveSearch) {
139:                        currentline = currentline.toLowerCase();
140:                    }
141:
142:                    if (currentline.indexOf(searchString) > -1) {
143:                        result = true;
144:
145:                        break;
146:                    }
147:                }
148:
149:                return result;
150:            }
151:
152:            /**
153:             * Gets file date and time.
154:             *
155:             * @param   url     The URL of the file for which date and time will be returned.
156:             * @return  Returns long value which is the date and time of the file. If any error
157:             *          occures returns -1 (=no file date and time available).
158:             */
159:            public static long getFileDateTime(URL url) {
160:                if (url == null)
161:                    return -1;
162:
163:                String fileName = url.getFile();
164:                if (fileName.charAt(0) == '/' || fileName.charAt(0) == '\\')
165:                    fileName = fileName.substring(1, fileName.length());
166:
167:                try {
168:                    File file = new File(fileName);
169:                    // File name must be a file or a directory.
170:                    if (!file.isDirectory() && !file.isFile()) {
171:                        return -1;
172:                    }
173:
174:                    return file.lastModified();
175:                } catch (java.lang.Exception e) { // Trap all Exception based exceptions and return -1.
176:                    return -1;
177:                }
178:            }
179:
180:            public static String[] getFileNames(String dirPath)
181:                    throws Exception {
182:                return getFileNames(dirPath, null);
183:            }
184:
185:            public static String[] getFileNames(String dirPath,
186:                    FilenameFilter fileNameFilter) throws Exception {
187:                String fileNames[] = null;
188:                File dir = new File(dirPath);
189:                if (dir.isDirectory()) {
190:                    if (fileNameFilter != null) {
191:                        fileNames = dir.list(fileNameFilter);
192:                    } else {
193:                        fileNames = dir.list();
194:                    }
195:                }
196:                return fileNames;
197:            }
198:
199:            /** 
200:             * Test main
201:             *
202:             * @param args
203:             */
204:            public static void main(String[] args) {
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.