Class RecordableHttpURLConnection
-
Field Summary
Fields inherited from class java.net.HttpURLConnection
chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessageFields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches -
Constructor Summary
ConstructorsConstructorDescriptionRecordableHttpURLConnection(URL url, Cassette cassette, Mode mode)Constructor for the RecordableHttpURLConnection class.RecordableHttpURLConnection(URL url, Cassette cassette, Mode mode, AdvancedSettings advancedSettings)Constructor for the RecordableHttpURLConnection class.RecordableHttpURLConnection(URL url, Proxy proxy, Cassette cassette, Mode mode)Constructor for the RecordableHttpURLConnection class.RecordableHttpURLConnection(URL url, Proxy proxy, Cassette cassette, Mode mode, AdvancedSettings advancedSettings)Constructor for the RecordableHttpURLConnection class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRequestProperty(String key, String value)Adds a general request property specified by a key-value pair.voidconnect()voidbooleanReturns the value of theallowUserInteractionfield for this object.intReturns setting for connect timeout.Retrieves the contents of this URL connection.getContent(Class[] classes)Retrieves the contents of this URL connection.Returns the value of thecontent-encodingheader field.intReturns the value of thecontent-lengthheader field.longReturns the value of thecontent-lengthheader field as a long.Returns the value of thecontent-typeheader field.longgetDate()Returns the value of thedateheader field.booleanReturns the default value of aURLConnection'suseCachesflag.booleanReturns the value of thisURLConnection'sdoInputflag.booleanReturns the value of thisURLConnection'sdoOutputflag.Returns the error stream if the connection failed but the server sent useful data nonetheless.longReturns the value of theexpiresheader field.getHeaderField(int n)Returns the value for thenth header field.getHeaderField(String name)Returns the value of the named header field.longgetHeaderFieldDate(String name, long Default)intgetHeaderFieldInt(String name, int Default)Returns the value of the named field parsed as a number.getHeaderFieldKey(int n)Returns the key for thenth header field.longgetHeaderFieldLong(String name, long Default)Returns the value of the named field parsed as a number.Returns an unmodifiable Map of the header fields.longReturns the value of this object'sifModifiedSincefield.booleanReturns the value of thisRecordableHttpUrlConnection'sinstanceFollowRedirectsfield.longReturns the value of thelast-modifiedheader field.Returns an output stream that writes to this connection.Returns aSocketPermissionobject representing the permission necessary to connect to the destination host and port.intReturns setting for read timeout.get the request method.Returns an unmodifiable Map of general request properties for this connection.getRequestProperty(String key)Returns the value of the named general request property for this connection.intgets the status code from an HTTP response message.gets the HTTP response message, if any, returned along with the response code from a server.getURL()Returns the value of thisURLConnection'sURLfield.booleanReturns the value of thisURLConnection'suseCachesfield.voidsetAllowUserInteraction(boolean allowuserinteraction)Set the value of theallowUserInteractionfield of thisURLConnection.voidsetChunkedStreamingMode(int chunklen)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance.voidsetConnectTimeout(int timeout)Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection.voidsetDefaultUseCaches(boolean defaultusecaches)Sets the default value of theuseCachesfield to the specified value.voidsetDoInput(boolean doinput)Sets the value of thedoInputfield for thisURLConnectionto the specified value.voidsetDoOutput(boolean dooutput)Sets the value of thedoOutputfield for thisURLConnectionto the specified value.voidsetFixedLengthStreamingMode(int contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.voidsetFixedLengthStreamingMode(long contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.voidsetIfModifiedSince(long ifmodifiedsince)Sets the value of theifModifiedSincefield of thisURLConnectionto the specified value.voidsetInstanceFollowRedirects(boolean followRedirects)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by thisRecordableHttpUrlConnectioninstance.voidsetReadTimeout(int timeout)Sets the read timeout to a specified timeout, in milliseconds.voidsetRequestMethod(String method)Set the method for the URL request, one of: GET POST HEAD OPTIONS PUT DELETE TRACE are legal, subject to protocol restrictions.voidsetRequestProperty(String key, String value)Sets the general request property.voidsetUseCaches(boolean usecaches)Sets the value of theuseCachesfield of thisURLConnectionto the specified value.toString()Returns aStringrepresentation of this URL connection.booleanMethods inherited from class java.net.HttpURLConnection
getFollowRedirects, setFollowRedirects
-
Constructor Details
-
RecordableHttpURLConnection
public RecordableHttpURLConnection(URL url, Proxy proxy, Cassette cassette, Mode mode, AdvancedSettings advancedSettings) throws IOException, RecordingExpirationExceptionConstructor for the RecordableHttpURLConnection class.- Parameters:
url- The URL to connect to.proxy- The proxy to use.cassette- The cassette to use.mode- The mode to use.advancedSettings- The advanced settings to use.- Throws:
IOException- If an error occurs.RecordingExpirationException
-
RecordableHttpURLConnection
public RecordableHttpURLConnection(URL url, Cassette cassette, Mode mode, AdvancedSettings advancedSettings) throws IOException, RecordingExpirationExceptionConstructor for the RecordableHttpURLConnection class.- Parameters:
url- The URL to connect to.cassette- The cassette to use.mode- The mode to use.advancedSettings- The advanced settings to use.- Throws:
IOException- If an error occurs.RecordingExpirationException
-
RecordableHttpURLConnection
public RecordableHttpURLConnection(URL url, Proxy proxy, Cassette cassette, Mode mode) throws IOException, RecordingExpirationExceptionConstructor for the RecordableHttpURLConnection class.- Parameters:
url- The URL to connect to.proxy- The proxy to use.cassette- The cassette to use.mode- The mode to use.- Throws:
IOException- If an error occurs.RecordingExpirationException
-
RecordableHttpURLConnection
public RecordableHttpURLConnection(URL url, Cassette cassette, Mode mode) throws IOException, RecordingExpirationExceptionConstructor for the RecordableHttpURLConnection class.- Parameters:
url- The URL to connect to.cassette- The cassette to use.mode- The mode to use.- Throws:
IOException- If an error occurs.RecordingExpirationException
-
-
Method Details
-
connect
- Specified by:
connectin classURLConnection- Throws:
IOException
-
disconnect
public void disconnect()- Specified by:
disconnectin classHttpURLConnection
-
usingProxy
public boolean usingProxy()- Specified by:
usingProxyin classHttpURLConnection
-
getHeaderFieldKey
Returns the key for thenth header field. Some implementations may treat the0th header field as special, i.e. as the status line returned by the HTTP server. In this case,getHeaderField(0)returns the status line, butgetHeaderFieldKey(0)returns null.- Overrides:
getHeaderFieldKeyin classHttpURLConnection- Parameters:
n- an index, wheren >=0.- Returns:
- the key for the
nth header field, ornullif the key does not exist.
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(int contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.
When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
NOTE:
setFixedLengthStreamingMode(long)is recommended instead of this method as it allows larger content lengths to be set.- Overrides:
setFixedLengthStreamingModein classHttpURLConnection- Parameters:
contentLength- The number of bytes which will be written to the OutputStream.- Throws:
IllegalStateException- if URLConnection is already connected or if a different streaming mode is already enabled.IllegalArgumentException- if a content length less than zero is specified.- Since:
- 1.5
- See Also:
setChunkedStreamingMode(int)
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(long contentLength)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is known in advance.An exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.
When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
The content length set by invoking this method takes precedence over any value set by
setFixedLengthStreamingMode(int).- Overrides:
setFixedLengthStreamingModein classHttpURLConnection- Parameters:
contentLength- The number of bytes which will be written to the OutputStream.- Throws:
IllegalStateException- if URLConnection is already connected or if a different streaming mode is already enabled.IllegalArgumentException- if a content length less than zero is specified.- Since:
- 1.7
-
setChunkedStreamingMode
public void setChunkedStreamingMode(int chunklen)This method is used to enable streaming of a HTTP request body without internal buffering, when the content length is not known in advance. In this mode, chunked transfer encoding is used to send the request body. Note, not all HTTP servers support this mode.When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
- Overrides:
setChunkedStreamingModein classHttpURLConnection- Parameters:
chunklen- The number of bytes to write in each chunk. If chunklen is less than or equal to zero, a default value will be used.- Throws:
IllegalStateException- if URLConnection is already connected or if a different streaming mode is already enabled.- Since:
- 1.5
- See Also:
setFixedLengthStreamingMode(int)
-
getHeaderField
Returns the value for thenth header field. Some implementations may treat the0th header field as special, i.e. as the status line returned by the HTTP server.This method can be used in conjunction with the
getHeaderFieldKeymethod to iterate through all the headers in the message.- Overrides:
getHeaderFieldin classHttpURLConnection- Parameters:
n- an index, wheren>=0.- Returns:
- the value of the
nth header field, ornullif the value does not exist. - See Also:
HttpURLConnection.getHeaderFieldKey(int)
-
getInstanceFollowRedirects
public boolean getInstanceFollowRedirects()Returns the value of thisRecordableHttpUrlConnection'sinstanceFollowRedirectsfield.- Overrides:
getInstanceFollowRedirectsin classHttpURLConnection- Returns:
- the value of this
RecordableHttpUrlConnection'sinstanceFollowRedirectsfield. - Since:
- 1.3
- See Also:
setInstanceFollowRedirects(boolean)
-
setInstanceFollowRedirects
public void setInstanceFollowRedirects(boolean followRedirects)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by thisRecordableHttpUrlConnectioninstance.The default value comes from followRedirects, which defaults to true.
- Overrides:
setInstanceFollowRedirectsin classHttpURLConnection- Parameters:
followRedirects- abooleanindicating whether or not to follow HTTP redirects.- Since:
- 1.3
- See Also:
getInstanceFollowRedirects()
-
getRequestMethod
get the request method.- Overrides:
getRequestMethodin classHttpURLConnection- Returns:
- the HTTP request method
- See Also:
setRequestMethod(String)
-
setRequestMethod
Set the method for the URL request, one of:- GET
- POST
- HEAD
- OPTIONS
- PUT
- DELETE
- TRACE
- Overrides:
setRequestMethodin classHttpURLConnection- Parameters:
method- the HTTP method- Throws:
ProtocolException- if the method cannot be reset or if the requested method isn't valid for HTTP.SecurityException- if a security manager is set and the method is "TRACE", but the "allowHttpTrace" NetPermission is not granted.- See Also:
getRequestMethod()
-
getResponseCode
gets the status code from an HTTP response message. For example, in the case of the following status lines:HTTP/1.0 200 OK HTTP/1.0 401 Unauthorized
It will return 200 and 401 respectively. Returns -1 if no code can be discerned from the response (i.e., the response is not valid HTTP).- Overrides:
getResponseCodein classHttpURLConnection- Returns:
- the HTTP Status-Code, or -1
- Throws:
IOException- if an error occurred connecting to the server.
-
getResponseMessage
gets the HTTP response message, if any, returned along with the response code from a server. From responses like:HTTP/1.0 200 OK HTTP/1.0 404 Not Found
Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).- Overrides:
getResponseMessagein classHttpURLConnection- Returns:
- the HTTP response message, or
null - Throws:
IOException- if an error occurred connecting to the server.
-
getPermission
Returns aSocketPermissionobject representing the permission necessary to connect to the destination host and port.- Overrides:
getPermissionin classHttpURLConnection- Returns:
- a
SocketPermissionobject representing the permission necessary to connect to the destination host and port. - Throws:
IOException- if an error occurs while computing the permission.
-
getErrorStream
Returns the error stream if the connection failed but the server sent useful data nonetheless. The typical example is when an HTTP server responds with a 404, which will cause a FileNotFoundException to be thrown in connect, but the server sent an HTML help page with suggestions as to what to do.This method will not cause a connection to be initiated. If the connection was not connected, or if the server did not have an error while connecting or if the server had an error but no error data was sent, this method will return null. This is the default.
- Overrides:
getErrorStreamin classHttpURLConnection- Returns:
- an error stream if any, null if there have been no errors, the connection is not connected or the server sent no useful data.
-
getConnectTimeout
public int getConnectTimeout()Returns setting for connect timeout.0 return implies that the option is disabled (i.e., timeout of infinity).
- Overrides:
getConnectTimeoutin classURLConnection- Returns:
- an
intthat indicates the connect timeout value in milliseconds - Since:
- 1.5
- See Also:
setConnectTimeout(int),connect()
-
setConnectTimeout
public 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. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.Some non-standard implementation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().
- Overrides:
setConnectTimeoutin classURLConnection- Parameters:
timeout- anintthat specifies the connect timeout value in milliseconds- Throws:
IllegalArgumentException- if the timeout parameter is negative- Since:
- 1.5
- See Also:
getConnectTimeout(),connect()
-
getReadTimeout
public int getReadTimeout()Returns setting for read timeout. 0 return implies that the option is disabled (i.e., timeout of infinity).- Overrides:
getReadTimeoutin classURLConnection- Returns:
- an
intthat indicates the read timeout value in milliseconds - Since:
- 1.5
- See Also:
setReadTimeout(int),InputStream.read()
-
setReadTimeout
public void setReadTimeout(int timeout)Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout.Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().
- Overrides:
setReadTimeoutin classURLConnection- Parameters:
timeout- anintthat specifies the timeout value to be used in milliseconds- Throws:
IllegalArgumentException- if the timeout parameter is negative- Since:
- 1.5
- See Also:
getReadTimeout(),InputStream.read()
-
getURL
Returns the value of thisURLConnection'sURLfield.- Overrides:
getURLin classURLConnection- Returns:
- the value of this
URLConnection'sURLfield.
-
getContentType
Returns the value of thecontent-typeheader field.- Overrides:
getContentTypein classURLConnection- Returns:
- the content type of the resource that the URL references,
or
nullif not known. - See Also:
URLConnection.getHeaderField(String)
-
getContentEncoding
Returns the value of thecontent-encodingheader field.- Overrides:
getContentEncodingin classURLConnection- Returns:
- the content encoding of the resource that the URL references,
or
nullif not known. - See Also:
URLConnection.getHeaderField(String)
-
getExpiration
public long getExpiration()Returns the value of theexpiresheader field.- Overrides:
getExpirationin classURLConnection- Returns:
- the expiration date of the resource that this URL references, or 0 if not known. The value is the number of milliseconds since January 1, 1970 GMT.
- See Also:
URLConnection.getHeaderField(String)
-
getHeaderField
Returns the value of the named header field.If called on a connection that sets the same header multiple times with possibly different values, only the last value is returned.
- Overrides:
getHeaderFieldin classURLConnection- Parameters:
name- the name of a header field.- Returns:
- the value of the named header field, or
nullif there is no such field in the header.
-
getHeaderFields
Returns an unmodifiable Map of the header fields. The Map keys are Strings that represent the response-header field names. Each Map value is an unmodifiable List of Strings that represents the corresponding field values.- Overrides:
getHeaderFieldsin classURLConnection- Returns:
- a Map of header fields
- Since:
- 1.4
-
getContent
Retrieves the contents of this URL connection.This method first determines the content type of the object by calling the
getContentTypemethod. If this is the first time that the application has seen that specific content type, a content handler for that content type is created.This is done as follows:
- If the application has set up a content handler factory instance
using the
setContentHandlerFactorymethod, thecreateContentHandlermethod of that instance is called with the content type as an argument; the result is a content handler for that content type. - If no
ContentHandlerFactoryhas yet been set up, or if the factory'screateContentHandlermethod returnsnull, then the ServiceLoader mechanism is used to locate ContentHandlerFactory implementations using the system class loader. The order that factories are located is implementation specific, and an implementation is free to cache the located factories. A ServiceConfigurationError,ErrororRuntimeExceptionthrown from thecreateContentHandler, if encountered, will be propagated to the calling thread. ThecreateContentHandlermethod of each factory, if instantiated, is invoked, with the content type, until a factory returns non-null, or all factories have been exhausted. - Failing that, this method tries to load a content handler
class as defined by
ContentHandler. If the class does not exist, or is not a subclass ofContentHandler, then anUnknownServiceExceptionis thrown.
- Overrides:
getContentin classURLConnection- Returns:
- the object fetched. The
instanceofoperator should be used to determine the specific kind of object returned. - Throws:
IOException- if an I/O error occurs while getting the content.UnknownServiceException- if the protocol does not support the content type.- See Also:
ContentHandlerFactory.createContentHandler(String),URLConnection.getContentType(),URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)
- If the application has set up a content handler factory instance
using the
-
toString
Returns aStringrepresentation of this URL connection.- Overrides:
toStringin classURLConnection- Returns:
- a string representation of this
URLConnection.
-
getDoInput
public boolean getDoInput()Returns the value of thisURLConnection'sdoInputflag.- Overrides:
getDoInputin classURLConnection- Returns:
- the value of this
URLConnection'sdoInputflag. - See Also:
setDoInput(boolean)
-
setDoInput
public void setDoInput(boolean doinput)Sets the value of thedoInputfield for thisURLConnectionto 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.
- Overrides:
setDoInputin classURLConnection- Parameters:
doinput- the new value.- Throws:
IllegalStateException- if already connected- See Also:
getDoInput()
-
getDoOutput
public boolean getDoOutput()Returns the value of thisURLConnection'sdoOutputflag.- Overrides:
getDoOutputin classURLConnection- Returns:
- the value of this
URLConnection'sdoOutputflag. - See Also:
setDoOutput(boolean)
-
setDoOutput
public void setDoOutput(boolean dooutput)Sets the value of thedoOutputfield for thisURLConnectionto 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.
- Overrides:
setDoOutputin classURLConnection- Parameters:
dooutput- the new value.- Throws:
IllegalStateException- if already connected- See Also:
getDoOutput()
-
getAllowUserInteraction
public boolean getAllowUserInteraction()Returns the value of theallowUserInteractionfield for this object.- Overrides:
getAllowUserInteractionin classURLConnection- Returns:
- the value of the
allowUserInteractionfield for this object. - See Also:
setAllowUserInteraction(boolean)
-
setAllowUserInteraction
public void setAllowUserInteraction(boolean allowuserinteraction)Set the value of theallowUserInteractionfield of thisURLConnection.- Overrides:
setAllowUserInteractionin classURLConnection- Parameters:
allowuserinteraction- the new value.- Throws:
IllegalStateException- if already connected- See Also:
getAllowUserInteraction()
-
getUseCaches
public boolean getUseCaches()Returns the value of thisURLConnection'suseCachesfield.- Overrides:
getUseCachesin classURLConnection- Returns:
- the value of this
URLConnection'suseCachesfield. - See Also:
setUseCaches(boolean)
-
setUseCaches
public void setUseCaches(boolean usecaches)Sets the value of theuseCachesfield of thisURLConnectionto 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.
- Overrides:
setUseCachesin classURLConnection- Parameters:
usecaches- abooleanindicating whether or not to allow caching- Throws:
IllegalStateException- if already connected- See Also:
getUseCaches()
-
getIfModifiedSince
public long getIfModifiedSince()Returns the value of this object'sifModifiedSincefield.- Overrides:
getIfModifiedSincein classURLConnection- Returns:
- the value of this object's
ifModifiedSincefield. - See Also:
setIfModifiedSince(long)
-
setIfModifiedSince
public void setIfModifiedSince(long ifmodifiedsince)Sets the value of theifModifiedSincefield of thisURLConnectionto the specified value.- Overrides:
setIfModifiedSincein classURLConnection- Parameters:
ifmodifiedsince- the new value.- Throws:
IllegalStateException- if already connected- See Also:
getIfModifiedSince()
-
getDefaultUseCaches
public boolean getDefaultUseCaches()Returns the default value of aURLConnection'suseCachesflag.This 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.
- Overrides:
getDefaultUseCachesin classURLConnection- Returns:
- the default value of a
URLConnection'suseCachesflag. - See Also:
setDefaultUseCaches(boolean)
-
setDefaultUseCaches
public void setDefaultUseCaches(boolean defaultusecaches)Sets the default value of theuseCachesfield to the specified value.- Overrides:
setDefaultUseCachesin classURLConnection- Parameters:
defaultusecaches- the new value.- See Also:
getDefaultUseCaches()
-
setRequestProperty
Sets the general request property. If a property with the key already exists, overwrite its value with the new value.NOTE: HTTP requires all request properties which can legally have multiple instances with the same key to use a comma-separated list syntax which enables multiple properties to be appended into a single property.
- Overrides:
setRequestPropertyin classURLConnection- Parameters:
key- the keyword by which the request is known (e.g., "Accept").value- the value associated with it.- Throws:
IllegalStateException- if already connectedNullPointerException- if key isnull- See Also:
getRequestProperty(String)
-
addRequestProperty
Adds a general request property specified by a key-value pair. This method will not overwrite existing values associated with the same key.- Overrides:
addRequestPropertyin classURLConnection- Parameters:
key- the keyword by which the request is known (e.g., "Accept").value- the value associated with it.- Throws:
IllegalStateException- if already connectedNullPointerException- if key is null- Since:
- 1.4
- See Also:
getRequestProperties()
-
getRequestProperty
Returns the value of the named general request property for this connection.- Overrides:
getRequestPropertyin classURLConnection- Parameters:
key- the keyword by which the request is known (e.g., "Accept").- Returns:
- the value of the named general request property for this connection. If key is null, then null is returned.
- Throws:
IllegalStateException- if already connected- See Also:
setRequestProperty(String, String)
-
getRequestProperties
Returns an unmodifiable Map of general request properties for this connection. The Map keys are Strings that represent the request-header field names. Each Map value is a unmodifiable List of Strings that represents the corresponding field values.- Overrides:
getRequestPropertiesin classURLConnection- Returns:
- a Map of the general request properties for this connection.
- Throws:
IllegalStateException- if already connected- Since:
- 1.4
-
getInputStream
- Overrides:
getInputStreamin classURLConnection- Throws:
IOException
-
getHeaderFieldDate
- Overrides:
getHeaderFieldDatein classHttpURLConnection
-
getContentLength
public int getContentLength()Returns the value of thecontent-lengthheader field.Note:
getContentLengthLong()should be preferred over this method, since it returns alonginstead and is therefore more portable.- Overrides:
getContentLengthin classURLConnection- Returns:
- the content length of the resource that this connection's URL
references,
-1if the content length is not known, or if the content length is greater than Integer.MAX_VALUE.
-
getContentLengthLong
public long getContentLengthLong()Returns the value of thecontent-lengthheader field as a long.- Overrides:
getContentLengthLongin classURLConnection- Returns:
- the content length of the resource that this connection's URL
references, or
-1if the content length is not known. - Since:
- 1.7
-
getDate
public long getDate()Returns the value of thedateheader field.- Overrides:
getDatein classURLConnection- Returns:
- the sending date of the resource that the URL references,
or
0if not known. The value returned is the number of milliseconds since January 1, 1970 GMT. - See Also:
URLConnection.getHeaderField(String)
-
getLastModified
public long getLastModified()Returns the value of thelast-modifiedheader field. The result is the number of milliseconds since January 1, 1970 GMT.- Overrides:
getLastModifiedin classURLConnection- Returns:
- the date the resource referenced by this
URLConnectionwas last modified, or 0 if not known. - See Also:
URLConnection.getHeaderField(String)
-
getHeaderFieldInt
Returns the value of the named field parsed as a number.This form of
getHeaderFieldexists 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.- Overrides:
getHeaderFieldIntin classURLConnection- Parameters:
name- the name of the header field.Default- the default value.- Returns:
- the value of the named field, parsed as an integer. The
Defaultvalue is returned if the field is missing or malformed.
-
getHeaderFieldLong
Returns the value of the named field parsed as a number.This form of
getHeaderFieldexists 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.- Overrides:
getHeaderFieldLongin classURLConnection- Parameters:
name- the name of the header field.Default- the default value.- Returns:
- the value of the named field, parsed as a long. The
Defaultvalue is returned if the field is missing or malformed. - Since:
- 1.7
-
getContent
Retrieves the contents of this URL connection.- Overrides:
getContentin classURLConnection- Parameters:
classes- theClassarray indicating the requested types- Returns:
- the object fetched that is the first match of the type
specified in the classes array. null if none of
the requested types are supported.
The
instanceofoperator should be used to determine the specific kind of object returned. - Throws:
IOException- if an I/O error occurs while getting the content.UnknownServiceException- if the protocol does not support the content type.- Since:
- 1.3
- See Also:
URLConnection.getContent(),ContentHandlerFactory.createContentHandler(String),URLConnection.getContent(Class[]),URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)
-
getOutputStream
Returns an output stream that writes to this connection.- Overrides:
getOutputStreamin classURLConnection- Returns:
- an output stream that writes to this connection.
- Throws:
IOException- if an I/O error occurs while creating the output stream.UnknownServiceException- if the protocol does not support output.
-