Most visited

Recently visited

Added in API level 1

JarURLConnection

public abstract class JarURLConnection
extends URLConnection

java.lang.Object
    java.net.URLConnection
      java.net.JarURLConnection


到Java归档(JAR)文件的URL连接或JAR文件中的条目。

JAR URL的语法是:

 jar:<url>!/{entry}
 

例如:

jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class

应该使用Jar URL来引用JAR文件或JAR文件中的条目。 上面的例子是一个引用JAR条目的JAR URL。 如果省略条目名称,则URL指的是整个JAR文件: jar:http://www.foo.com/bar/baz.jar!/

当用户知道他们创建的URL是JAR URL时,他们应该将通用URLConnection转换为JarURLConnection,并且他们需要特定于JAR的功能。 例如:

 URL url = new URL("jar:file:/home/duke/duke.jar!/");
 JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
 Manifest manifest = jarConnection.getManifest();
 

JarURLConnection实例只能用于从JAR文件读取。 使用此类无法获取OutputStream修改或写入底层JAR文件。

例子:

A Jar entry
jar:http://www.foo.com/bar/baz.jar!/COM/foo/Quux.class
A Jar file
jar:http://www.foo.com/bar/baz.jar!/
A Jar directory
jar:http://www.foo.com/bar/baz.jar!/COM/foo/

!/被称为 分隔符

通过 new URL(context, spec)构建JAR url时,适用以下规则:

也可以看看:

摘要(Summary)

Fields

protected URLConnection jarFileURLConnection

连接到JAR文件的URL,如果连接已经启动。

Inherited fields

From class java.net.URLConnection

Protected constructors

JarURLConnection(URL url)

将新的JarURLConnection创建为指定的URL。

公共方法(Public methods)

Attributes getAttributes()

如果此连接的URL指向JAR文件条目,则返回此连接的Attributes对象,否则返回null。

Certificate[] getCertificates()

如果它的URL指向一个JAR文件条目,则返回此连接的Certificate对象,否则返回null。

String getEntryName()

返回此连接的条目名称。

JarEntry getJarEntry()

返回此连接的JAR条目对象(如果有)。

abstract JarFile getJarFile()

返回此连接的JAR文件。

URL getJarFileURL()

返回此连接的Jar文件的URL。

Attributes getMainAttributes()

返回此连接的JAR文件的主要属性。

Manifest getManifest()

返回此连接的清单,如果没有,则返回null。

继承方法(Inherited methods)

From class java.net.URLConnection
From class java.lang.Object

Fields

jarFileURLConnection

Added in API level 1
URLConnection jarFileURLConnection

连接到JAR文件的URL,如果连接已经启动。 这应该由连接设置。

Protected constructors

JarURLConnection

Added in API level 1
JarURLConnection (URL url)

将新的JarURLConnection创建为指定的URL。

参数(Parameters)
url URL: the URL
抛出异常(Throws)
MalformedURLException if no legal protocol could be found in a specification string or the string could not be parsed.

公共方法(Public methods)

getAttributes

Added in API level 1
Attributes getAttributes ()

如果此连接的URL指向JAR文件条目,则返回此连接的Attributes对象,否则返回null。

返回(Returns)
Attributes the Attributes object for this connection if the URL for it points to a JAR file entry, null otherwise.
抛出异常(Throws)
IOException if getting the JAR entry causes an IOException to be thrown.

也可以看看:

getCertificates

Added in API level 1
Certificate[] getCertificates ()

如果它的URL指向一个JAR文件条目,则返回此连接的Certificate对象,否则返回null。 只有在连接已经通过从输入流中读取完成验证,直到流的末尾已经达到,才能调用此方法。 否则,此方法将返回null

返回(Returns)
Certificate[] the Certificate object for this connection if the URL for it points to a JAR file entry, null otherwise.
抛出异常(Throws)
IOException if getting the JAR entry causes an IOException to be thrown.

也可以看看:

getEntryName

Added in API level 1
String getEntryName ()

返回此连接的条目名称。 如果与此连接对应的JAR文件URL指向JAR文件而不是JAR文件条目,则此方法返回null。

返回(Returns)
String the entry name for this connection, if any.

getJarEntry

Added in API level 1
JarEntry getJarEntry ()

返回此连接的JAR条目对象(如果有)。 如果与此连接对应的JAR文件URL指向JAR文件而不是JAR文件条目,则此方法返回null。

返回(Returns)
JarEntry the JAR entry object for this connection, or null if the JAR URL for this connection points to a JAR file.
抛出异常(Throws)
IOException if getting the JAR file for this connection causes an IOException to be trown.

也可以看看:

getJarFile

Added in API level 1
JarFile getJarFile ()

返回此连接的JAR文件。

返回(Returns)
JarFile the JAR file for this connection. If the connection is a connection to an entry of a JAR file, the JAR file object is returned
抛出异常(Throws)
IOException if an IOException occurs while trying to connect to the JAR file for this connection.

也可以看看:

getJarFileURL

Added in API level 1
URL getJarFileURL ()

返回此连接的Jar文件的URL。

返回(Returns)
URL the URL for the Jar file for this connection.

getMainAttributes

Added in API level 1
Attributes getMainAttributes ()

返回此连接的JAR文件的主要属性。

返回(Returns)
Attributes the main Attributes for the JAR file for this connection.
抛出异常(Throws)
IOException if getting the manifest causes an IOException to be thrown.

也可以看看:

getManifest

Added in API level 1
Manifest getManifest ()

返回此连接的清单,如果没有,则返回null。

返回(Returns)
Manifest the manifest object corresponding to the JAR file object for this connection.
抛出异常(Throws)
IOException if getting the JAR file for this connection causes an IOException to be trown.

也可以看看:

Hooray!