public class URLConnectionCopy
extends java.net.URLConnection
| Modifier and Type | Field and Description |
|---|---|
private java.net.URLConnection |
connection
Connection base
|
private java.io.File |
fileCopy
File where copy
|
| Constructor and Description |
|---|
URLConnectionCopy(java.net.URL url,
java.io.File fileCopy)
Constructs URLConnectionCopy
|
| Modifier and Type | Method and Description |
|---|---|
void |
addRequestProperty(java.lang.String key,
java.lang.String value)
Adds a general request property specified by a key-value pair.
|
void |
connect()
Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.
|
boolean |
getAllowUserInteraction()
Returns the value of the
allowUserInteraction field for this object. |
int |
getConnectTimeout()
Returns setting for connect timeout.
|
java.lang.Object |
getContent()
Retrieves the contents of this URL connection.
|
java.lang.Object |
getContent(java.lang.Class[] classes)
Retrieves the contents of this URL connection.
|
java.lang.String |
getContentEncoding()
Returns the value of the
content-encoding header field. |
int |
getContentLength()
Returns the value of the
content-length header field. |
java.lang.String |
getContentType()
Returns the value of the
content-type header field. |
long |
getDate()
Returns the value of the
date header field. |
boolean |
getDefaultUseCaches()
Returns the default value of a
URLConnection's useCaches flag. |
boolean |
getDoInput()
Returns the value of this
URLConnection's doInput flag. |
boolean |
getDoOutput()
Returns the value of this
URLConnection's doOutput flag. |
long |
getExpiration()
Returns the value of the
expires header field. |
java.lang.String |
getHeaderField(int n)
Returns the value for the
nth header field. |
java.lang.String |
getHeaderField(java.lang.String name)
Returns the value of the named header field.
|
long |
getHeaderFieldDate(java.lang.String name,
long Default)
Returns the value of the named field parsed as date.
|
int |
getHeaderFieldInt(java.lang.String name,
int Default)
Returns the value of the named field parsed as a number.
|
java.lang.String |
getHeaderFieldKey(int n)
Returns the key for the
nth header field. |
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getHeaderFields()
Returns an unmodifiable Map of the header fields.
|
long |
getIfModifiedSince()
Returns the value of this object's
ifModifiedSince field. |
java.io.InputStream |
getInputStream()
Returns an input stream that reads and copy the reading in the file in same time from this open connection.
|
long |
getLastModified()
Returns the value of the
last-modified header field. |
java.io.OutputStream |
getOutputStream()
Returns an output stream that writes to this connection.
|
java.security.Permission |
getPermission()
Returns a permission object representing the permission necessary to make the connection represented by this object.
|
int |
getReadTimeout()
Returns setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getRequestProperties()
Returns an unmodifiable Map of general request properties for this connection.
|
java.lang.String |
getRequestProperty(java.lang.String key)
Returns the value of the named general request property for this connection.
|
java.net.URL |
getURL()
Returns the value of this
URLConnection's URL field. |
boolean |
getUseCaches()
Returns the value of this
URLConnection's useCaches field. |
void |
setAllowUserInteraction(boolean allowuserinteraction)
Set the value of the
allowUserInteraction field of this URLConnection. |
void |
setConnectTimeout(int timeout)
Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced
by this URLConnection.
|
void |
setDefaultUseCaches(boolean defaultusecaches)
Sets the default value of the
useCaches field to the specified value. |
void |
setDoInput(boolean doinput)
Sets the value of the
doInput field for this URLConnection to the specified value. |
void |
setDoOutput(boolean dooutput)
Sets the value of the
doOutput field for this URLConnection to the specified value. |
void |
setIfModifiedSince(long ifmodifiedsince)
Sets the value of the
ifModifiedSince field of this URLConnection to the specified value. |
void |
setReadTimeout(int timeout)
Sets the read timeout to a specified timeout, in milliseconds.
|
void |
setRequestProperty(java.lang.String key,
java.lang.String value)
Sets the general request property.
|
void |
setUseCaches(boolean usecaches)
Sets the value of the
useCaches field of this URLConnection to the specified value. |
getContentLengthLong, getDefaultAllowUserInteraction, getDefaultRequestProperty, getFileNameMap, getHeaderFieldLong, guessContentTypeFromName, guessContentTypeFromStream, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setFileNameMap, toStringprivate final java.net.URLConnection connection
private final java.io.File fileCopy
public URLConnectionCopy(java.net.URL url,
java.io.File fileCopy)
throws java.io.IOException
url - URL to readfileCopy - File where write the copyjava.io.IOException - On opening connection issue or the file can't be createpublic void addRequestProperty(java.lang.String key,
java.lang.String value)
addRequestProperty in class java.net.URLConnectionkey - the keyword by which the request is known (e.g., " accept").value - the value associated with it.java.lang.IllegalStateException - if already connectedjava.lang.NullPointerException - if key is nullgetRequestProperties(),
URLConnection.addRequestProperty(java.lang.String, java.lang.String)public void connect()
throws java.io.IOException
If the connect method is called when the connection has already been opened (indicated by the
connected field having the value true), the call is ignored.
URLConnection objects go through two phases: first they are created, then they are connected. After being created, and before being connected, various options can be specified (e.g., doInput and UseCaches). After connecting, it is an error to try to set them. Operations that depend on being connected, like getContentLength, will implicitly perform the connection, if necessary.
connect in class java.net.URLConnectionjava.net.SocketTimeoutException - if the timeout expires before the connection can be establishedjava.io.IOException - if an I/O error occurs while opening the connection.getConnectTimeout(),
setConnectTimeout(int),
URLConnection.connect()public boolean getAllowUserInteraction()
allowUserInteraction field for this object.getAllowUserInteraction in class java.net.URLConnectionallowUserInteraction field for this object.setAllowUserInteraction(boolean),
URLConnection.getAllowUserInteraction()public int getConnectTimeout()
0 return implies that the option is disabled (i.e., timeout of infinity).
getConnectTimeout in class java.net.URLConnectionint that indicates the connect timeout value in millisecondssetConnectTimeout(int),
connect(),
URLConnection.getConnectTimeout()public java.lang.Object getContent()
throws java.io.IOException
This method first determines the content type of the object by calling the getContentType method. If this is
the first time that the application has seen that specific content type, a content handler for that content type is
created:
setContentHandlerFactory
method, the createContentHandler method of that instance is called with the content type as an argument; the
result is a content handler for that content type.
createContentHandler method
returns null, then the application loads the class named:
sun.net.www.content.<<i>contentType</i>>
where <contentType> is formed by taking the content-type string, replacing all slash characters
with a period ('.'), and all other non-alphanumeric characters with the underscore character '_
'. The alphanumeric characters are specifically the 26 uppercase ASCII letters 'A' through ' Z',
the 26 lowercase ASCII letters 'a' through ' z', and the 10 ASCII digits '0'
through ' 9'. If the specified class does not exist, or is not a subclass of ContentHandler,
then an UnknownServiceException is thrown.
getContent in class java.net.URLConnectioninstanceof operator should be used to determine the specific kind of object
returned.java.io.IOException - if an I/O error occurs while getting the content.java.net.UnknownServiceException - if the protocol does not support the content type.ContentHandlerFactory.createContentHandler(java.lang.String),
URLConnection.getContentType(),
URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory),
URLConnection.getContent()public java.lang.Object getContent(java.lang.Class[] classes)
throws java.io.IOException
getContent in class java.net.URLConnectionclasses - the Class array indicating the requested typesinstanceof operator should be used to determine the specific kind
of object returned.java.io.IOException - if an I/O error occurs while getting the content.java.net.UnknownServiceException - if the protocol does not support the content type.URLConnection.getContent(),
ContentHandlerFactory.createContentHandler(java.lang.String),
URLConnection.getContent(java.lang.Class[]),
URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory),
URLConnection.getContent(java.lang.Class[])public java.lang.String getContentEncoding()
content-encoding header field.getContentEncoding in class java.net.URLConnectionnull if not known.URLConnection.getHeaderField(java.lang.String),
URLConnection.getContentEncoding()public int getContentLength()
content-length header field.getContentLength in class java.net.URLConnection-1 if the content length
is not known.URLConnection.getContentLength()public java.lang.String getContentType()
content-type header field.getContentType in class java.net.URLConnectionnull if not known.URLConnection.getHeaderField(java.lang.String),
URLConnection.getContentType()public long getDate()
date header field.getDate in class java.net.URLConnection0 if not known. The value returned is
the number of milliseconds since January 1, 1970 GMT.URLConnection.getHeaderField(java.lang.String),
URLConnection.getDate()public boolean getDefaultUseCaches()
URLConnection's useCaches flag.
Ths default is "sticky", being a part of the static state of all URLConnections. This flag applies to the next, and all following URLConnections that are created.
getDefaultUseCaches in class java.net.URLConnectionURLConnection's useCaches flag.setDefaultUseCaches(boolean),
URLConnection.getDefaultUseCaches()public boolean getDoInput()
URLConnection's doInput flag.getDoInput in class java.net.URLConnectionURLConnection's doInput flag.setDoInput(boolean),
URLConnection.getDoInput()public boolean getDoOutput()
URLConnection's doOutput flag.getDoOutput in class java.net.URLConnectionURLConnection's doOutput flag.setDoOutput(boolean),
URLConnection.getDoOutput()public long getExpiration()
expires header field.getExpiration in class java.net.URLConnectionURLConnection.getHeaderField(java.lang.String),
URLConnection.getExpiration()public java.lang.String getHeaderField(int n)
nth header field. It returns null if there are fewer than
n+1fields.
This method can be used in conjunction with the getHeaderFieldKey method to iterate
through all the headers in the message.
getHeaderField in class java.net.URLConnectionn - an index, where n>=0nth header field or null if there are fewer than
n+1 fieldsURLConnection.getHeaderFieldKey(int),
URLConnection.getHeaderField(int)public java.lang.String getHeaderField(java.lang.String name)
If called on a connection that sets the same header multiple times with possibly different values, only the last value is returned.
getHeaderField in class java.net.URLConnectionname - the name of a header field.null if there is no such field in the header.URLConnection.getHeaderField(java.lang.String)public long getHeaderFieldDate(java.lang.String name,
long Default)
This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed
headers. Classes for that connection type can override this method and short-circuit the parsing.
getHeaderFieldDate in class java.net.URLConnectionname - the name of the header field.Default - a default value.Default argument is returned if the field
is missing or malformed.URLConnection.getHeaderFieldDate(java.lang.String, long)public int getHeaderFieldInt(java.lang.String name,
int Default)
This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed
headers. Classes for that connection type can override this method and short-circuit the parsing.
getHeaderFieldInt in class java.net.URLConnectionname - the name of the header field.Default - the default value.Default value is returned if the field is
missing or malformed.URLConnection.getHeaderFieldInt(java.lang.String, int)public java.lang.String getHeaderFieldKey(int n)
nth header field. It returns null if there are fewer than
n+1 fields.getHeaderFieldKey in class java.net.URLConnectionn - an index, where n>=0nth header field, or null if there are fewer than
n+1 fields.URLConnection.getHeaderFieldKey(int)public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getHeaderFields()
getHeaderFields in class java.net.URLConnectionURLConnection.getHeaderFields()public long getIfModifiedSince()
ifModifiedSince field.getIfModifiedSince in class java.net.URLConnectionifModifiedSince field.setIfModifiedSince(long),
URLConnection.getIfModifiedSince()public java.io.InputStream getInputStream()
throws java.io.IOException
getInputStream in class java.net.URLConnectionjava.io.IOException - if an I/O error occurs while creating the input stream.java.net.UnknownServiceException - if the protocol does not support input.setReadTimeout(int),
getReadTimeout(),
URLConnection.getInputStream()public long getLastModified()
last-modified header field. The result is the number of milliseconds since January
1, 1970 GMT.getLastModified in class java.net.URLConnectionURLConnection was last modified, or 0 if not known.URLConnection.getHeaderField(java.lang.String),
URLConnection.getLastModified()public java.io.OutputStream getOutputStream()
throws java.io.IOException
getOutputStream in class java.net.URLConnectionjava.io.IOException - if an I/O error occurs while creating the output stream.java.net.UnknownServiceException - if the protocol does not support output.URLConnection.getOutputStream()public java.security.Permission getPermission()
throws java.io.IOException
java.security.AllPermission. Subclasses should override this method and return the permission that best
represents the permission required to make a a connection to the URL. For example, a URLConnection
representing a file: URL would return a java.io.FilePermission object.
The permission returned may dependent upon the state of the connection. For example, the permission before connecting may be different from that after connecting. For example, an HTTP sever, say foo.com, may redirect the connection to a different host, say bar.com. Before connecting the permission returned by the connection will represent the permission needed to connect to foo.com, while the permission returned after connecting will be to bar.com.
Permissions are generally used for two purposes: to protect caches of objects obtained through URLConnections, and to check the right of a recipient to learn about a particular URL. In the first case, the permission should be obtained after the object has been obtained. For example, in an HTTP connection, this will represent the permission to connect to the host from which the data was ultimately fetched. In the second case, the permission should be obtained and tested before connecting.
getPermission in class java.net.URLConnectionjava.io.IOException - if the computation of the permission requires network or file I/O and an exception occurs while computing
it.URLConnection.getPermission()public int getReadTimeout()
getReadTimeout in class java.net.URLConnectionint that indicates the read timeout value in millisecondssetReadTimeout(int),
InputStream.read(),
URLConnection.getReadTimeout()public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestProperties()
getRequestProperties in class java.net.URLConnectionjava.lang.IllegalStateException - if already connectedURLConnection.getRequestProperties()public java.lang.String getRequestProperty(java.lang.String key)
getRequestProperty in class java.net.URLConnectionkey - the keyword by which the request is known (e.g., "accept").java.lang.IllegalStateException - if already connectedsetRequestProperty(java.lang.String, java.lang.String),
URLConnection.getRequestProperty(java.lang.String)public java.net.URL getURL()
URLConnection's URL field.getURL in class java.net.URLConnectionURLConnection's URL field.URLConnection.getURL()public boolean getUseCaches()
URLConnection's useCaches field.getUseCaches in class java.net.URLConnectionURLConnection's useCaches field.setUseCaches(boolean),
URLConnection.getUseCaches()public void setAllowUserInteraction(boolean allowuserinteraction)
allowUserInteraction field of this URLConnection.setAllowUserInteraction in class java.net.URLConnectionallowuserinteraction - the new value.java.lang.IllegalStateException - if already connectedgetAllowUserInteraction(),
URLConnection.setAllowUserInteraction(boolean)public void setConnectTimeout(int timeout)
Some non-standard implmentation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().
setConnectTimeout in class java.net.URLConnectiontimeout - an int that specifies the connect timeout value in millisecondsjava.lang.IllegalArgumentException - if the timeout parameter is negativegetConnectTimeout(),
connect(),
URLConnection.setConnectTimeout(int)public void setDefaultUseCaches(boolean defaultusecaches)
useCaches field to the specified value.setDefaultUseCaches in class java.net.URLConnectiondefaultusecaches - the new value.getDefaultUseCaches(),
URLConnection.setDefaultUseCaches(boolean)public void setDoInput(boolean doinput)
doInput field for this URLConnection to the specified value.
A URL connection can be used for input and/or output. Set the DoInput flag to true if you intend to use the URL connection for input, false if not. The default is true.
setDoInput in class java.net.URLConnectiondoinput - the new value.java.lang.IllegalStateException - if already connectedgetDoInput(),
URLConnection.setDoInput(boolean)public void setDoOutput(boolean dooutput)
doOutput field for this URLConnection to the specified value.
A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.
setDoOutput in class java.net.URLConnectiondooutput - the new value.java.lang.IllegalStateException - if already connectedgetDoOutput(),
URLConnection.setDoOutput(boolean)public void setIfModifiedSince(long ifmodifiedsince)
ifModifiedSince field of this URLConnection to the specified value.setIfModifiedSince in class java.net.URLConnectionifmodifiedsince - the new value.java.lang.IllegalStateException - if already connectedgetIfModifiedSince(),
URLConnection.setIfModifiedSince(long)public void setReadTimeout(int timeout)
Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().
setReadTimeout in class java.net.URLConnectiontimeout - an int that specifies the timeout value to be used in millisecondsjava.lang.IllegalArgumentException - if the timeout parameter is negativegetReadTimeout(),
InputStream.read(),
URLConnection.setReadTimeout(int)public void setRequestProperty(java.lang.String key,
java.lang.String value)
NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-seperated list syntax which enables multiple properties to be appended into a single property.
setRequestProperty in class java.net.URLConnectionkey - the keyword by which the request is known (e.g., " accept").value - the value associated with it.java.lang.IllegalStateException - if already connectedjava.lang.NullPointerException - if key is nullgetRequestProperty(java.lang.String),
URLConnection.setRequestProperty(java.lang.String, java.lang.String)public void setUseCaches(boolean usecaches)
useCaches field of this URLConnection to the specified value.
Some protocols do caching of documents. Occasionally, it is important to be able to "tunnel through" and ignore the caches (e.g., the "reload" button in a browser). If the UseCaches flag on a connection is true, the connection is allowed to use whatever caches it can. If false, caches are to be ignored. The default value comes from DefaultUseCaches, which defaults to true.
setUseCaches in class java.net.URLConnectionusecaches - a boolean indicating whether or not to allow cachingjava.lang.IllegalStateException - if already connectedgetUseCaches(),
URLConnection.setUseCaches(boolean)