com.mongodb.gridfs
Class GridFSFile

java.lang.Object
  extended by com.mongodb.gridfs.GridFSFile
All Implemented Interfaces:
DBObject, BSONObject
Direct Known Subclasses:
GridFSDBFile, GridFSInputFile

public abstract class GridFSFile
extends Object
implements DBObject

The abstract class representing a GridFS file

Author:
antoine

Field Summary
protected  GridFS _fs
           
 
Constructor Summary
GridFSFile()
           
 
Method Summary
 boolean containsField(String s)
          Checks if this object contains a field with the given name.
 boolean containsKey(String s)
          Deprecated. 
 Object get(String key)
          Gets a field from this object by a given name.
 List<String> getAliases()
          Gets the aliases from the metadata.
 long getChunkSize()
          Gets the size of a chunk
 String getContentType()
          Gets the content type
 String getFilename()
          Gets the filename
 Object getId()
          Gets the id
 long getLength()
          Gets the file's length
 String getMD5()
          Gets the observed MD5 during transfer
 DBObject getMetaData()
          Gets the file metadata
 Date getUploadDate()
          Gets the upload date
 boolean isPartialObject()
          whether markAsPartialObject was ever called only matters if you are going to upsert and do not want to risk losing fields
 Set<String> keySet()
          Returns this object's fields' names
 void markAsPartialObject()
          if this object was retrieved with only some fields (using a field filter) this method will be called to mark it as such.
 int numChunks()
          Returns the number of chunks that store the file data
 Object put(String key, Object v)
          Sets a name/value pair in this object.
 void putAll(BSONObject o)
          Sets all key/value pairs from an object into this object
 void putAll(Map m)
          Sets all key/value pairs from a map into this object
 Object removeField(String key)
          Removes a field with a given name from this object.
 void save()
          Saves the file entry to the files collection
protected  void setGridFS(GridFS fs)
          Sets the GridFS associated with this file
 void setMetaData(DBObject metadata)
          Gets the file metadata
 Map toMap()
          Returns a map representing this BSONObject.
 String toString()
           
 void validate()
          Verifies that the MD5 matches between the database and the local file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_fs

protected GridFS _fs
Constructor Detail

GridFSFile

public GridFSFile()
Method Detail

save

public void save()
Saves the file entry to the files collection

Throws:
MongoException

validate

public void validate()
Verifies that the MD5 matches between the database and the local file. This should be called after transferring a file.

Throws:
MongoException

numChunks

public int numChunks()
Returns the number of chunks that store the file data

Returns:

getId

public Object getId()
Gets the id

Returns:

getFilename

public String getFilename()
Gets the filename

Returns:

getContentType

public String getContentType()
Gets the content type

Returns:

getLength

public long getLength()
Gets the file's length

Returns:

getChunkSize

public long getChunkSize()
Gets the size of a chunk

Returns:

getUploadDate

public Date getUploadDate()
Gets the upload date

Returns:

getAliases

public List<String> getAliases()
Gets the aliases from the metadata. note: to set aliases, call put( "aliases" , List )

Returns:

getMetaData

public DBObject getMetaData()
Gets the file metadata

Returns:

setMetaData

public void setMetaData(DBObject metadata)
Gets the file metadata


getMD5

public String getMD5()
Gets the observed MD5 during transfer

Returns:

put

public Object put(String key,
                  Object v)
Description copied from interface: BSONObject
Sets a name/value pair in this object.

Specified by:
put in interface BSONObject
Parameters:
key - Name to set
v - Corresponding value
Returns:
v

get

public Object get(String key)
Description copied from interface: BSONObject
Gets a field from this object by a given name.

Specified by:
get in interface BSONObject
Parameters:
key - The name of the field fetch
Returns:
The field, if found

putAll

public void putAll(BSONObject o)
Description copied from interface: BSONObject
Sets all key/value pairs from an object into this object

Specified by:
putAll in interface BSONObject
Parameters:
o - the object

putAll

public void putAll(Map m)
Description copied from interface: BSONObject
Sets all key/value pairs from a map into this object

Specified by:
putAll in interface BSONObject
Parameters:
m - the map

toMap

public Map toMap()
Description copied from interface: BSONObject
Returns a map representing this BSONObject.

Specified by:
toMap in interface BSONObject
Returns:
the map

removeField

public Object removeField(String key)
Description copied from interface: BSONObject
Removes a field with a given name from this object.

Specified by:
removeField in interface BSONObject
Parameters:
key - The name of the field to remove
Returns:
The value removed from this object

containsKey

@Deprecated
public boolean containsKey(String s)
Deprecated. 

Description copied from interface: BSONObject
Deprecated

Specified by:
containsKey in interface BSONObject
Returns:
True if the key is present

containsField

public boolean containsField(String s)
Description copied from interface: BSONObject
Checks if this object contains a field with the given name.

Specified by:
containsField in interface BSONObject
Parameters:
s - Field name for which to check
Returns:
True if the field is present

keySet

public Set<String> keySet()
Description copied from interface: BSONObject
Returns this object's fields' names

Specified by:
keySet in interface BSONObject
Returns:
The names of the fields in this object

isPartialObject

public boolean isPartialObject()
Description copied from interface: DBObject
whether markAsPartialObject was ever called only matters if you are going to upsert and do not want to risk losing fields

Specified by:
isPartialObject in interface DBObject

markAsPartialObject

public void markAsPartialObject()
Description copied from interface: DBObject
if this object was retrieved with only some fields (using a field filter) this method will be called to mark it as such.

Specified by:
markAsPartialObject in interface DBObject

toString

public String toString()
Overrides:
toString in class Object

setGridFS

protected void setGridFS(GridFS fs)
Sets the GridFS associated with this file

Parameters:
fs -