1 22 package org.jboss.virtual.plugins.context.jar; 23 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Set ; 27 import java.util.concurrent.CopyOnWriteArraySet ; 28 29 35 public class JarUtils 36 { 37 38 private static Set <String > jarSuffixes = new CopyOnWriteArraySet <String >(); 39 40 static 42 { 43 jarSuffixes.add(".zip"); 44 jarSuffixes.add(".ear"); 45 jarSuffixes.add(".jar"); 46 jarSuffixes.add(".rar"); 47 jarSuffixes.add(".war"); 48 jarSuffixes.add(".sar"); 49 jarSuffixes.add(".har"); 50 jarSuffixes.add(".aop"); 51 } 52 53 59 public static void setJarSuffixes(Set <String > suffixes) 60 { 61 if (suffixes == null) 62 throw new IllegalArgumentException ("Null suffix"); 63 jarSuffixes = suffixes; 64 } 65 66 73 public static boolean addJarSuffix(String suffix) 74 { 75 if (suffix == null) 76 throw new IllegalArgumentException ("Null suffix"); 77 return jarSuffixes.add(suffix); 78 } 79 80 87 public static boolean removeJarSuffix(String suffix) 88 { 89 if (suffix == null) 90 throw new IllegalArgumentException ("Null suffix"); 91 return jarSuffixes.remove(suffix); 92 } 93 94 99 public static Set <String > getSuffixes() 100 { 101 return jarSuffixes; 102 } 103 104 108 public static void clearSuffixes() 109 { 110 jarSuffixes.clear(); 111 } 112 113 116 private JarUtils() 117 { 118 } 119 120 127 public static boolean isArchive(String name) 128 { 129 if (name == null) 130 throw new IllegalArgumentException ("Null name"); 131 132 int index = name.lastIndexOf('.'); 133 if (index == -1) 134 return false; 135 String suffix = name.substring(index); 136 return jarSuffixes.contains(suffix); 137 } 138 139 147 public static URL createJarURL(URL url) throws MalformedURLException 148 { 149 if (url == null) 150 throw new IllegalArgumentException ("Null url"); 151 return new URL ("jar:" + url + "!/"); 152 } 153 } 154 | Popular Tags |