1 23 24 29 30 package com.sun.enterprise.tools.verifier; 31 32 import javax.enterprise.deploy.shared.ModuleType ; 33 34 import java.io.BufferedOutputStream ; 35 import java.io.File ; 36 import java.io.FileOutputStream ; 37 import java.io.IOException ; 38 import java.io.InputStream ; 39 import java.io.OutputStream ; 40 import java.util.Enumeration ; 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 51 public class VerifierUtils { 52 53 public static void copyArchiveToDir(File source, File dest) 54 throws IOException { 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 dest) 68 throws IOException { 69 for (Enumeration elements = source.entries(); 70 elements.hasMoreElements();) { 71 String elementName = (String ) elements.nextElement(); 72 InputStream is = source.getEntry(elementName); 73 OutputStream fos = null; 74 try { 75 if (elementName.indexOf('/') != -1) { 76 String directory = elementName.substring(0, 77 elementName.lastIndexOf('/')); 78 File dir = new File (dest, directory); 79 if (!dir.exists()) { 80 dir.mkdirs(); 81 } 82 } 83 File elementFile = new File (dest, elementName); 84 fos = new BufferedOutputStream ( 85 new FileOutputStream (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 e) {} 94 } 95 } 96 } 97 98 } 99 | Popular Tags |