Class GridFSUploadStream

java.lang.Object
java.io.OutputStream
com.mongodb.client.gridfs.GridFSUploadStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

@NotThreadSafe public abstract class GridFSUploadStream extends OutputStream
A GridFS OutputStream for uploading data into GridFS

Provides the id for the file to be uploaded as well as the write methods of a OutputStream

This implementation of a OutputStream will not throw IOExceptions. However, it will throw a MongoException if there is an error writing to MongoDB.

Since:
3.1
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Aborts the upload and deletes any data.
    abstract void
     
    void
     
    abstract org.bson.BsonValue
    Gets the BsonValue for the file to be uploaded
    abstract org.bson.types.ObjectId
    Gets the ObjectId for the file to be uploaded or throws an error if an alternative BsonType has been used for the id.
    abstract void
    write(byte[] b)
     
    abstract void
    write(byte[] b, int off, int len)
     
    abstract void
    write(int b)
     

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GridFSUploadStream

      public GridFSUploadStream()
  • Method Details

    • getObjectId

      public abstract org.bson.types.ObjectId getObjectId()
      Gets the ObjectId for the file to be uploaded or throws an error if an alternative BsonType has been used for the id.

      Throws a MongoGridFSException if the file id is not an ObjectId.

      Returns:
      the ObjectId for the file to be uploaded
    • getId

      public abstract org.bson.BsonValue getId()
      Gets the BsonValue for the file to be uploaded
      Returns:
      the BsonValue for the file to be uploaded
    • abort

      public abstract void abort()
      Aborts the upload and deletes any data.
    • write

      public abstract void write(int b)
      Specified by:
      write in class OutputStream
    • write

      public abstract void write(byte[] b)
      Overrides:
      write in class OutputStream
    • write

      public abstract void write(byte[] b, int off, int len)
      Overrides:
      write in class OutputStream
    • flush

      public void flush()
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
    • close

      public abstract void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream