public class GridFSInputFile extends GridFSFile
This class represents a GridFS file to be written to the database. Operations include:
Modifier | Constructor and Description |
---|---|
protected |
GridFSInputFile(GridFS gridFS)
Minimal constructor that does not rely on the presence of an
InputStream . |
protected |
GridFSInputFile(GridFS gridFS,
InputStream inputStream,
String filename)
Default constructor setting the GridFS file name and providing an input stream containing data to be written to the file.
|
protected |
GridFSInputFile(GridFS gridFS,
InputStream inputStream,
String filename,
boolean closeStreamOnPersist)
Default constructor setting the GridFS file name and providing an input stream containing data to be written to the file.
|
protected |
GridFSInputFile(GridFS gridFS,
String filename)
Constructor that only provides a file name, but does not rely on the presence of an
InputStream . |
Modifier and Type | Method and Description |
---|---|
protected DBObject |
createChunk(Object id,
int currentChunkNumber,
byte[] writeBuffer)
Creates a new chunk of this file.
|
OutputStream |
getOutputStream()
After retrieving this
OutputStream , this object will be capable of accepting successively written data to the output
stream. |
void |
save()
Calls
save(long) with the existing chunk size. |
void |
save(long chunkSize)
This method first calls saveChunks(long) if the file data has not been saved yet.
|
int |
saveChunks()
Saves all data into chunks from configured
InputStream input stream to GridFS. |
int |
saveChunks(long chunkSize)
Saves all data into chunks from configured
InputStream input stream to GridFS. |
void |
setChunkSize(long chunkSize)
Set the chunk size.
|
void |
setContentType(String contentType)
Sets the content type (MIME type) on the GridFS entry.
|
void |
setFilename(String filename)
Sets the file name on the GridFS entry.
|
void |
setId(Object id)
Sets the ID of this GridFS file.
|
containsField, containsKey, get, getAliases, getChunkSize, getContentType, getFilename, getGridFS, getId, getLength, getMD5, getMetaData, getUploadDate, isPartialObject, keySet, markAsPartialObject, numChunks, put, putAll, putAll, removeField, setGridFS, setMetaData, toMap, toString, validate
protected GridFSInputFile(GridFS gridFS, InputStream inputStream, String filename, boolean closeStreamOnPersist)
gridFS
- The GridFS connection handle.inputStream
- Stream used for reading data from.filename
- Name of the file to be created.closeStreamOnPersist
- indicate the passed in input stream should be closed once the data chunk persistedprotected GridFSInputFile(GridFS gridFS, InputStream inputStream, String filename)
gridFS
- The GridFS connection handle.inputStream
- Stream used for reading data from.filename
- Name of the file to be created.protected GridFSInputFile(GridFS gridFS, String filename)
InputStream
. An OutputStream
can later be obtained for writing using the getOutputStream()
method.gridFS
- The GridFS connection handle.filename
- Name of the file to be created.protected GridFSInputFile(GridFS gridFS)
InputStream
. An OutputStream
can later
be obtained for writing using the getOutputStream()
method.gridFS
- The GridFS connection handle.public void setId(Object id)
id
- the file's ID.public void setFilename(String filename)
filename
- File name.public void setContentType(String contentType)
contentType
- Content type.public void setChunkSize(long chunkSize)
chunkSize
- The size in bytes.public void save()
save(long)
with the existing chunk size.save
in class GridFSFile
MongoException
- if there's a problem saving the file.public void save(long chunkSize)
chunkSize
- Size of chunks for file in bytes.MongoException
- if there's a problem saving the file.public int saveChunks() throws IOException
InputStream
input stream to GridFS.IOException
- on problems reading the new entry's InputStream
.MongoException
- if there's a failuresaveChunks(long)
public int saveChunks(long chunkSize) throws IOException
InputStream
input stream to GridFS. A non-default chunk size can be
specified. This method does NOT save the file object itself, one must call save() to do so.chunkSize
- Size of chunks for file in bytes.IOException
- on problems reading the new entry's InputStream
.MongoException
- if there's a failurepublic OutputStream getOutputStream()
OutputStream
, this object will be capable of accepting successively written data to the output
stream. To completely persist this GridFS object, you must finally call the OutputStream.close()
method on the output
stream. Note that calling the save() and saveChunks() methods will throw Exceptions once you obtained the OutputStream.protected DBObject createChunk(Object id, int currentChunkNumber, byte[] writeBuffer)
id
- the file IDcurrentChunkNumber
- the unique id for this chunkwriteBuffer
- the byte array containing the data for this chunk