@Override public void close() { synchronized (closeLock) { if (!closed) { closed = true; } discardCursor(); } }
@Override public GridFSDownloadStream batchSize(final int batchSize) { isTrueArgument("batchSize cannot be negative", batchSize >= 0); this.batchSize = batchSize; discardCursor(); return this; }
@Override public synchronized void reset() { checkClosed(); if (currentPosition == markPosition) { return; } bufferOffset = (int) (markPosition % chunkSizeInBytes); currentPosition = markPosition; int markChunkIndex = (int) Math.floor(markPosition / (double) chunkSizeInBytes); if (markChunkIndex != chunkIndex) { chunkIndex = markChunkIndex; buffer = null; discardCursor(); } }
@Override public long skip(final long bytesToSkip) { checkClosed(); if (bytesToSkip <= 0) { return 0; } long skippedPosition = currentPosition + bytesToSkip; bufferOffset = (int) (skippedPosition % chunkSizeInBytes); if (skippedPosition >= length) { long skipped = length - currentPosition; chunkIndex = numberOfChunks - 1; currentPosition = length; buffer = null; discardCursor(); return skipped; } else { int newChunkIndex = (int) Math.floor(skippedPosition / (double) chunkSizeInBytes); if (chunkIndex != newChunkIndex) { chunkIndex = newChunkIndex; buffer = null; discardCursor(); } currentPosition += bytesToSkip; return bytesToSkip; } }
@Nullable private Document getChunk(final int startChunkIndex) { if (cursor == null) { cursor = getCursor(startChunkIndex); } Document chunk = null; if (cursor.hasNext()) { chunk = cursor.next(); if (batchSize == 1) { discardCursor(); } if (chunk.getInteger("n") != startChunkIndex) { throw new MongoGridFSException(format("Could not find file chunk for file_id: %s at chunk index %s.", fileId, startChunkIndex)); } } return chunk; }
@Override public void close() { synchronized (closeLock) { if (!closed) { closed = true; } discardCursor(); } }
@Override public void close() { synchronized (closeLock) { if (!closed) { closed = true; } discardCursor(); } }
@Override public GridFSDownloadStream batchSize(final int batchSize) { isTrueArgument("batchSize cannot be negative", batchSize >= 0); this.batchSize = batchSize; discardCursor(); return this; }
@Override public GridFSDownloadStream batchSize(final int batchSize) { isTrueArgument("batchSize cannot be negative", batchSize >= 0); this.batchSize = batchSize; discardCursor(); return this; }
@Override public long skip(final long bytesToSkip) { checkClosed(); if (bytesToSkip <= 0) { return 0; } long skippedPosition = currentPosition + bytesToSkip; bufferOffset = (int) (skippedPosition % chunkSizeInBytes); if (skippedPosition >= length) { long skipped = length - currentPosition; chunkIndex = numberOfChunks - 1; currentPosition = length; buffer = null; discardCursor(); return skipped; } else { int newChunkIndex = (int) Math.floor(skippedPosition / (double) chunkSizeInBytes); if (chunkIndex != newChunkIndex) { chunkIndex = newChunkIndex; buffer = null; discardCursor(); } currentPosition += bytesToSkip; return bytesToSkip; } }
@Override public synchronized void reset() { checkClosed(); if (currentPosition == markPosition) { return; } bufferOffset = (int) (markPosition % chunkSizeInBytes); currentPosition = markPosition; int markChunkIndex = (int) Math.floor(markPosition / (double) chunkSizeInBytes); if (markChunkIndex != chunkIndex) { chunkIndex = markChunkIndex; buffer = null; discardCursor(); } }
@Override public long skip(final long bytesToSkip) { checkClosed(); if (bytesToSkip <= 0) { return 0; } long skippedPosition = currentPosition + bytesToSkip; bufferOffset = (int) (skippedPosition % chunkSizeInBytes); if (skippedPosition >= length) { long skipped = length - currentPosition; chunkIndex = numberOfChunks - 1; currentPosition = length; buffer = null; discardCursor(); return skipped; } else { int newChunkIndex = (int) Math.floor(skippedPosition / (double) chunkSizeInBytes); if (chunkIndex != newChunkIndex) { chunkIndex = newChunkIndex; buffer = null; discardCursor(); } currentPosition += bytesToSkip; return bytesToSkip; } }
@Override public synchronized void reset() { checkClosed(); if (currentPosition == markPosition) { return; } bufferOffset = (int) (markPosition % chunkSizeInBytes); currentPosition = markPosition; int markChunkIndex = (int) Math.floor(markPosition / (double) chunkSizeInBytes); if (markChunkIndex != chunkIndex) { chunkIndex = markChunkIndex; buffer = null; discardCursor(); } }
@Nullable private Document getChunk(final int startChunkIndex) { if (cursor == null) { cursor = getCursor(startChunkIndex); } Document chunk = null; if (cursor.hasNext()) { chunk = cursor.next(); if (batchSize == 1) { discardCursor(); } if (chunk.getInteger("n") != startChunkIndex) { throw new MongoGridFSException(format("Could not find file chunk for file_id: %s at chunk index %s.", fileId, startChunkIndex)); } } return chunk; }
@Nullable private Document getChunk(final int startChunkIndex) { if (cursor == null) { cursor = getCursor(startChunkIndex); } Document chunk = null; if (cursor.hasNext()) { chunk = cursor.next(); if (batchSize == 1) { discardCursor(); } if (chunk.getInteger("n") != startChunkIndex) { throw new MongoGridFSException(format("Could not find file chunk for file_id: %s at chunk index %s.", fileId, startChunkIndex)); } } return chunk; }