Package spark.resource
Class ExternalResource
- java.lang.Object
-
- spark.resource.AbstractResource
-
- spark.resource.AbstractFileResolvingResource
-
- spark.resource.ExternalResource
-
- All Implemented Interfaces:
InputStreamResource
,Resource
public class ExternalResource extends AbstractFileResolvingResource
Created by Per Wendel on 2014-05-18.
-
-
Field Summary
Fields Modifier and Type Field Description private java.io.File
file
-
Constructor Summary
Constructors Constructor Description ExternalResource(java.lang.String path)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
exists()
This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.java.lang.String
getDescription()
java.lang.String
getFilename()
This implementation returns the name of the file that this external resource refers to.java.io.InputStream
getInputStream()
Return anInputStream
.java.lang.String
getPath()
Gets the pathjava.net.URL
getURL()
This implementation returns a URL for the underlying class path resource.boolean
isDirectory()
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
-
-
-
-
Method Detail
-
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
public java.lang.String 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:
Object.toString()
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
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:
java.io.IOException
- if the stream could not be opened
-
getURL
public java.net.URL getURL() throws java.io.IOException
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:
java.io.IOException
- if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor- See Also:
ClassLoader.getResource(String)
,Class.getResource(String)
-
getPath
public java.lang.String getPath()
Gets the path- Returns:
- the path
-
getFilename
public java.lang.String 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:
StringUtils.getFilename(String)
-
-