GridFS retrieve only a range of a file using java driver

gridfs, java, mongodb

Solution

You can skip over the part of the file not needed and read only what you need from there.

    GridFSDBFile file = files.findOne("file");

    InputStream inputStream = file.getInputStream();

    long actuallySkipped = inputStream.skip(numberOfBytesToSkip);
    // read from here...

Hope this helps.

Problem

The docs mention that it is possible to retrieve a range of a document using gridFS. However I haven't found any more details about this. I would like to obtain a range of a file using the java driver for a grails app to support audio streaming. Do I need to get and assemble the packages manually in that case or is there any better way?

Original source