- All Implemented Interfaces:
AsyncResource
,Resource
,AutoCloseable
A Resource
implementation that identifies resources by a URL that looks up data by opening a URLConnection
.
A typical usage is:
URLResource resource = new URLResource(URI.create("http://host/path/to/resource"));
...
- Since:
- 1.0
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class io.inverno.mod.base.resource.AbstractAsyncResource
AbstractAsyncResource.EndOfFileException
-
Field Summary
Fields inherited from class io.inverno.mod.base.resource.AbstractAsyncResource
DEFAULT_READ_BUFFER_CAPACITY
Fields inherited from class io.inverno.mod.base.resource.AbstractResource
IS_WINDOWS_PATH
-
Constructor Summary
ConstructorDescriptionURLResource
(URI uri) Creates a URL resource with the specified URI.URLResource
(URI uri, MediaTypeService mediaTypeService) Creates a URL resource with the specified URI and media type service.URLResource
(URL url) Creates a URL resource with the specified URL.URLResource
(URL url, MediaTypeService mediaTypeService) Creates a URL resource with the specified URL and media type service. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
delete()
Deletes the resource.exists()
Determines whether the resource exists.Returns the resource file name.getURI()
Returns the resource URI.isFile()
Determines whether this resource represents a file.Returns the resource last modified time stamp.Opens a readable byte channel to the resource.openWritableByteChannel
(boolean append, boolean createParents) Opens a writable byte channel to the resource that will append or not content to an existing resource and create or not missing parent directories.Resolves the specified URI against the resource URI as defined byPath.resolve(Path)
.size()
Returns the resource content size.Methods inherited from class io.inverno.mod.base.resource.AbstractAsyncResource
getExecutor, read, setExecutor, setReadBufferCapacity, write
Methods inherited from class io.inverno.mod.base.resource.AbstractResource
getMediaType, getMediaTypeService, pathToSanitizedString, setMediaTypeService
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.inverno.mod.base.resource.Resource
getMediaType, openWritableByteChannel, openWritableByteChannel, resolve, write, write
-
Constructor Details
-
URLResource
Creates a URL resource with the specified URI.
- Parameters:
uri
- the resource URI throwsIllegalArgumentException
if the URI can't be converted to a URL- Throws:
IllegalArgumentException
-
URLResource
Creates a URL resource with the specified URL.
- Parameters:
url
- the resource URL throwsIllegalArgumentException
if the URL can't be converted to a URI- Throws:
IllegalArgumentException
-
URLResource
Creates a URL resource with the specified URI and media type service.
- Parameters:
uri
- the resource URImediaTypeService
- a media type service throwsIllegalArgumentException
if the URI can't be converted to a URL- Throws:
IllegalArgumentException
-
URLResource
Creates a URL resource with the specified URL and media type service.
- Parameters:
url
- the resource URLmediaTypeService
- a media type service throwsIllegalArgumentException
if the URL can't be converted to a URI- Throws:
IllegalArgumentException
-
-
Method Details
-
getURI
Description copied from interface:Resource
Returns the resource URI.
- Returns:
- the resource URI
-
getFilename
Description copied from interface:Resource
Returns the resource file name.
- Returns:
- the resource file name
- Throws:
ResourceException
- if there was an error resolving the resource file name
-
exists
Description copied from interface:Resource
Determines whether the resource exists.
- Returns:
- an optional returning true if the resource exists, false otherwise or an empty optional if existence couldn't be determined
- Throws:
ResourceException
- if there was an error determining resource existence
-
isFile
Description copied from interface:Resource
Determines whether this resource represents a file.
A file resource is a resource that can be accessed through a
FileChannel
.- Returns:
- an optional returning true if the resource is a file, false otherwise or an empty optional if it couldn't be determined
- Throws:
ResourceException
- if there was an error determining whether the resource is a file
-
lastModified
Description copied from interface:Resource
Returns the resource last modified time stamp.
- Returns:
- an optional returning the resource last modified time stamp or an empty optional if it couldn't be determined
- Throws:
ResourceException
- if there was an error resolving resource last modified time stamp
-
size
Description copied from interface:Resource
Returns the resource content size.
- Returns:
- an optional returning the resource content size or an empty optional if it couldn't be determined
- Throws:
ResourceException
- if there was an error resolving resource content size
-
openReadableByteChannel
Description copied from interface:Resource
Opens a readable byte channel to the resource.
The caller is responsible for closing the channel to prevent resource leak.
- Returns:
- an optional returning a readable byte channel or an empty optional if the resource is not readable
- Throws:
ResourceException
- if there was an error opening the readable byte channel
-
openWritableByteChannel
public Optional<WritableByteChannel> openWritableByteChannel(boolean append, boolean createParents) throws ResourceException Description copied from interface:Resource
Opens a writable byte channel to the resource that will append or not content to an existing resource and create or not missing parent directories.
The caller is responsible for closing the channel to prevent resource leak.
- Parameters:
append
- true to append content to an existing resourcecreateParents
- true to create missing parent directories- Returns:
- an optional returning a writable byte channel or an empty optional if the resource is not writable
- Throws:
ResourceException
- if there was an error opening the writable byte channel
-
delete
Description copied from interface:Resource
Deletes the resource.
- Returns:
- true if the resource had been deleted, false otherwise
- Throws:
ResourceException
- if there was an error deleting to the resource
-
resolve
Description copied from interface:Resource
Resolves the specified URI against the resource URI as defined by
Path.resolve(Path)
.- Parameters:
path
- the path to resolve- Returns:
- a new resource resulting from the resolution of the specified path against the resource
- Throws:
ResourceException
- if there was an error resolving the resource
-
close
public void close()
-