Patch for LUCENE-511.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@382499 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doug Cutting 2006-03-02 20:16:49 +00:00
parent 7dab9545be
commit 4b6426ac56
2 changed files with 23 additions and 0 deletions

View File

@ -58,6 +58,7 @@ public abstract class BufferedIndexOutput extends IndexOutput {
flush();
// and write data at once
flushBuffer(b, length);
bufferStart += length;
} else {
// we fill/flush the buffer (until the input is written)
int pos = 0; // position in the input data

View File

@ -622,4 +622,26 @@ public class TestCompoundFile extends TestCase
is.close();
cr.close();
}
/** This test that writes larger than the size of the buffer output
* will correctly increment the file pointer.
*/
public void testLargeWrites() throws IOException {
IndexOutput os = dir.createOutput("testBufferStart.txt");
byte[] largeBuf = new byte[2048];
for (int i=0; i<largeBuf.length; i++) {
largeBuf[i] = (byte) (Math.random() * 256);
}
long currentPos = os.getFilePointer();
os.writeBytes(largeBuf, largeBuf.length);
try {
assertEquals(currentPos + largeBuf.length, os.getFilePointer());
} finally {
os.close();
}
}
}