Skip to content

Apache Lucene open-source search software

DirectIOIndexInput - add overloads for bulk retrieval (#14124)

Chris Hegarty60efc4ad28e2
diff --git a/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java b/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
index 40d43e613a0..8b5f4fd76b7 100644
--- a/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
+++ b/lucene/misc/src/java/org/apache/lucene/misc/store/DirectIODirectory.java
@@ -463,6 +463,63 @@ public class DirectIODirectory extends FilterDirectory {
}
}
+ @Override
+ public void readInts(int[] dst, int offset, int len) throws IOException {
+ int remainingDst = len;
+ while (remainingDst > 0) {
+ int cnt = Math.min(buffer.remaining() / Integer.BYTES, remainingDst);
+ buffer.asIntBuffer().get(dst, offset + len - remainingDst, cnt);
+ buffer.position(buffer.position() + Integer.BYTES * cnt);
+ remainingDst -= cnt;
+ if (remainingDst > 0) {
+ if (buffer.hasRemaining()) {
+ dst[offset + len - remainingDst] = readInt();
+ --remainingDst;
+ } else {
+ refill(remainingDst * Integer.BYTES);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void readFloats(float[] dst, int offset, int len) throws IOException {
+ int remainingDst = len;
+ while (remainingDst > 0) {
+ int cnt = Math.min(buffer.remaining() / Float.BYTES, remainingDst);
+ buffer.asFloatBuffer().get(dst, offset + len - remainingDst, cnt);
+ buffer.position(buffer.position() + Float.BYTES * cnt);
+ remainingDst -= cnt;
+ if (remainingDst > 0) {
+ if (buffer.hasRemaining()) {
+ dst[offset + len - remainingDst] = Float.intBitsToFloat(readInt());
+ --remainingDst;
+ } else {
+ refill(remainingDst * Float.BYTES);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void readLongs(long[] dst, int offset, int len) throws IOException {
+ int remainingDst = len;
+ while (remainingDst > 0) {
+ int cnt = Math.min(buffer.remaining() / Long.BYTES, remainingDst);
+ buffer.asLongBuffer().get(dst, offset + len - remainingDst, cnt);
+ buffer.position(buffer.position() + Long.BYTES * cnt);
+ remainingDst -= cnt;
+ if (remainingDst > 0) {
+ if (buffer.hasRemaining()) {
+ dst[offset + len - remainingDst] = readLong();
+ --remainingDst;
+ } else {
+ refill(remainingDst * Long.BYTES);
+ }
+ }
+ }
+ }
+
@Override
public DirectIOIndexInput clone() {
try {