Class GridFsResource
java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.InputStreamResource
org.springframework.data.mongodb.gridfs.GridFsResource
- All Implemented Interfaces:
InputStreamSource
,Resource
,GridFsObject<Object,
InputStream>
GridFSFile
based Resource
implementation.- Author:
- Oliver Gierke, Christoph Strobl, Hartmut Lang, Mark Paluch
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.gridfs.GridFsObject
GridFsObject.Options
-
Constructor Summary
ConstructorDescriptionGridFsResource
(com.mongodb.client.gridfs.model.GridFSFile file) Creates a newGridFsResource
from the givenGridFSFile
.GridFsResource
(com.mongodb.client.gridfs.model.GridFSFile file, InputStream inputStream) -
Method Summary
Modifier and TypeMethodDescriptionstatic GridFsResource
Obtain an absentGridFsResource
.long
boolean
exists()
The actual file content.Returns theResource
's content type.TheGridFSFile.getId()
value converted into its simple java type.The filename.com.mongodb.client.gridfs.model.GridFSFile
getId()
Returns theResource
's id.Additional information like file metadata (eg. contentType).long
Methods inherited from class org.springframework.core.io.InputStreamResource
equals, hashCode, isOpen
Methods inherited from class org.springframework.core.io.AbstractResource
createRelative, getFile, getFileForLastModifiedCheck, getURI, getURL, isFile, isReadable, readableChannel, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.core.io.Resource
getContentAsByteArray, getContentAsString
-
Constructor Details
-
GridFsResource
public GridFsResource(com.mongodb.client.gridfs.model.GridFSFile file) Creates a newGridFsResource
from the givenGridFSFile
.- Parameters:
file
- must not be null.
-
GridFsResource
- Parameters:
file
- must not be null.inputStream
- must not be null.
-
-
Method Details
-
absent
Obtain an absentGridFsResource
.- Parameters:
filename
- filename of the absent resource, must not be null.- Returns:
- never null.
- Since:
- 2.1
-
getInputStream
- Specified by:
getInputStream
in interfaceInputStreamSource
- Overrides:
getInputStream
in classInputStreamResource
- Throws:
IOException
IllegalStateException
-
contentLength
- Specified by:
contentLength
in interfaceResource
- Overrides:
contentLength
in classAbstractResource
- Throws:
IOException
-
getFilename
Description copied from interface:GridFsObject
The filename.- Specified by:
getFilename
in interfaceGridFsObject<Object,
InputStream> - Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
- Throws:
IllegalStateException
-
exists
public boolean exists()- Specified by:
exists
in interfaceResource
- Overrides:
exists
in classInputStreamResource
-
lastModified
- Specified by:
lastModified
in interfaceResource
- Overrides:
lastModified
in classAbstractResource
- Throws:
IOException
-
getDescription
- Specified by:
getDescription
in interfaceResource
- Overrides:
getDescription
in classInputStreamResource
-
getId
Returns theResource
's id.- Returns:
- never null.
- Throws:
IllegalStateException
- if the file does notexists()
.
-
getFileId
Description copied from interface:GridFsObject
TheGridFSFile.getId()
value converted into its simple java type.
ABsonString
will be converted to plainString
.- Specified by:
getFileId
in interfaceGridFsObject<Object,
InputStream> - Returns:
- can be null depending on the implementation.
-
getGridFSFile
- Returns:
- the underlying
GridFSFile
. Can be null if absent. - Since:
- 2.2
-
getContentType
Returns theResource
's content type.- Returns:
- never null.
- Throws:
com.mongodb.MongoGridFSException
- in case no content type declared onGridFSFile.getMetadata()
nor provided viaGridFSFile
.IllegalStateException
- if the file does notexists()
.
-
getContent
Description copied from interface:GridFsObject
The actual file content.- Specified by:
getContent
in interfaceGridFsObject<Object,
InputStream> - Returns:
-
getOptions
Description copied from interface:GridFsObject
Additional information like file metadata (eg. contentType).- Specified by:
getOptions
in interfaceGridFsObject<Object,
InputStream> - Returns:
- never null.
-