final class GridFSDownloadStreamImpl extends java.lang.Object implements GridFSDownloadStream
Modifier and Type | Field and Description |
---|---|
private int |
batchSize |
private byte[] |
buffer |
private int |
bufferOffset |
private int |
chunkIndex |
private MongoCollection<Document> |
chunksCollection |
private java.lang.Object |
closeAndReadingLock |
private boolean |
closed |
private long |
currentPosition |
private AsyncBatchCursor<Document> |
cursor |
private GridFSFile |
fileInfo |
private GridFSFindIterable |
fileInfoIterable |
private static Logger |
LOGGER |
private int |
numberOfChunks |
private boolean |
reading |
private java.util.concurrent.ConcurrentLinkedQueue<Document> |
resultsQueue |
Constructor and Description |
---|
GridFSDownloadStreamImpl(GridFSFindIterable fileInfoIterable,
MongoCollection<Document> chunksCollection) |
Modifier and Type | Method and Description |
---|---|
GridFSDownloadStream |
batchSize(int batchSize)
Sets the number of chunks to return per batch.
|
private <T> void |
callbackClosedException(SingleResultCallback<T> callback) |
private <T> void |
callbackIsReadingException(SingleResultCallback<T> callback) |
private void |
checkAndFetchResults(int amountRead,
java.nio.ByteBuffer dst,
SingleResultCallback<java.lang.Integer> callback) |
private boolean |
checkClosed() |
private MongoGridFSException |
chunkNotFound(int chunkIndex) |
void |
close(SingleResultCallback<java.lang.Void> callback)
Closes the input stream
|
private void |
discardCursor() |
private byte[] |
getBufferFromChunk(Document chunk,
int expectedChunkIndex) |
private boolean |
getBufferFromResultsQueue() |
void |
getGridFSFile(SingleResultCallback<GridFSFile> callback)
Gets the corresponding
GridFSFile for the file being downloaded |
private boolean |
getReadingLock() |
private boolean |
hasFileInfo() |
private boolean |
hasResultsToProcess() |
private void |
processResults(int previousAmountRead,
java.nio.ByteBuffer dst,
SingleResultCallback<java.lang.Integer> callback) |
void |
read(java.nio.ByteBuffer dst,
SingleResultCallback<java.lang.Integer> callback)
Reads a sequence of bytes from this stream into the given buffer.
|
private void |
releaseReadingLock() |
private <A> boolean |
tryGetReadingLock(SingleResultCallback<A> callback) |
private static final Logger LOGGER
private final GridFSFindIterable fileInfoIterable
private final MongoCollection<Document> chunksCollection
private final java.util.concurrent.ConcurrentLinkedQueue<Document> resultsQueue
private final java.lang.Object closeAndReadingLock
private boolean reading
private boolean closed
private GridFSFile fileInfo
private int numberOfChunks
private AsyncBatchCursor<Document> cursor
private int batchSize
private int chunkIndex
private int bufferOffset
private long currentPosition
private byte[] buffer
GridFSDownloadStreamImpl(GridFSFindIterable fileInfoIterable, MongoCollection<Document> chunksCollection)
public void getGridFSFile(SingleResultCallback<GridFSFile> callback)
GridFSDownloadStream
GridFSFile
for the file being downloadedgetGridFSFile
in interface GridFSDownloadStream
callback
- that returns the corresponding GridFSFile for the file being downloadedpublic GridFSDownloadStream batchSize(int batchSize)
GridFSDownloadStream
Can be used to control the memory consumption of this InputStream. The smaller the batchSize the lower the memory consumption and higher latency.
batchSize
in interface GridFSDownloadStream
batchSize
- the batch sizepublic void read(java.nio.ByteBuffer dst, SingleResultCallback<java.lang.Integer> callback)
AsyncInputStream
read
in interface AsyncInputStream
dst
- the destination buffercallback
- the callback returning the total number of bytes read into the buffer, or
-1
if there is no more data because the end of the stream has been reached.private void checkAndFetchResults(int amountRead, java.nio.ByteBuffer dst, SingleResultCallback<java.lang.Integer> callback)
private void processResults(int previousAmountRead, java.nio.ByteBuffer dst, SingleResultCallback<java.lang.Integer> callback)
public void close(SingleResultCallback<java.lang.Void> callback)
AsyncInputStream
close
in interface AsyncInputStream
callback
- the callback that indicates when the stream has been closedprivate boolean hasFileInfo()
private MongoGridFSException chunkNotFound(int chunkIndex)
private byte[] getBufferFromChunk(Document chunk, int expectedChunkIndex)
private boolean getBufferFromResultsQueue()
private boolean hasResultsToProcess()
private <A> boolean tryGetReadingLock(SingleResultCallback<A> callback)
private boolean checkClosed()
private boolean getReadingLock()
private void releaseReadingLock()
private void discardCursor()
private <T> void callbackClosedException(SingleResultCallback<T> callback)
private <T> void callbackIsReadingException(SingleResultCallback<T> callback)