Source Code Cross Referenced for JarHelper.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.util;
018:
019:        import java.io.File;
020:        import java.io.FileFilter;
021:        import java.io.FileNotFoundException;
022:        import java.io.FileOutputStream;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.io.OutputStream;
026:        import java.util.Enumeration;
027:        import java.util.jar.JarEntry;
028:        import java.util.jar.JarFile;
029:
030:        /**
031:         * @author <a href="mailto:weaver@apache.org">Scott T. Weaver </a>
032:         * 
033:         * Creates a a temp directory to which a JarFile is expanded and can be
034:         * manipulated. All operations are performed by an internal instance of
035:         * {@link DirectoryHelper}.
036:         *  
037:         */
038:        public class JarHelper extends AbstractFileSystemHelper implements 
039:                FileSystemHelper {
040:            protected JarFile jarFile;
041:            protected DirectoryHelper dirHelper;
042:            protected File file;
043:            private boolean deleteOnClose;
044:            protected File jarRoot;
045:
046:            /**
047:             * 
048:             * @param jarFile
049:             * @throws IOException
050:             */
051:            public JarHelper(File file, boolean deleteOnClose)
052:                    throws IOException {
053:                this .jarFile = new JarFile(file);
054:                this .deleteOnClose = deleteOnClose;
055:                this .file = file;
056:                String tmpDirPath = System.getProperty("java.io.tmpdir");
057:                File tmpDir = new File(tmpDirPath);
058:                jarRoot = null;
059:
060:                jarRoot = new File(tmpDir, "jetspeed-jar-tmp/" + file.getName());
061:
062:                if (!jarRoot.exists()) {
063:                    jarRoot.mkdirs();
064:                }
065:                jarRoot.deleteOnExit();
066:
067:                Enumeration entries = this .jarFile.entries();
068:                while (entries.hasMoreElements()) {
069:                    JarEntry jarEntry = (JarEntry) entries.nextElement();
070:                    String name = jarEntry.getName();
071:                    if (jarEntry.isDirectory()) {
072:                        File newDir = new File(jarRoot, name);
073:                        newDir.mkdir();
074:                        newDir.deleteOnExit();
075:                    } else {
076:                        copyEntryToFile(jarFile, jarRoot, jarEntry);
077:                    }
078:                }
079:
080:                dirHelper = new DirectoryHelper(jarRoot);
081:            }
082:
083:            /**
084:             * <p>
085:             * copyEntryToFile
086:             * </p>
087:             * 
088:             * @param jarFile
089:             * @param jarRoot
090:             * @param jarEntry
091:             * @throws IOException
092:             * @throws FileNotFoundException
093:             */
094:            protected void copyEntryToFile(JarFile jarFile, File jarRoot,
095:                    JarEntry jarEntry) throws IOException,
096:                    FileNotFoundException {
097:                String name = jarEntry.getName();
098:                File file = new File(jarRoot, name);
099:                if (!file.getParentFile().exists()) {
100:                    file.getParentFile().mkdirs();
101:                    file.getParentFile().deleteOnExit();
102:                }
103:                file.createNewFile();
104:                file.deleteOnExit();
105:
106:                InputStream is = null;
107:                OutputStream os = null;
108:                try {
109:                    is = jarFile.getInputStream(jarEntry);
110:                    os = new FileOutputStream(file);
111:
112:                    byte[] buf = new byte[1024];
113:                    int len;
114:                    while ((len = is.read(buf)) > 0) {
115:                        os.write(buf, 0, len);
116:                    }
117:
118:                } finally {
119:                    if (is != null) {
120:                        is.close();
121:                    }
122:
123:                    if (os != null) {
124:                        os.close();
125:                    }
126:                }
127:            }
128:
129:            /**
130:             * <p>
131:             * copyFrom
132:             * </p>
133:             *
134:             * @param directory
135:             * @param fileFilter
136:             * @throws IOException
137:             */
138:            public void copyFrom(File directory, FileFilter fileFilter)
139:                    throws IOException {
140:                dirHelper.copyFrom(directory, fileFilter);
141:            }
142:
143:            /**
144:             * <p>
145:             * copyFrom
146:             * </p>
147:             * 
148:             * @see org.apache.jetspeed.util.FileSystemHelper#copyFrom(java.io.File)
149:             * @param directory
150:             * @throws IOException
151:             */
152:            public void copyFrom(File directory) throws IOException {
153:                dirHelper.copyFrom(directory);
154:            }
155:
156:            /**
157:             * <p>
158:             * getRootDirectory
159:             * </p>
160:             * 
161:             * @see org.apache.jetspeed.util.FileSystemHelper#getRootDirectory()
162:             * @return
163:             */
164:            public File getRootDirectory() {
165:                return dirHelper.getRootDirectory();
166:            }
167:
168:            /**
169:             * <p>
170:             * remove
171:             * </p>
172:             * 
173:             * @see org.apache.jetspeed.util.FileSystemHelper#remove()
174:             * @return
175:             */
176:            public boolean remove() {
177:                return dirHelper.remove();
178:            }
179:
180:            /**
181:             * <p>
182:             * close
183:             * </p>
184:             * 
185:             * @throws IOException
186:             * 
187:             * @see org.apache.jetspeed.util.FileSystemHelper#close()
188:             *  
189:             */
190:            public void close() throws IOException {
191:                jarFile.close();
192:                if (deleteOnClose) {
193:                    // remove all temporary files
194:                    dirHelper.remove();
195:                }
196:
197:                dirHelper.close();
198:            }
199:
200:            /**
201:             * <p>
202:             * getSourcePath
203:             * </p>
204:             * 
205:             * @see org.apache.jetspeed.util.FileSystemHelper#getSourcePath()
206:             * @return
207:             */
208:            public String getSourcePath() {
209:                return file.getAbsolutePath();
210:            }
211:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.