Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-185

add OutputStream capability to GridFSInputFile

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.4
    • Affects Version/s: None
    • Component/s: API
    • None
    • Environment:
      feature usable for all environments

      For the implementation of certain types of servers it is
      desirable to obtain a handle to a newly created file in the form
      of a java.io.OutputStream, which can be used to successively
      write to until the file is closed. A similar request already came
      in June this year, see Peter's email here:

      http://www.listware.net/201006/mongodb-user/17457-mongodb-user-java-driver-obtaining-an-outputstream-for-a-gridfs-file.html

      or simpler: http://ur1.ca/1vfuf

      I have finished an implementing this addition, and it would be
      good to see it getting into the MongoDB Java API. The
      implementation is compatible to the current Git HEAD and pass all
      unit tests (including two newly made ones for the new feature).

      A Github repository containing the patch along with a pull
      request into the mongo-java-driver main branch can be found here:

      Some information on the implementation:

      • The implementation has been aimed at staying backwards compatible with
        previous versions.
      • The class GridFS now contains two more createFile() methods, taking no
        parameters and just taking a file name (String). This way I do not have the
        necessity anymore of having to provide a file/InputStream/byte array object.
      • The GridFSInputFile class now offers a public method getOutputStream(). As
        soon as this output stream is obtained, a save() or saveChunks() call will
        only persist the already available input stream data, but the object will
        remain writable on the retrieved output stream until the stream's close()
        method is called.
      • Two further unit tests in GridFSTest are provided to test the output stream
        functionality.
      • For all new API methods and all of GridFSInputFile proper Javadoc is
        provided (it was really tedious to find out things in the beginning with the
        currently very sparse API documentation).
      • All wild card imports in the three files have been removed in favour of a
        clean list of individual imports. (Thanks to Eclipse's "organise imports" that
        was a breeze.)

            Assignee:
            antoine Antoine Girbal
            Reporter:
            xemacs Guy K. Kloss
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: