[JAVA-1024] Change visibility of GridFSDBFile.getChunk(int) to public Created: 16/Oct/13  Updated: 03/Sep/15  Resolved: 03/Sep/15

Status: Closed
Project: Java Driver
Component/s: GridFS
Affects Version/s: 2.11.3
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jan Hallonsten [X] Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We are using GridFS to store multipart/mixed mime messages. We would like to read these messages from GridFS via the mongodb java driver. The messages can be large up to GB size.
Since the mime parser has to reposition and create sub streams on part of the stream we started to implement our own InputStream that implemented https://javamail.java.net/nonav/docs/api/javax/mail/internet/SharedInputStream.html
and also added support for mark and reset. We used GridFSDBFile to do this but we needed to use the getChunk method which unfortunately is package private. To circumvent this we implemented
a helper class in the same package as GridFSDBFile that called getChunk. Unfortunately this workaround does not work in our deployment environment since we are using an osgi platform.

So if it is possible we would like you to change the visibility of the getChunk method to public.



 Comments   
Comment by Jeffrey Yemin [ 03/Sep/15 ]

We didn't make getChunk public, but rather added markSupported, mark, and reset support in the new GridFS implementation

Comment by Ross Lawley [ 02/Sep/15 ]

Fixed in the new GridFS implementation JAVA-1713.

Mark and reset support was added in JAVA-1917.

Comment by Jan Hallonsten [X] [ 16/Oct/13 ]

I guess that you are right it would be sufficient with an implementation of InputStream.mark() and InputStream.reset() which implies that InputStream.markSupported() is changed to return true. Then we could just implement the SharedInputStream.newStream(long start, long end) by calling GridFSDBFile.getInputStream() and then use InputStream.skip(long) to position the new stream at the correct position and then wrap that stream with our own stream implementation that keeps track of the current position and makes sure that the stream is not read past the provided end position.

One disadvantage for us with that approach would be that the same chunk would have to be retrieved several times, first for the parent stream and the again for the sub streams returned by SharedInputStream.newStream. If we had access to the getChunk method we could reuse the chunk if the start position of the new stream is within the currentChunk.

So if you would not like to commit to having getChunk public we could solve our use case with just mark, reset and skip but we would have more possibilities with getChunk.

Comment by Jeffrey Yemin [ 16/Oct/13 ]

As I mentioned on mongodb-user, I'd like to consider the alternative of implementing InputStream.mark() and InputStream.reset() on com.mongodb.gridfs.GridFSDBFile.MyInputStream. Currently they both throw an exception. Would mark and reset support on the InputStream returned by GridFSDBFile#getInputStream be sufficient?

Generated at Thu Feb 08 08:53:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.