Skip to content

Commit ac5769e

Browse files
author
Daniel Gottlieb
committed
Null out the data field when skipping past the end of a GridFS file and modify the GridFSTest to ensure skipping from the beginning of a GridFSFile works
1 parent c3e1d1e commit ac5769e

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

src/main/com/mongodb/gridfs/GridFSDBFile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public long skip(long numBytesToSkip) throws IOException {
173173
offsetInFile = _currentChunkIdx * _chunkSize + _offset;
174174
if (numBytesToSkip + offsetInFile >= _length) {
175175
_currentChunkIdx = _numChunks;
176+
_data = null;
176177
return _length - offsetInFile;
177178
}
178179

@@ -186,8 +187,6 @@ public long skip(long numBytesToSkip) throws IOException {
186187
}
187188

188189
final int _numChunks;
189-
//Math trick to ensure the _lastChunkSize is between 1 and _chunkSize
190-
//final long _lastChunkSize = ((_length - 1) % _chunkSize) + 1;
191190

192191
int _currentChunkIdx = -1;
193192
int _offset = 0;

src/test/com/mongodb/gridfs/GridFSTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,9 @@ public void testInputStreamSkipping() throws Exception {
222222

223223
inputStream = (GridFSDBFile.MyInputStream)savedFile.getInputStream();
224224

225-
int position = 0;
226-
assertEquals((byte)(position++ % 251), (byte)inputStream.read());
227-
228225
long skipped = inputStream.skip(1);
229226
assertEquals(1, skipped);
230-
position += 1;
227+
int position = 1;
231228
assertEquals((byte)(position++ % 251), (byte)inputStream.read());
232229

233230
skipped = inputStream.skip(chunkSize);

0 commit comments

Comments
 (0)