%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.deployment.impl.JarExpander |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.deployment.impl; |
|
18 | ||
19 | import org.apache.jetspeed.util.DirectoryHelper; |
|
20 | ||
21 | import java.io.File; |
|
22 | import java.io.FileOutputStream; |
|
23 | import java.io.IOException; |
|
24 | import java.io.InputStream; |
|
25 | import java.io.OutputStream; |
|
26 | ||
27 | import java.util.Enumeration; |
|
28 | import java.util.jar.JarEntry; |
|
29 | import java.util.jar.JarFile; |
|
30 | ||
31 | /** |
|
32 | * JarExpander |
|
33 | * |
|
34 | * @author <a href="mailto:ate@douma.nu">Ate Douma </a> |
|
35 | * @version $Id: JarExpander.java 516448 2007-03-09 16:25:47Z ate $ |
|
36 | */ |
|
37 | 0 | public class JarExpander |
38 | { |
|
39 | public static void expand(File srcFile, File targetDir) throws IOException |
|
40 | { |
|
41 | 0 | if (targetDir.exists()) |
42 | { |
|
43 | 0 | DirectoryHelper cleanup = new DirectoryHelper(targetDir); |
44 | 0 | cleanup.remove(); |
45 | 0 | cleanup.close(); |
46 | } |
|
47 | ||
48 | 0 | targetDir.mkdirs(); |
49 | 0 | JarFile jarFile = new JarFile(srcFile); |
50 | ||
51 | try |
|
52 | { |
|
53 | 0 | Enumeration entries = jarFile.entries(); |
54 | ||
55 | 0 | InputStream is = null; |
56 | 0 | OutputStream os = null; |
57 | ||
58 | 0 | byte[] buf = new byte[1024]; |
59 | int len; |
|
60 | ||
61 | 0 | while (entries.hasMoreElements()) |
62 | { |
|
63 | 0 | JarEntry jarEntry = (JarEntry) entries.nextElement(); |
64 | 0 | String name = jarEntry.getName(); |
65 | 0 | File entryFile = new File(targetDir, name); |
66 | ||
67 | 0 | if (jarEntry.isDirectory()) |
68 | { |
|
69 | 0 | entryFile.mkdir(); |
70 | } |
|
71 | else |
|
72 | { |
|
73 | 0 | if (!entryFile.getParentFile().exists()) |
74 | { |
|
75 | 0 | entryFile.getParentFile().mkdirs(); |
76 | } |
|
77 | ||
78 | 0 | entryFile.createNewFile(); |
79 | ||
80 | try |
|
81 | { |
|
82 | 0 | is = jarFile.getInputStream(jarEntry); |
83 | 0 | os = new FileOutputStream(entryFile); |
84 | ||
85 | 0 | while ((len = is.read(buf)) > 0) |
86 | { |
|
87 | 0 | os.write(buf, 0, len); |
88 | } |
|
89 | } |
|
90 | finally |
|
91 | { |
|
92 | 0 | if (is != null) |
93 | { |
|
94 | 0 | is.close(); |
95 | } |
|
96 | ||
97 | 0 | if (os != null) |
98 | { |
|
99 | 0 | os.close(); |
100 | } |
|
101 | } |
|
102 | } |
|
103 | 0 | } |
104 | } |
|
105 | finally |
|
106 | { |
|
107 | 0 | if (jarFile != null) |
108 | { |
|
109 | 0 | jarFile.close(); |
110 | } |
|
111 | } |
|
112 | 0 | } |
113 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |