Package libcore.net.url
Class JarURLConnectionImpl
java.lang.Object
java.net.URLConnection
java.net.JarURLConnection
libcore.net.url.JarURLConnectionImpl
public class JarURLConnectionImpl extends JarURLConnection
This subclass extends
URLConnection.
This class is responsible for connecting and retrieving resources from a Jar file which can be anywhere that can be referred to by an URL.
-
Field Summary
Fields inherited from class java.net.JarURLConnection
jarFileURLConnectionFields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches -
Constructor Summary
Constructors Constructor Description JarURLConnectionImpl(URL url) -
Method Summary
Modifier and Type Method Description voidconnect()Opens a connection to the resource.ObjectgetContent()Returns the object pointed by thisURL.intgetContentLength()Returns the content length of the resource.StringgetContentType()Returns the content type of the resource.booleangetDefaultUseCaches()Returns the default setting whether this connection allows using caches.InputStreamgetInputStream()Creates an input stream for reading from this URL Connection.JarEntrygetJarEntry()Returns the JarEntry of the entry referenced by thisURLConnection.JarFilegetJarFile()Returns the Jar file referred by thisURLConnection.PermissiongetPermission()Returns the permission, in this case the subclass, FilePermission object which represents the permission necessary for this URLConnection to establish the connection.booleangetUseCaches()Returns the value of the flag which specifies whether thisURLConnectionallows to use caches.voidsetDefaultUseCaches(boolean defaultusecaches)Sets the default value for the flag indicating whether this connection allows to use caches.voidsetUseCaches(boolean usecaches)Sets the flag indicating whether this connection allows to use caches or not.Methods inherited from class java.net.JarURLConnection
getAttributes, getCertificates, getEntryName, getJarFileURL, getMainAttributes, getManifestMethods inherited from class java.net.URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContentEncoding, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getLastModified, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, getURL, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, toString
-
Constructor Details
-
JarURLConnectionImpl
- Parameters:
url- the URL of the JAR- Throws:
MalformedURLException- if the URL is malformedIOException- if there is a problem opening the connection.
-
-
Method Details
-
connect
Description copied from class:URLConnectionOpens a connection to the resource. This method will not reconnect to a resource after the initial connection has been closed.- Specified by:
connectin classURLConnection- Throws:
IOException- if an error occurs while connecting to the resource.- See Also:
URLConnection.connect()
-
getJarFile
Returns the Jar file referred by thisURLConnection.- Specified by:
getJarFilein classJarURLConnection- Returns:
- the referenced JarFile object.
- Throws:
IOException- thrown if an IO error occurs while connecting to the resource.
-
getJarEntry
Returns the JarEntry of the entry referenced by thisURLConnection.- Overrides:
getJarEntryin classJarURLConnection- Returns:
- the JarEntry referenced
- Throws:
IOException- if an IO error occurs while getting the entry
-
getInputStream
Creates an input stream for reading from this URL Connection.- Overrides:
getInputStreamin classURLConnection- Returns:
- the input stream
- Throws:
IOException- if an IO error occurs while connecting to the resource.
-
getContentType
Returns the content type of the resource. For jar file itself "x-java/jar" should be returned, for jar entries the content type of the entry should be returned. Returns non-null results ("content/unknown" for unknown types).- Overrides:
getContentTypein classURLConnection- Returns:
- the content type
-
getContentLength
public int getContentLength()Returns the content length of the resource. Test cases reveal that if the URL is referring to a Jar file, this method answers a content-length returned by URLConnection. For jar entry it should return it's size. Otherwise, it will return -1.- Overrides:
getContentLengthin classURLConnection- Returns:
- the content length
-
getContent
Returns the object pointed by thisURL. If this URLConnection is pointing to a Jar File (no Jar Entry), this method will return aJarFileIf there is a Jar Entry, it will return the object corresponding to the Jar entry content type.- Overrides:
getContentin classURLConnection- Returns:
- a non-null object
- Throws:
IOException- if an IO error occurred- See Also:
ContentHandler,ContentHandlerFactory,IOException,URLConnection.setContentHandlerFactory(ContentHandlerFactory)
-
getPermission
Returns the permission, in this case the subclass, FilePermission object which represents the permission necessary for this URLConnection to establish the connection.- Overrides:
getPermissionin classURLConnection- Returns:
- the permission required for this URLConnection.
- Throws:
IOException- thrown when an IO exception occurs while creating the permission.
-
getUseCaches
public boolean getUseCaches()Description copied from class:URLConnectionReturns the value of the flag which specifies whether thisURLConnectionallows to use caches.- Overrides:
getUseCachesin classURLConnection- Returns:
trueif using caches is allowed,falseotherwise.
-
setUseCaches
public void setUseCaches(boolean usecaches)Description copied from class:URLConnectionSets the flag indicating whether this connection allows to use caches or not. This method can only be called prior to the connection establishment.- Overrides:
setUseCachesin classURLConnection- Parameters:
usecaches- the value of the flag to be set.- See Also:
URLConnection.useCaches
-
getDefaultUseCaches
public boolean getDefaultUseCaches()Description copied from class:URLConnectionReturns the default setting whether this connection allows using caches.- Overrides:
getDefaultUseCachesin classURLConnection- Returns:
- the value of the default setting
defaultUseCaches. - See Also:
URLConnection.useCaches
-
setDefaultUseCaches
public void setDefaultUseCaches(boolean defaultusecaches)Description copied from class:URLConnectionSets the default value for the flag indicating whether this connection allows to use caches. ExistingURLConnections are unaffected.- Overrides:
setDefaultUseCachesin classURLConnection- Parameters:
defaultusecaches- the default value of the flag to be used for new connections.- See Also:
URLConnection.useCaches
-