Package spark.resource
Class ExternalResource
java.lang.Object
spark.resource.AbstractResource
spark.resource.AbstractFileResolvingResource
spark.resource.ExternalResource
- All Implemented Interfaces:
InputStreamResource
,Resource
Created by Per Wendel on 2014-05-18.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
exists()
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.This implementation returns the name of the file that this external resource refers to.Return anInputStream
.getPath()
Gets the pathgetURL()
This implementation returns a URL for the underlying class path resource.boolean
Tests whether the file denoted by this abstract pathname is a directory.Methods inherited from class spark.resource.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, isReadable, lastModified
Methods inherited from class spark.resource.AbstractResource
createRelative, equals, getURI, hashCode, isOpen, toString
-
Field Details
-
file
-
-
Constructor Details
-
ExternalResource
Constructor- Parameters:
path
- the path to the external resource
-
-
Method Details
-
isDirectory
public boolean isDirectory()Tests whether the file denoted by this abstract pathname is a directory.- Returns:
- true if and only if the file denoted by this abstract pathname exists and is a directory; false otherwise
-
exists
public boolean exists()Description copied from class:AbstractResource
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened. This will cover both directories and content resources.- Specified by:
exists
in interfaceResource
- Overrides:
exists
in classAbstractFileResolvingResource
- Returns:
- if exists
-
getDescription
- Returns:
- a description for this resource,
to be used for error output when working with the resource.
Implementations are also encouraged to return this value from their
toString
method. - See Also:
-
getInputStream
Description copied from interface:InputStreamResource
Return anInputStream
.It is expected that each call creates a fresh stream.
This requirement is particularly important when you consider an API such as JavaMail, which needs to be able to read the stream multiple times when creating mail attachments. For such a use case, it is required that each
getInputStream()
call returns a fresh stream.- Returns:
- the input stream for the underlying resource (must not be
null
) - Throws:
IOException
- if the stream could not be opened
-
getURL
This implementation returns a URL for the underlying class path resource.- Specified by:
getURL
in interfaceResource
- Overrides:
getURL
in classAbstractResource
- Returns:
- a URL handle for this resource.
- Throws:
IOException
- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor- See Also:
-
getPath
Gets the path- Returns:
- the path
-
getFilename
This implementation returns the name of the file that this external resource refers to.- Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
- Returns:
- the file name.
- See Also:
-