KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > VerifierUtils


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * VerifierUtils.java
26  *
27  * Created on September 9, 2002, 12:08 PM
28  */

29
30 package com.sun.enterprise.tools.verifier;
31
32 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
33
34 import java.io.BufferedOutputStream JavaDoc;
35 import java.io.File JavaDoc;
36 import java.io.FileOutputStream JavaDoc;
37 import java.io.IOException JavaDoc;
38 import java.io.InputStream JavaDoc;
39 import java.io.OutputStream JavaDoc;
40 import java.util.Enumeration JavaDoc;
41
42 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
43 import com.sun.enterprise.deployment.deploy.shared.JarArchiveFactory;
44 import com.sun.enterprise.deployment.archivist.Archivist;
45 import com.sun.enterprise.deployment.archivist.ArchivistFactory;
46 import com.sun.enterprise.util.shared.ArchivistUtils;
47
48 /**
49  * @author dochez
50  */

51 public class VerifierUtils {
52
53     public static void copyArchiveToDir(File JavaDoc source, File JavaDoc dest)
54             throws IOException JavaDoc {
55         AbstractArchive in = null;
56         try {
57             in =
58                     (new JarArchiveFactory()).openArchive(
59                             source.getAbsolutePath());
60             copyArchiveToDir(in, dest);
61         } finally {
62             if (in != null)
63                 in.close();
64         }
65     }
66
67     public static void copyArchiveToDir(AbstractArchive source, File JavaDoc dest)
68             throws IOException JavaDoc {
69         for (Enumeration JavaDoc elements = source.entries();
70              elements.hasMoreElements();) {
71             String JavaDoc elementName = (String JavaDoc) elements.nextElement();
72             InputStream JavaDoc is = source.getEntry(elementName);
73             OutputStream JavaDoc fos = null;
74             try {
75                 if (elementName.indexOf('/') != -1) {
76                     String JavaDoc directory = elementName.substring(0,
77                             elementName.lastIndexOf('/'));
78                     File JavaDoc dir = new File JavaDoc(dest, directory);
79                     if (!dir.exists()) {
80                         dir.mkdirs();
81                     }
82                 }
83                 File JavaDoc elementFile = new File JavaDoc(dest, elementName);
84                 fos = new BufferedOutputStream JavaDoc(
85                         new FileOutputStream JavaDoc(elementFile));
86                 ArchivistUtils.copy(is, fos);
87             } finally {
88                 try {
89                     if(is != null)
90                         is.close();
91                     if(fos != null)
92                         fos.close();
93                 } catch (Exception JavaDoc e) {}
94             }
95         }
96     }
97
98 }
99
Popular Tags