當前位置: 首頁>>代碼示例>>Java>>正文


Java JarURLConnection類代碼示例

本文整理匯總了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();
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:17,代碼來源:URLClassPath.java

示例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());
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:JarClassLoaderTest.java

示例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();
    }        
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:URLMapperTestHidden.java

示例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());
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:Configuration.java

示例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));
			}
		}
	}

}
 
開發者ID:shenzhenMirren,項目名稱:vertx-generator,代碼行數:23,代碼來源:TemplateUtil.java

示例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));
            }
        }
    }
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:36,代碼來源:ClassLoaderHelper.java

示例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;
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:26,代碼來源:RepositoryLoaderService.java

示例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());
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:19,代碼來源:BundleClassPathWildcardTest.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:18,代碼來源:WorkspaceJarModelManager.java

示例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);
        }
    }
}
 
開發者ID:RaiMan,項目名稱:Sikulix2tesseract,代碼行數:29,代碼來源:LoadLibs.java

示例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);
            }
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:20,代碼來源:ClassPathScanner.java

示例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;
	}
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:18,代碼來源:VDMJC.java

示例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;
	}
}
 
開發者ID:nickbattle,項目名稱:FJ-VDMJ,代碼行數:18,代碼來源:VDMJ.java

示例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;
}
 
開發者ID:omsfuk,項目名稱:Samurai,代碼行數:18,代碼來源:ClassUtil.java

示例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;
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:39,代碼來源:SqlLoaderImpl.java


注:本文中的java.net.JarURLConnection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。