1 18 19 package org.apache.tools.ant.types; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.Enumeration ; 24 import java.util.Map ; 25 import java.util.zip.ZipException ; 26 27 import org.apache.tools.ant.BuildException; 28 import org.apache.tools.ant.types.resources.FileResource; 29 import org.apache.tools.ant.types.resources.ZipResource; 30 import org.apache.tools.zip.ZipEntry; 31 import org.apache.tools.zip.ZipFile; 32 33 36 public class ZipScanner extends ArchiveScanner { 37 38 55 protected void fillMapsFromArchive(Resource src, String encoding, 56 Map fileEntries, Map matchFileEntries, 57 Map dirEntries, Map matchDirEntries) { 58 ZipEntry entry = null; 59 ZipFile zf = null; 60 61 File srcFile = null; 62 if (src instanceof FileResource) { 63 srcFile = ((FileResource) src).getFile(); 64 } else { 65 throw new BuildException("only file resources are supported"); 66 } 67 68 try { 69 try { 70 zf = new ZipFile(srcFile, encoding); 71 } catch (ZipException ex) { 72 throw new BuildException("problem reading " + srcFile, ex); 73 } catch (IOException ex) { 74 throw new BuildException("problem opening " + srcFile, ex); 75 } 76 Enumeration e = zf.getEntries(); 77 while (e.hasMoreElements()) { 78 entry = (ZipEntry) e.nextElement(); 79 Resource r = new ZipResource(srcFile, encoding, entry); 80 String name = entry.getName(); 81 if (entry.isDirectory()) { 82 name = trimSeparator(name); 83 dirEntries.put(name, r); 84 if (match(name)) { 85 matchDirEntries.put(name, r); 86 } 87 } else { 88 fileEntries.put(name, r); 89 if (match(name)) { 90 matchFileEntries.put(name, r); 91 } 92 } 93 } 94 } finally { 95 if (zf != null) { 96 try { 97 zf.close(); 98 } catch (IOException ex) { 99 } 101 } 102 } 103 } 104 } 105 | Popular Tags |