Class PathResource
- java.lang.Object
-
- io.undertow.server.handlers.resource.PathResource
-
- All Implemented Interfaces:
RangeAwareResource
,Resource
- Direct Known Subclasses:
FileResource
public class PathResource extends Object implements RangeAwareResource
A path resource- Author:
- Stuart Douglas
-
-
Constructor Summary
Constructors Constructor Description PathResource(Path file, PathResourceManager manager, String path)
PathResource(Path file, PathResourceManager manager, String path, ETag eTag)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getCacheKey()
Long
getContentLength()
String
getContentType(MimeMappings mimeMappings)
Return the resources content type.ETag
getETag()
File
getFile()
Path
getFilePath()
Date
getLastModified()
String
getLastModifiedString()
String
getName()
String
getPath()
File
getResourceManagerRoot()
Returns the resource manager root.Path
getResourceManagerRootPath()
Returns the resource manager root.URL
getUrl()
boolean
isDirectory()
boolean
isRangeSupported()
It is possible that some resources managers may only support range requests on a subset of their resources,List<Resource>
list()
void
serve(Sender sender, HttpServerExchange exchange, IoCallback callback)
Serve the resource, and call the provided callback when complete.void
serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback callback)
Serve the resource, and call the provided callback when complete.
-
-
-
Constructor Detail
-
PathResource
public PathResource(Path file, PathResourceManager manager, String path, ETag eTag)
-
PathResource
public PathResource(Path file, PathResourceManager manager, String path)
-
-
Method Detail
-
getPath
public String getPath()
-
getLastModified
public Date getLastModified()
- Specified by:
getLastModified
in interfaceResource
- Returns:
- The last modified date of this resource, or null if this cannot be determined
-
getLastModifiedString
public String getLastModifiedString()
- Specified by:
getLastModifiedString
in interfaceResource
- Returns:
- A string representation of the last modified date, or null if this cannot be determined
-
getETag
public ETag getETag()
-
getName
public String getName()
-
isDirectory
public boolean isDirectory()
- Specified by:
isDirectory
in interfaceResource
- Returns:
true
if this resource represents a directory
-
getContentType
public String getContentType(MimeMappings mimeMappings)
Description copied from interface:Resource
Return the resources content type. In most cases this will simply use the provided mime mappings, however in some cases the resource may have additional information as to the actual content type.- Specified by:
getContentType
in interfaceResource
-
serve
public void serve(Sender sender, HttpServerExchange exchange, IoCallback callback)
Description copied from interface:Resource
Serve the resource, and call the provided callback when complete.
-
serveRange
public void serveRange(Sender sender, HttpServerExchange exchange, long start, long end, IoCallback callback)
Description copied from interface:RangeAwareResource
Serve the resource, and call the provided callback when complete.- Specified by:
serveRange
in interfaceRangeAwareResource
- Parameters:
sender
- The sender to use.exchange
- The exchange
-
getContentLength
public Long getContentLength()
- Specified by:
getContentLength
in interfaceResource
- Returns:
- The content length, or null if it is unknown
-
getCacheKey
public String getCacheKey()
- Specified by:
getCacheKey
in interfaceResource
- Returns:
- A string that uniquely identifies this resource
-
getFile
public File getFile()
-
getFilePath
public Path getFilePath()
- Specified by:
getFilePath
in interfaceResource
- Returns:
- The underlying file that matches the resource. This may return null if the resource does not map to a file
-
getResourceManagerRoot
public File getResourceManagerRoot()
Description copied from interface:Resource
Returns the resource manager root. If the resource manager has multiple roots then this returns the one that is the parent of this resource.- Specified by:
getResourceManagerRoot
in interfaceResource
- Returns:
- a file representing the resource manager root. This may return null if the resource does not map to a file
-
getResourceManagerRootPath
public Path getResourceManagerRootPath()
Description copied from interface:Resource
Returns the resource manager root. If the resource manager has multiple roots then this returns the one that is the parent of this resource.- Specified by:
getResourceManagerRootPath
in interfaceResource
- Returns:
- a path representing the resource manager root. This may return null if the resource does not map to a file
-
getUrl
public URL getUrl()
-
isRangeSupported
public boolean isRangeSupported()
Description copied from interface:RangeAwareResource
It is possible that some resources managers may only support range requests on a subset of their resources,- Specified by:
isRangeSupported
in interfaceRangeAwareResource
- Returns:
true
if this resource supports range requests
-
-