Skip to content

Apache Lucene open-source search software

fix RAMDirectory(Directory) 2GB size limitation: LUCENE-546

Yonik Seeley45712c518f6e
diff --git a/CHANGES.txt b/CHANGES.txt
index 5c35a9eadaf..191e98854d5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -69,6 +69,9 @@ Bug fixes
14. LUCENE-556: Added empty extractTerms() implementation to MatchAllDocsQuery and
ConstantScoreQuery in order to allow their use with a MultiSearcher.
(Yonik Seeley)
+
+15. LUCENE-546: Creating a RAMDirectory from a Directory truncated files over 2GB.
+ (Peter Royal via Yonik Seeley)
1.9.1
diff --git a/src/java/org/apache/lucene/store/RAMDirectory.java b/src/java/org/apache/lucene/store/RAMDirectory.java
index a18abe45d42..c3282f0a079 100644
--- a/src/java/org/apache/lucene/store/RAMDirectory.java
+++ b/src/java/org/apache/lucene/store/RAMDirectory.java
@@ -60,10 +60,10 @@ public final class RAMDirectory extends Directory {
// read current file
IndexInput is = dir.openInput(files[i]);
// and copy to ram disk
- int len = (int) is.length();
- int readCount = 0;
+ long len = is.length();
+ long readCount = 0;
while (readCount < len) {
- int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? len - readCount : BufferedIndexOutput.BUFFER_SIZE;
+ int toRead = readCount + BufferedIndexOutput.BUFFER_SIZE > len ? (int)(len - readCount) : BufferedIndexOutput.BUFFER_SIZE;
is.readBytes(buf, 0, toRead);
os.writeBytes(buf, toRead);
readCount += toRead;