本文整理汇总了Java中java.net.JarURLConnection类的典型用法代码示例。如果您正苦于以下问题:Java JarURLConnection类的具体用法?Java JarURLConnection怎么用?Java JarURLConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JarURLConnection类属于java.net包,在下文中一共展示了JarURLConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJarFile
import java.net.JarURLConnection; //导入依赖的package包/类
private JarFile getJarFile(URL url) throws IOException {
// Optimize case where url refers to a local jar file
if (isOptimizable(url)) {
//HACK
//FileURLMapper p = new FileURLMapper (url);
File p = new File(url.getPath());
if (!p.exists()) {
throw new FileNotFoundException(p.getPath());
}
return new JarFile (p.getPath());
}
URLConnection uc = getBaseURL().openConnection();
uc.setRequestProperty(USER_AGENT_JAVA_VERSION, JAVA_VERSION);
return ((JarURLConnection)uc).getJarFile();
}
示例2: testAddURLMethod
import java.net.JarURLConnection; //导入依赖的package包/类
public void testAddURLMethod() throws Exception {
File jar = new File(getWorkDir(), "default-package-resource.jar");
TestFileUtils.writeZipFile(jar, "META-INF/MANIFEST.MF:Manifest-Version: 1.0\nfoo: bar\n\n", "package/re source++.txt:content");
JarClassLoader jcl = new JarClassLoader(Collections.<File>emptyList(), new ProxyClassLoader[0]);
jcl.addURL(Utilities.toURI(jar).toURL());
URL url = jcl.getResource("package/re source++.txt");
assertTrue(url.toString(), url.toString().endsWith("default-package-resource.jar!/package/re%20source++.txt"));
URLConnection conn = url.openConnection();
assertEquals(7, conn.getContentLength());
assertTrue(conn instanceof JarURLConnection);
JarURLConnection jconn = (JarURLConnection) conn;
assertEquals("package/re source++.txt", jconn.getEntryName());
assertEquals(Utilities.toURI(jar).toURL(), jconn.getJarFileURL());
assertEquals("bar", jconn.getMainAttributes().getValue("foo"));
assertEquals(jar.getAbsolutePath(), jconn.getJarFile().getName());
}
示例3: implTestIfReachable
import java.net.JarURLConnection; //导入依赖的package包/类
private void implTestIfReachable(FileObject fo) throws Exception {
URL urlFromMapper = URLMapper.findURL(fo, getURLType());
if (isNullURLExpected(urlFromMapper, fo)) return;
assertNotNull(urlFromMapper);
URLConnection fc = urlFromMapper.openConnection();
if (fc instanceof JarURLConnection && fo.isFolder()) return;
InputStream ic = fc.getInputStream();
try {
assertNotNull(ic);
} finally {
if (ic != null) ic.close();
}
}
示例4: parse
import java.net.JarURLConnection; //导入依赖的package包/类
private Document parse(DocumentBuilder builder, URL url)
throws IOException, SAXException {
if (!quietmode) {
if (LOG.isDebugEnabled()) {
LOG.debug("parsing URL " + url);
}
}
if (url == null) {
return null;
}
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
// Disable caching for JarURLConnection to avoid sharing JarFile
// with other users.
connection.setUseCaches(false);
}
return parse(builder, connection.getInputStream(), url.toString());
}
示例5: jarCreateTemplate
import java.net.JarURLConnection; //导入依赖的package包/类
/**
* 将jar里面的文件复制到模板文件夹
*
* @param jarConn
* @return
* @throws IOException
*/
public static void jarCreateTemplate(JarURLConnection jarConn) throws IOException {
try (JarFile jarFile = jarConn.getJarFile()) {
Enumeration<JarEntry> entrys = jarFile.entries();
while (entrys.hasMoreElements()) {
JarEntry entry = entrys.nextElement();
if (entry.getName().startsWith(jarConn.getEntryName()) && !entry.getName().endsWith("/")) {
String fileName = entry.getName().replace(TEMPLATE_DIR + "/", "");
InputStream inpt = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(entry.getName());
Files.copy(inpt, Paths.get(TEMPLATE_DIR, fileName));
}
}
}
}
示例6: checkJarFile
import java.net.JarURLConnection; //导入依赖的package包/类
/**
* Private helper method.
*
* @param connection
* the connection to the jar
* @param pckgname
* the package name to search for
* @param classes
* the current ArrayList of all classes. This method will simply
* add new classes.
* @throws ClassNotFoundException
* if a file isn't loaded but still is in the jar file
* @throws IOException
* if it can't correctly read from the jar file.
*/
private static void checkJarFile(JarURLConnection connection,
String pckgname, ArrayList<Class<?>> classes)
throws ClassNotFoundException, IOException {
final JarFile jarFile = connection.getJarFile();
final Enumeration<JarEntry> entries = jarFile.entries();
String name;
for (JarEntry jarEntry = null; entries.hasMoreElements()
&& ((jarEntry = entries.nextElement()) != null);) {
name = jarEntry.getName();
if (name.contains(".class")) {
name = name.substring(0, name.length() - 6).replace('/', '.');
if (name.contains(pckgname)) {
classes.add(Class.forName(name));
}
}
}
}
示例7: getClassesNamesInPackage
import java.net.JarURLConnection; //导入依赖的package包/类
private List<String> getClassesNamesInPackage(final URL url,
String packageName) {
final List<String> classes = new ArrayList<String>();
packageName = packageName.replaceAll("\\.", "/");
try {
JarURLConnection juc = (JarURLConnection) url.openConnection();
JarFile jf = juc.getJarFile();
final Enumeration<JarEntry> entries = jf.entries();
while (entries.hasMoreElements()) {
final JarEntry je = entries.nextElement();
if ((je.getName().startsWith(packageName))
&& (je.getName().endsWith(".class"))) {
classes.add(je.getName().replaceAll("/", "\\.")
.replaceAll("\\.class", ""));
}
}
jf.close();
jf = null;
juc = null;
System.gc();
} catch (final Exception e) {
e.printStackTrace();
}
return classes;
}
示例8: testJarConnectionOn
import java.net.JarURLConnection; //导入依赖的package包/类
private void testJarConnectionOn(Resource jar) throws Exception {
String toString = jar.getURL().toExternalForm();
// force JarURLConnection
String urlString = "jar:" + toString + "!/";
URL newURL = new URL(urlString);
System.out.println(newURL);
System.out.println(newURL.toExternalForm());
URLConnection con = newURL.openConnection();
System.out.println(con);
System.out.println(con instanceof JarURLConnection);
JarURLConnection jarCon = (JarURLConnection) con;
JarFile jarFile = jarCon.getJarFile();
System.out.println(jarFile.getName());
Enumeration enm = jarFile.entries();
while (enm.hasMoreElements())
System.out.println(enm.nextElement());
}
示例9: isPluginJar
import java.net.JarURLConnection; //导入依赖的package包/类
private boolean isPluginJar(IFile file)
{
if( "jar".equals(file.getFileExtension()) )
{
URI jarURI = URIUtil.toJarURI(file.getLocationURI(), JPFProject.MANIFEST_PATH);
try
{
JarEntry jarFile = ((JarURLConnection) jarURI.toURL().openConnection()).getJarEntry();
return jarFile != null;
}
catch( IOException e )
{
// Bad zip
}
}
return false;
}
示例10: copyResources
import java.net.JarURLConnection; //导入依赖的package包/类
/**
* Copies resources to target folder.
*
* @param resourceUrl
* @param targetPath
* @return
*/
static void copyResources(URL resourceUrl, File targetPath) throws IOException {
if (resourceUrl == null) {
return;
}
URLConnection urlConnection = resourceUrl.openConnection();
/**
* Copy resources either from inside jar or from project folder.
*/
if (urlConnection instanceof JarURLConnection) {
copyJarResourceToPath((JarURLConnection) urlConnection, targetPath);
} else {
File file = new File(resourceUrl.getPath());
if (file.isDirectory()) {
FileUtils.copyDirectory(file, targetPath);
} else {
FileUtils.copyFile(file, targetPath);
}
}
}
示例11: checkJarFile
import java.net.JarURLConnection; //导入依赖的package包/类
private void checkJarFile(final ClassLoader classLoader, final URL url, final String pckgname) throws IOException {
final JarURLConnection conn = (JarURLConnection) url.openConnection();
final JarFile jarFile = conn.getJarFile();
final Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final JarEntry jarEntry = entries.nextElement();
String name = jarEntry.getName();
if (name.endsWith(".class")) {
name = name.substring(0, name.length() - 6).replace('/', '.');
if (name.startsWith(pckgname)) {
addClass(classLoader, name);
}
}
}
}
示例12: getVersion
import java.net.JarURLConnection; //导入依赖的package包/类
private static String getVersion()
{
try
{
String path = VDMJC.class.getName().replaceAll("\\.", "/");
URL url = VDMJC.class.getResource("/" + path + ".class");
JarURLConnection conn = (JarURLConnection)url.openConnection();
JarFile jar = conn.getJarFile();
Manifest mf = jar.getManifest();
String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
return version;
}
catch (Exception e)
{
return null;
}
}
示例13: getVersion
import java.net.JarURLConnection; //导入依赖的package包/类
private static String getVersion()
{
try
{
String path = VDMJ.class.getName().replaceAll("\\.", "/");
URL url = VDMJ.class.getResource("/" + path + ".class");
JarURLConnection conn = (JarURLConnection)url.openConnection();
JarFile jar = conn.getJarFile();
Manifest mf = jar.getManifest();
String version = (String)mf.getMainAttributes().get(Attributes.Name.IMPLEMENTATION_VERSION);
return version;
}
catch (Exception e)
{
return null;
}
}
示例14: loadClassFromJarFile
import java.net.JarURLConnection; //导入依赖的package包/类
private static List<Class<?>> loadClassFromJarFile(URL url) {
List<Class<?>> list = new LinkedList<>();
try {
JarURLConnection connection = (JarURLConnection) url.openConnection();
JarFile jarFile = connection.getJarFile();
Enumeration<JarEntry> jarEntries = jarFile.entries();
while (jarEntries.hasMoreElements()) {
String entryName = jarEntries.nextElement().getName();
if (entryName.endsWith(".class")) {
list.add(loadClass(entryName.substring(0, entryName.length() - 6).replace("/", ".")));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return list;
}
示例15: load
import java.net.JarURLConnection; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* @see jp.co.future.uroborosql.store.SqlLoader#load()
*/
@Override
public ConcurrentHashMap<String, String> load() {
ConcurrentHashMap<String, String> loadedSqlMap = new ConcurrentHashMap<>();
try {
Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources(loadPath);
while (resources.hasMoreElements()) {
URL resource = resources.nextElement();
File rootDir = new File(URLDecoder.decode(resource.getFile(), StandardCharsets.UTF_8.toString()));
if (!rootDir.exists() || !rootDir.isDirectory()) {
if ("jar".equalsIgnoreCase(resource.getProtocol())) {
putAllIfAbsent(loadedSqlMap, load((JarURLConnection) resource.openConnection(), loadPath));
continue;
}
LOG.warn("Ignore because not directory.[{}]", rootDir.getAbsolutePath());
continue;
}
LOG.debug("Start loading SQL template.[{}]", rootDir.getAbsolutePath());
putAllIfAbsent(loadedSqlMap, load(new StringBuilder(), rootDir));
}
} catch (IOException e) {
throw new UroborosqlRuntimeException("Failed to load SQL template.", e);
}
if (loadedSqlMap.isEmpty()) {
LOG.warn("SQL template could not be found.");
LOG.warn("Returns an empty SQL cache.");
}
return loadedSqlMap;
}