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
ConstructorsConstructorDescriptionGridFsResource(com.mongodb.client.gridfs.model.GridFSFile file) Creates a newGridFsResourcefrom the givenGridFSFile.GridFsResource(com.mongodb.client.gridfs.model.GridFSFile file, InputStream inputStream) -
Method Summary
Modifier and TypeMethodDescriptionstatic GridFsResourceObtain an absentGridFsResource.longbooleanexists()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.GridFSFilegetId()Returns theResource's id.Additional information like file metadata (eg. contentType).longMethods inherited from class org.springframework.core.io.InputStreamResource
equals, hashCode, isOpenMethods inherited from class org.springframework.core.io.AbstractResource
createRelative, getFile, getFileForLastModifiedCheck, getURI, getURL, isFile, isReadable, readableChannel, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.Resource
getContentAsByteArray, getContentAsString
-
Constructor Details
-
GridFsResource
public GridFsResource(com.mongodb.client.gridfs.model.GridFSFile file) Creates a newGridFsResourcefrom 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:
getInputStreamin interfaceInputStreamSource- Overrides:
getInputStreamin classInputStreamResource- Throws:
IOExceptionIllegalStateException
-
contentLength
- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classAbstractResource- Throws:
IOException
-
getFilename
Description copied from interface:GridFsObjectThe filename.- Specified by:
getFilenamein interfaceGridFsObject<Object,InputStream> - Specified by:
getFilenamein interfaceResource- Overrides:
getFilenamein classAbstractResource- Throws:
IllegalStateException
-
exists
public boolean exists()- Specified by:
existsin interfaceResource- Overrides:
existsin classInputStreamResource
-
lastModified
- Specified by:
lastModifiedin interfaceResource- Overrides:
lastModifiedin classAbstractResource- Throws:
IOException
-
getDescription
- Specified by:
getDescriptionin interfaceResource- Overrides:
getDescriptionin classInputStreamResource
-
getId
Returns theResource's id.- Returns:
- never null.
- Throws:
IllegalStateException- if the file does notexists().
-
getFileId
Description copied from interface:GridFsObjectTheGridFSFile.getId()value converted into its simple java type.
ABsonStringwill be converted to plainString.- Specified by:
getFileIdin 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:GridFsObjectThe actual file content.- Specified by:
getContentin interfaceGridFsObject<Object,InputStream> - Returns:
-
getOptions
Description copied from interface:GridFsObjectAdditional information like file metadata (eg. contentType).- Specified by:
getOptionsin interfaceGridFsObject<Object,InputStream> - Returns:
- never null.
-