Top Description Fields Constructors Methods
io.smallrye.common.resource

public final Class ResourceURLConnection

extends URLConnection
Class Inheritance
Imports
java.io.IOException, .InputStream, java.net.URL, .URLConnection, java.nio.ByteBuffer, java.time.Instant, io.smallrye.common.constraint.Assert

A URL connection backed by a resource.

Field Summary

Modifier and TypeField and Description
private final Resource
Inherited from java.net.URLConnection:
allowUserInteractionconnecteddoInputdoOutputifModifiedSinceurluseCaches

Constructor Summary

AccessConstructor and Description
pack-priv
ResourceURLConnection(final URL url, final Resource resource)

Method Summary

Modifier and TypeMethod and Description
public void
connect()

Implements abstract java.net.URLConnection.connect.

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.

public Object
getContent(final Class<?>...
the Class array indicating the requested types
classes
)

Overrides java.net.URLConnection.getContent.

Retrieves the contents of this URL connection.

public Object
getContent()

Overrides java.net.URLConnection.getContent.

Retrieves the contents of this URL connection.

public long
getContentLengthLong()

Overrides java.net.URLConnection.getContentLengthLong.

Returns the value of the content-length header field as a long.

public String
getContentType()

Overrides java.net.URLConnection.getContentType.

Returns the value of the content-type header field.

public InputStream
getInputStream()

Overrides java.net.URLConnection.getInputStream.

Returns an input stream that reads from this open connection.

public long
getLastModified()

Overrides java.net.URLConnection.getLastModified.

Returns the value of the last-modified header field.

public Resource

Returns:

the resource associated with this connection (not null)
resource
()

Returns the resource associated with this connection (not null).

Inherited from java.net.URLConnection:
addRequestPropertygetAllowUserInteractiongetConnectTimeoutgetContentEncodinggetContentLengthgetDategetDefaultAllowUserInteractiongetDefaultRequestPropertygetDefaultUseCachesgetDefaultUseCachesgetDoInputgetDoOutputgetExpirationgetFileNameMapgetHeaderFieldgetHeaderFieldgetHeaderFieldDategetHeaderFieldIntgetHeaderFieldKeygetHeaderFieldLonggetHeaderFieldsgetIfModifiedSincegetOutputStreamgetPermissiongetReadTimeoutgetRequestPropertiesgetRequestPropertygetURLgetUseCachesguessContentTypeFromNameguessContentTypeFromStreamsetAllowUserInteractionsetConnectTimeoutsetContentHandlerFactorysetDefaultAllowUserInteractionsetDefaultRequestPropertysetDefaultUseCachessetDefaultUseCachessetDoInputsetDoOutputsetFileNameMapsetIfModifiedSincesetReadTimeoutsetRequestPropertysetUseCachestoString

Field Detail

resourceback to summary
private final Resource resource

Constructor Detail

ResourceURLConnectionback to summary
pack-priv ResourceURLConnection(final URL url, final Resource resource)

Method Detail

connectback to summary
public void connect()

Implements abstract java.net.URLConnection.connect.

Doc from java.net.URLConnection.connect.

Opens a communications link to the resource referenced by this URL, if such a connection has not already been established.

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.

getContentback to summary
public Object getContent(final Class<?>... classes) throws IOException

Overrides java.net.URLConnection.getContent.

Doc from java.net.URLConnection.getContent.

Retrieves the contents of this URL connection.

Parameters
classes:Class<?>[]

the Class array indicating the requested types

Returns:Object

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 instanceof operator should be used to determine the specific kind of object returned.

Exceptions
IOException:
if an I/O error occurs while getting the content.
getContentback to summary
public Object getContent() throws IOException

Overrides java.net.URLConnection.getContent.

Doc from java.net.URLConnection.getContent.

Retrieves the contents of this URL connection.

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.

This is done as follows:

  1. If the application has set up a content handler factory instance using the 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.
  2. If no ContentHandlerFactory has yet been set up, or if the factory's createContentHandler method returns null, 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, Error or RuntimeException thrown from the createContentHandler, if encountered, will be propagated to the calling thread. The createContentHandler method of each factory, if instantiated, is invoked, with the content type, until a factory returns non-null, or all factories have been exhausted.
  3. 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 of ContentHandler, then an UnknownServiceException is thrown.
Returns:Object

the object fetched. The instanceof operator should be used to determine the specific kind of object returned.

Exceptions
IOException:
if an I/O error occurs while getting the content.
getContentLengthLongback to summary
public long getContentLengthLong()

Overrides java.net.URLConnection.getContentLengthLong.

Doc from java.net.URLConnection.getContentLengthLong.

Returns the value of the content-length header field as a long.

Returns:long

the content length of the resource that this connection's URL references, or -1 if the content length is not known.

getContentTypeback to summary
public String getContentType()

Overrides java.net.URLConnection.getContentType.

Doc from java.net.URLConnection.getContentType.

Returns the value of the content-type header field.

Returns:String

the content type of the resource that the URL references, or null if not known.

getInputStreamback to summary
public InputStream getInputStream() throws IOException

Overrides java.net.URLConnection.getInputStream.

Doc from java.net.URLConnection.getInputStream.

Returns 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.

Returns:InputStream

an input stream that reads from this open connection.

Exceptions
IOException:
if an I/O error occurs while creating the input stream.
getLastModifiedback to summary
public long getLastModified()

Overrides java.net.URLConnection.getLastModified.

Doc from java.net.URLConnection.getLastModified.

Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT.

Returns:long

the date the resource referenced by this URLConnection was last modified, or 0 if not known.

resourceback to summary
public Resource resource()

Returns the resource associated with this connection (not null).

Returns:Resource

the resource associated with this connection (not null)