Class HttpsURLConnectionImpl
- java.lang.Object
-
- java.net.URLConnection
-
- java.net.HttpURLConnection
-
- javax.net.ssl.HttpsURLConnection
-
- sun.net.www.protocol.https.HttpsURLConnectionImpl
-
public class HttpsURLConnectionImpl extends HttpsURLConnection
A class to represent an HTTP connection to a remote object. Ideally, this class should subclass and inherit the http handler implementation, but it can't do so because that class have the wrong Java Type. Thus it uses the delegate (aka, the Adapter/Wrapper design pattern) to reuse code from the http handler. Since it would use a delegate to access sun.net.www.protocol.http.HttpURLConnection functionalities, it needs to implement all public methods in it's super class and all the way to Object.
-
-
Field Summary
Fields Modifier and Type Field Description protected DelegateHttpsURLConnectiondelegate-
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_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessage
-
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, doInput, doOutput, url, useCaches
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpsURLConnectionImpl(URL u)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRequestProperty(String key, String value)Adds a general request property specified by a key-value pair.voidconnect()Implements the HTTP protocol handler's "connect" method, establishing an SSL connection to the server as necessary.voiddisconnect()Disconnect from the server.booleanequals(Object obj)Indicates whether some other object is "equal to" this one.booleangetAllowUserInteraction()Returns the value of theallowUserInteractionfield for this object.intgetConnectTimeout()Returns setting for connect timeout.ObjectgetContent()Retrieves the contents of this URL connection.ObjectgetContent(Class[] classes)Retrieves the contents of this URL connection.StringgetContentEncoding()Returns the value of thecontent-encodingheader field.intgetContentLength()Returns the value of thecontent-lengthheader field.longgetContentLengthLong()Returns the value of thecontent-lengthheader field as a long.StringgetContentType()Returns the value of thecontent-typeheader field.booleangetDefaultUseCaches()Returns the default value of aURLConnection'suseCachesflag.booleangetDoInput()Returns the value of thisURLConnection'sdoInputflag.booleangetDoOutput()Returns the value of thisURLConnection'sdoOutputflag.InputStreamgetErrorStream()Returns the error stream if the connection failed but the server sent useful data nonetheless.StringgetHeaderField(int n)Gets a header field by index.StringgetHeaderField(String name)Gets a header field by name.intgetHeaderFieldInt(String name, int Default)Returns the value of the named field parsed as a number.StringgetHeaderFieldKey(int n)Gets a header field by index.longgetHeaderFieldLong(String name, long Default)Returns the value of the named field parsed as a number.Map<String,List<String>>getHeaderFields()Returns an unmodifiable Map of the header fields.InputStreamgetInputStream()Returns an input stream that reads from this open connection.booleangetInstanceFollowRedirects()Returns the value of thisHttpURLConnection'sinstanceFollowRedirectsfield.OutputStreamgetOutputStream()Returns an output stream that writes to this connection.PermissiongetPermission()Returns aSocketPermissionobject representing the permission necessary to connect to the destination host and port.intgetReadTimeout()Returns setting for read timeout.StringgetRequestMethod()Get the request method.Map<String,List<String>>getRequestProperties()Returns an unmodifiable Map of general request properties for this connection.StringgetRequestProperty(String key)Returns the value of the named general request property for this connection.intgetResponseCode()Overwrite super class methodStringgetResponseMessage()Gets the HTTP response message, if any, returned along with the response code from a server.URLgetURL()Returns the value of thisURLConnection'sURLfield.booleangetUseCaches()Returns the value of thisURLConnection'suseCachesfield.inthashCode()Returns a hash code value for the object.protected booleanisConnected()Used by subclass to access "connected" variable.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.protected voidsetConnected(boolean conn)Used by subclass to access "connected" variable.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.voidsetInstanceFollowRedirects(boolean shouldFollow)Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by thisHttpURLConnectioninstance.protected voidsetNewClient(URL url)Create a new HttpClient object, bypassing the cache of HTTP client objects/connections.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 request property.voidsetUseCaches(boolean usecaches)Sets the value of theuseCachesfield of thisURLConnectionto the specified value.StringtoString()Returns aStringrepresentation of this URL connection.booleanusingProxy()Indicates if the connection is going through a proxy.-
Methods inherited from class javax.net.ssl.HttpsURLConnection
getDefaultSSLSocketFactory, getSSLSocketFactory, setDefaultSSLSocketFactory, setSSLSocketFactory
-
Methods inherited from class java.net.HttpURLConnection
getFollowRedirects, setFollowRedirects
-
Methods inherited from class java.net.URLConnection
getDefaultAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction
-
-
-
-
Field Detail
-
delegate
protected DelegateHttpsURLConnection delegate
-
-
Constructor Detail
-
HttpsURLConnectionImpl
protected HttpsURLConnectionImpl(URL u) throws IOException
- Throws:
IOException
-
-
Method Detail
-
setNewClient
protected void setNewClient(URL url) throws IOException
Create a new HttpClient object, bypassing the cache of HTTP client objects/connections.- Parameters:
url- the URL being accessed- Throws:
IOException
-
connect
public void connect() throws IOExceptionImplements the HTTP protocol handler's "connect" method, establishing an SSL connection to the server as necessary.- Specified by:
connectin classURLConnection- Throws:
IOException- if an I/O error occurs while opening the connection.- See Also:
URLConnection.connected,URLConnection.getConnectTimeout(),URLConnection.setConnectTimeout(int)
-
isConnected
protected boolean isConnected()
Used by subclass to access "connected" variable. Since we are delegating the actual implementation to "delegate", we need to delegate the access of "connected" as well.
-
setConnected
protected void setConnected(boolean conn)
Used by subclass to access "connected" variable. Since we are delegating the actual implementation to "delegate", we need to delegate the access of "connected" as well.
-
getOutputStream
public OutputStream getOutputStream() throws IOException
Description copied from class:URLConnectionReturns 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.
-
getInputStream
public InputStream getInputStream() throws IOException
Description copied from class:URLConnectionReturns an input stream that reads from this open connection. A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.- Overrides:
getInputStreamin classURLConnection- Returns:
- an input stream that reads from this open connection.
- Throws:
IOException- if an I/O error occurs while creating the input stream.UnknownServiceException- if the protocol does not support input.- See Also:
URLConnection.setReadTimeout(int),URLConnection.getReadTimeout()
-
getErrorStream
@Nullable public InputStream getErrorStream()
Description copied from class:HttpURLConnectionReturns 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.
-
disconnect
public void disconnect()
Disconnect from the server.- Specified by:
disconnectin classHttpURLConnection
-
usingProxy
public boolean usingProxy()
Description copied from class:HttpURLConnectionIndicates if the connection is going through a proxy.- Specified by:
usingProxyin classHttpURLConnection- Returns:
- a boolean indicating if the connection is using a proxy.
-
getHeaderFields
public Map<String,List<String>> 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
-
getHeaderField
@Nullable public String getHeaderField(String name)
Gets a header field by name. Returns null if not known.- Overrides:
getHeaderFieldin classURLConnection- Parameters:
name- the name of the header field- Returns:
- the value of the named header field, or
nullif there is no such field in the header.
-
getHeaderField
@Nullable public String getHeaderField(int n)
Gets a header field by index. Returns null if not known.- Overrides:
getHeaderFieldin classHttpURLConnection- Parameters:
n- the index of the header field- Returns:
- the value of the
nth header field, ornullif the value does not exist. - See Also:
HttpURLConnection.getHeaderFieldKey(int)
-
getHeaderFieldKey
@Nullable public String getHeaderFieldKey(int n)
Gets a header field by index. Returns null if not known.- Overrides:
getHeaderFieldKeyin classHttpURLConnection- Parameters:
n- the index of the header field- Returns:
- the key for the
nth header field, ornullif the key does not exist.
-
setRequestProperty
public void setRequestProperty(String key, String value)
Sets request property. If a property with the key already exists, overwrite its value with the new value.- Overrides:
setRequestPropertyin classURLConnection- Parameters:
value- the value to be setkey- the keyword by which the request is known (e.g., "Accept").- See Also:
URLConnection.getRequestProperty(java.lang.String)
-
addRequestProperty
public void addRequestProperty(String key, String value)
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.- Since:
- 1.4
- See Also:
getRequestProperties()
-
getResponseCode
public int getResponseCode() throws IOExceptionOverwrite super class method- Overrides:
getResponseCodein classHttpURLConnection- Returns:
- the HTTP Status-Code, or -1
- Throws:
IOException- if an error occurred connecting to the server.
-
getRequestProperty
@Nullable public String getRequestProperty(String key)
Description copied from class:URLConnectionReturns 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.
- See Also:
URLConnection.setRequestProperty(java.lang.String, java.lang.String)
-
getRequestProperties
public Map<String,List<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
-
setInstanceFollowRedirects
public void setInstanceFollowRedirects(boolean shouldFollow)
Description copied from class:HttpURLConnectionSets whether HTTP redirects (requests with response code 3xx) should be automatically followed by thisHttpURLConnectioninstance.The default value comes from followRedirects, which defaults to true.
- Overrides:
setInstanceFollowRedirectsin classHttpURLConnection- Parameters:
shouldFollow- abooleanindicating whether or not to follow HTTP redirects.- See Also:
HttpURLConnection.instanceFollowRedirects,HttpURLConnection.getInstanceFollowRedirects()
-
getInstanceFollowRedirects
public boolean getInstanceFollowRedirects()
Description copied from class:HttpURLConnectionReturns the value of thisHttpURLConnection'sinstanceFollowRedirectsfield.- Overrides:
getInstanceFollowRedirectsin classHttpURLConnection- Returns:
- the value of this
HttpURLConnection'sinstanceFollowRedirectsfield. - See Also:
HttpURLConnection.instanceFollowRedirects,HttpURLConnection.setInstanceFollowRedirects(boolean)
-
setRequestMethod
public void setRequestMethod(String method) throws ProtocolException
Description copied from class:HttpURLConnectionSet 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.- See Also:
HttpURLConnection.getRequestMethod()
-
getRequestMethod
public String getRequestMethod()
Description copied from class:HttpURLConnectionGet the request method.- Overrides:
getRequestMethodin classHttpURLConnection- Returns:
- the HTTP request method
- See Also:
HttpURLConnection.setRequestMethod(java.lang.String)
-
getResponseMessage
@Nullable public String getResponseMessage() throws IOException
Description copied from class:HttpURLConnectionGets 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
public Permission getPermission() throws IOException
Description copied from class:HttpURLConnectionReturns 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.
-
getURL
public URL getURL()
Description copied from class:URLConnectionReturns the value of thisURLConnection'sURLfield.- Overrides:
getURLin classURLConnection- Returns:
- the value of this
URLConnection'sURLfield. - See Also:
URLConnection.url
-
getContentLength
public int getContentLength()
Description copied from class:URLConnectionReturns 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()
Description copied from class:URLConnectionReturns 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.
-
getContentType
@Nullable public String getContentType()
Description copied from class:URLConnectionReturns 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(java.lang.String)
-
getContentEncoding
@Nullable public String getContentEncoding()
Description copied from class:URLConnectionReturns 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(java.lang.String)
-
getHeaderFieldInt
public int getHeaderFieldInt(String name, int Default)
Description copied from class:URLConnectionReturns 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
public long getHeaderFieldLong(String name, long Default)
Description copied from class:URLConnectionReturns 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.
-
getContent
public Object getContent() throws IOException
Description copied from class:URLConnectionRetrieves 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:- 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 content handler factory has yet been set up, or if the factory's
createContentHandlermethod returnsnull, then the application loads the class named:
where <contentType> is formed by taking the content-type string, replacing all slash characters with asun.net.www.content.<contentType>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 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(java.lang.String),URLConnection.getContentType(),URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)
- If the application has set up a content handler factory instance using the
-
getContent
@Nullable public Object getContent(Class[] classes) throws IOException
Description copied from class:URLConnectionRetrieves 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.- See Also:
URLConnection.getContent(),ContentHandlerFactory.createContentHandler(java.lang.String),URLConnection.getContent(java.lang.Class[]),URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)
-
toString
public String toString()
Description copied from class:URLConnectionReturns aStringrepresentation of this URL connection.- Overrides:
toStringin classURLConnection- Returns:
- a string representation of this
URLConnection.
-
setDoInput
public void setDoInput(boolean doinput)
Description copied from class:URLConnectionSets 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.- See Also:
URLConnection.doInput,URLConnection.getDoInput()
-
getDoInput
public boolean getDoInput()
Description copied from class:URLConnectionReturns the value of thisURLConnection'sdoInputflag.- Overrides:
getDoInputin classURLConnection- Returns:
- the value of this
URLConnection'sdoInputflag. - See Also:
URLConnection.setDoInput(boolean)
-
setDoOutput
public void setDoOutput(boolean dooutput)
Description copied from class:URLConnectionSets 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.- See Also:
URLConnection.getDoOutput()
-
getDoOutput
public boolean getDoOutput()
Description copied from class:URLConnectionReturns the value of thisURLConnection'sdoOutputflag.- Overrides:
getDoOutputin classURLConnection- Returns:
- the value of this
URLConnection'sdoOutputflag. - See Also:
URLConnection.setDoOutput(boolean)
-
setAllowUserInteraction
public void setAllowUserInteraction(boolean allowuserinteraction)
Description copied from class:URLConnectionSet the value of theallowUserInteractionfield of thisURLConnection.- Overrides:
setAllowUserInteractionin classURLConnection- Parameters:
allowuserinteraction- the new value.- See Also:
URLConnection.getAllowUserInteraction()
-
getAllowUserInteraction
public boolean getAllowUserInteraction()
Description copied from class:URLConnectionReturns the value of theallowUserInteractionfield for this object.- Overrides:
getAllowUserInteractionin classURLConnection- Returns:
- the value of the
allowUserInteractionfield for this object. - See Also:
URLConnection.setAllowUserInteraction(boolean)
-
setUseCaches
public void setUseCaches(boolean usecaches)
Description copied from class:URLConnectionSets 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- See Also:
URLConnection.getUseCaches()
-
getUseCaches
public boolean getUseCaches()
Description copied from class:URLConnectionReturns the value of thisURLConnection'suseCachesfield.- Overrides:
getUseCachesin classURLConnection- Returns:
- the value of this
URLConnection'suseCachesfield. - See Also:
URLConnection.setUseCaches(boolean)
-
getDefaultUseCaches
public boolean getDefaultUseCaches()
Description copied from class:URLConnectionReturns the default value of aURLConnection'suseCachesflag.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.
- Overrides:
getDefaultUseCachesin classURLConnection- Returns:
- the default value of a
URLConnection'suseCachesflag. - See Also:
URLConnection.setDefaultUseCaches(boolean)
-
setDefaultUseCaches
public void setDefaultUseCaches(boolean defaultusecaches)
Description copied from class:URLConnectionSets the default value of theuseCachesfield to the specified value.- Overrides:
setDefaultUseCachesin classURLConnection- Parameters:
defaultusecaches- the new value.- See Also:
URLConnection.getDefaultUseCaches()
-
equals
public boolean equals(@Nullable Object obj)
Description copied from class:ObjectIndicates whether some other object is "equal to" this one.The
equalsmethod implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x,x.equals(x)should returntrue. - It is symmetric: for any non-null reference values
xandy,x.equals(y)should returntrueif and only ify.equals(x)returnstrue. - It is transitive: for any non-null reference values
x,y, andz, ifx.equals(y)returnstrueandy.equals(z)returnstrue, thenx.equals(z)should returntrue. - It is consistent: for any non-null reference values
xandy, multiple invocations ofx.equals(y)consistently returntrueor consistently returnfalse, provided no information used inequalscomparisons on the objects is modified. - For any non-null reference value
x,x.equals(null)should returnfalse.
The
equalsmethod for classObjectimplements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesxandy, this method returnstrueif and only ifxandyrefer to the same object (x == yhas the valuetrue).Note that it is generally necessary to override the
hashCodemethod whenever this method is overridden, so as to maintain the general contract for thehashCodemethod, which states that equal objects must have equal hash codes.- Overrides:
equalsin classObject- Parameters:
obj- the reference object with which to compare.- Returns:
trueif this object is the same as the obj argument;falseotherwise.- See Also:
Object.hashCode(),HashMap
- It is reflexive: for any non-null reference value
-
hashCode
public int hashCode()
Description copied from class:ObjectReturns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap.The general contract of
hashCodeis:- Whenever it is invoked on the same object more than once during an execution of a Java
application, the
hashCodemethod must consistently return the same integer, provided no information used inequalscomparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)method, then calling thehashCodemethod on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal according to the
Object.equals(java.lang.Object)method, then calling thehashCodemethod on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class
Objectdoes return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)- Overrides:
hashCodein classObject- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
- Whenever it is invoked on the same object more than once during an execution of a Java
application, the
-
setConnectTimeout
public void setConnectTimeout(int timeout)
Description copied from class:URLConnectionSets 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- See Also:
URLConnection.getConnectTimeout(),URLConnection.connect()
-
getConnectTimeout
public int getConnectTimeout()
Description copied from class:URLConnectionReturns 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 - See Also:
URLConnection.setConnectTimeout(int),URLConnection.connect()
-
setReadTimeout
public void setReadTimeout(int timeout)
Description copied from class:URLConnectionSets 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- See Also:
URLConnection.getReadTimeout(),InputStream.read()
-
getReadTimeout
public int getReadTimeout()
Description copied from class:URLConnectionReturns 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 - See Also:
URLConnection.setReadTimeout(int),InputStream.read()
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(int contentLength)
Description copied from class:HttpURLConnectionThis 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:
HttpURLConnection.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.- See Also:
HttpURLConnection.setChunkedStreamingMode(int)
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(long contentLength)
Description copied from class:HttpURLConnectionThis 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
HttpURLConnection.setFixedLengthStreamingMode(int).- Overrides:
setFixedLengthStreamingModein classHttpURLConnection- Parameters:
contentLength- The number of bytes which will be written to the OutputStream.
-
setChunkedStreamingMode
public void setChunkedStreamingMode(int chunklen)
Description copied from class:HttpURLConnectionThis 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.- See Also:
HttpURLConnection.setFixedLengthStreamingMode(int)
-
-