Interface Resource
-
- All Known Implementing Classes:
ClassPathResource,FileSystemResource,UrlResource
public interface ResourceResource that abstracts from the actual type of underlying source.- Since:
- 4.0.0
- Author:
- Dmytro Nosan
- See Also:
ClassPathResource,FileSystemResource,UrlResource
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanexists()Tests whether a resource exists.Optional<String>getFileName()Gets the file name of this resource.InputStreamgetInputStream()Open anInputStreamfor the underlying resource.OutputStreamgetOutputStream()Open anOutputStreamfor the underlying resource.booleanisReadable()Tests whether a resource is readable.booleanisWritable()Tests whether a resource is writable.default URItoURI()Gets aURIto the underlying resource.URLtoURL()Gets aURLto the underlying resource.
-
-
-
Method Detail
-
getFileName
Optional<String> getFileName()
Gets the file name of this resource.- Returns:
- the name of this Resource.
-
exists
boolean exists()
Tests whether a resource exists.- Returns:
trueif the resource exists
-
isWritable
boolean isWritable()
Tests whether a resource is writable.- Returns:
trueif the resource exists and is writable
-
isReadable
boolean isReadable()
Tests whether a resource is readable.- Returns:
trueif the resource exists and is readable
-
getInputStream
InputStream getInputStream() throws IOException
Open anInputStreamfor the underlying resource.- Returns:
- the input stream for the resource
- Throws:
IOException- if resource does not exist or an I/O error occurs
-
getOutputStream
OutputStream getOutputStream() throws IOException
Open anOutputStreamfor the underlying resource.- Returns:
- the output stream for the resource
- Throws:
IOException- if resource does not exist or an I/O error occurs
-
toURL
URL toURL() throws IOException
Gets aURLto the underlying resource.- Returns:
- the URL to the resource
- Throws:
IOException- if resource does not exist, orURLcannot be built
-
toURI
default URI toURI() throws IOException
Gets aURIto the underlying resource.- Returns:
- the URI to the resource
- Throws:
IOException- if resource does not exist, orURIcannot be built
-
-