Package com.mongodb.gridfs
Class GridFSFile
- java.lang.Object
-
- com.mongodb.gridfs.GridFSFile
-
- All Implemented Interfaces:
DBObject,BSONObject
- Direct Known Subclasses:
GridFSDBFile,GridFSInputFile
public abstract class GridFSFile extends java.lang.Object implements DBObject
The abstract class representing a GridFS file.
-
-
Constructor Summary
Constructors Constructor Description GridFSFile()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleancontainsField(java.lang.String s)Checks if this object contains a field with the given name.booleancontainsKey(java.lang.String key)Deprecated.java.lang.Objectget(java.lang.String key)Gets a field from this object by a given name.java.util.List<java.lang.String>getAliases()Gets the aliases from the metadata.longgetChunkSize()Gets the size of a chunk.java.lang.StringgetContentType()Gets the content type.java.lang.StringgetFilename()Gets the filename.java.lang.ObjectgetId()Gets the id.longgetLength()Gets the file's length.java.lang.StringgetMD5()Deprecated.there is no replacement for this methodDBObjectgetMetaData()Gets the file metadata.java.util.DategetUploadDate()Gets the upload date.booleanisPartialObject()WhetherDBObject.markAsPartialObject()was ever called only matters if you are going to upsert and do not want to risk losing fields.java.util.Set<java.lang.String>keySet()Returns this object's fields' namesvoidmarkAsPartialObject()If this object was retrieved with only some fields (using a field filter) this method will be called to mark it as such.intnumChunks()Returns the number of chunks that store the file data.java.lang.Objectput(java.lang.String key, java.lang.Object v)Sets a name/value pair in this object.voidputAll(java.util.Map m)Sets all key/value pairs from a map into this objectvoidputAll(BSONObject o)Sets all key/value pairs from an object into this objectjava.lang.ObjectremoveField(java.lang.String key)Removes a field with a given name from this object.voidsave()Saves the file entry to the files collectionvoidsetMetaData(DBObject metadata)Gets the file metadata.java.util.Map<?,?>toMap()Returns a map representing this BSONObject.java.lang.StringtoString()voidvalidate()Deprecated.there is no replacement for this method
-
-
-
Method Detail
-
save
public void save()
Saves the file entry to the files collection- Throws:
MongoException- if there's a failure
-
validate
@Deprecated public void validate()
Deprecated.there is no replacement for this methodVerifies that the MD5 matches between the database and the local file. This should be called after transferring a file.- Throws:
MongoException- if there's a failure
-
numChunks
public int numChunks()
Returns the number of chunks that store the file data.- Returns:
- number of chunks
-
getId
public java.lang.Object getId()
Gets the id.- Returns:
- the id of the file.
-
getFilename
public java.lang.String getFilename()
Gets the filename.- Returns:
- the name of the file
-
getContentType
public java.lang.String getContentType()
Gets the content type.- Returns:
- the content type
-
getLength
public long getLength()
Gets the file's length.- Returns:
- the length of the file
-
getChunkSize
public long getChunkSize()
Gets the size of a chunk.- Returns:
- the chunkSize
-
getUploadDate
public java.util.Date getUploadDate()
Gets the upload date.- Returns:
- the date
-
getAliases
public java.util.List<java.lang.String> getAliases()
Gets the aliases from the metadata. note: to set aliases, callput(String, Object)with"aliases" , List<String>.- Returns:
- list of aliases
-
getMetaData
public DBObject getMetaData()
Gets the file metadata.- Returns:
- the metadata
-
setMetaData
public void setMetaData(DBObject metadata)
Gets the file metadata.- Parameters:
metadata- metadata to be set
-
getMD5
@Deprecated public java.lang.String getMD5()
Deprecated.there is no replacement for this methodGets the observed MD5 during transfer- Returns:
- md5
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object v)Description copied from interface:BSONObjectSets a name/value pair in this object.- Specified by:
putin interfaceBSONObject- Parameters:
key- Name to setv- Corresponding value- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey.)
-
get
public java.lang.Object get(java.lang.String key)
Description copied from interface:BSONObjectGets a field from this object by a given name.- Specified by:
getin interfaceBSONObject- Parameters:
key- The name of the field fetch- Returns:
- The field, if found
-
containsKey
@Deprecated public boolean containsKey(java.lang.String key)
Deprecated.Description copied from interface:BSONObjectDeprecated- Specified by:
containsKeyin interfaceBSONObject- Parameters:
key- the key to check- Returns:
- True if the key is present
-
containsField
public boolean containsField(java.lang.String s)
Description copied from interface:BSONObjectChecks if this object contains a field with the given name.- Specified by:
containsFieldin interfaceBSONObject- Parameters:
s- Field name for which to check- Returns:
- True if the field is present
-
keySet
public java.util.Set<java.lang.String> keySet()
Description copied from interface:BSONObjectReturns this object's fields' names- Specified by:
keySetin interfaceBSONObject- Returns:
- The names of the fields in this object
-
isPartialObject
public boolean isPartialObject()
Description copied from interface:DBObjectWhetherDBObject.markAsPartialObject()was ever called only matters if you are going to upsert and do not want to risk losing fields.- Specified by:
isPartialObjectin interfaceDBObject- Returns:
- true if this has been marked as a partial object
-
markAsPartialObject
public void markAsPartialObject()
Description copied from interface:DBObjectIf this object was retrieved with only some fields (using a field filter) this method will be called to mark it as such.- Specified by:
markAsPartialObjectin interfaceDBObject
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
putAll
public void putAll(BSONObject o)
Description copied from interface:BSONObjectSets all key/value pairs from an object into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
o- the object
-
putAll
public void putAll(java.util.Map m)
Description copied from interface:BSONObjectSets all key/value pairs from a map into this object- Specified by:
putAllin interfaceBSONObject- Parameters:
m- the map
-
toMap
public java.util.Map<?,?> toMap()
Description copied from interface:BSONObjectReturns a map representing this BSONObject.- Specified by:
toMapin interfaceBSONObject- Returns:
- the map
-
removeField
public java.lang.Object removeField(java.lang.String key)
Description copied from interface:BSONObjectRemoves a field with a given name from this object.- Specified by:
removeFieldin interfaceBSONObject- Parameters:
key- The name of the field to remove- Returns:
- The value removed from this object
-
-