Skip to content

Apache Lucene open-source search software

LUCENE-9047: Directory API is now little endian

Ignacio Verab84e0c272b6e
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index b7f1b55f167..61fbee6c8b0 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -109,6 +109,8 @@ API Changes
only applicable for fields that are indexed with doc values only. (Mayya Sharipova,
Adrien Grand, Simon Willnauer)
+* LUCENE-9047: Directory API is now little endian. (Ignacio Vera, Adrien Grand)
+
Improvements
* LUCENE-9687: Hunspell support improvements: add API for spell-checking and suggestions, support compound words,
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java
index 9e6eb11d64a..45b3cc04995 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java
@@ -23,6 +23,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.FieldsProducer;
import org.apache.lucene.codecs.PostingsReaderBase;
@@ -131,7 +132,7 @@ public final class Lucene40BlockTreeTermsReader extends FieldsProducer {
try {
String termsName =
IndexFileNames.segmentFileName(segment, state.segmentSuffix, TERMS_EXTENSION);
- termsIn = state.directory.openInput(termsName, state.context);
+ termsIn = EndiannessReverserUtil.openInput(state.directory, termsName, state.context);
version =
CodecUtil.checkIndexHeader(
termsIn,
@@ -143,7 +144,7 @@ public final class Lucene40BlockTreeTermsReader extends FieldsProducer {
String indexName =
IndexFileNames.segmentFileName(segment, state.segmentSuffix, TERMS_INDEX_EXTENSION);
- indexIn = state.directory.openInput(indexName, state.context);
+ indexIn = EndiannessReverserUtil.openInput(state.directory, indexName, state.context);
CodecUtil.checkIndexHeader(
indexIn,
TERMS_INDEX_CODEC_NAME,
@@ -171,7 +172,7 @@ public final class Lucene40BlockTreeTermsReader extends FieldsProducer {
long indexLength = -1, termsLength = -1;
try (ChecksumIndexInput metaIn =
version >= VERSION_META_FILE
- ? state.directory.openChecksumInput(metaName, state.context)
+ ? EndiannessReverserUtil.openChecksumInput(state.directory, metaName, state.context)
: null) {
try {
final IndexInput indexMetaIn, termsMetaIn;
@@ -186,6 +187,7 @@ public final class Lucene40BlockTreeTermsReader extends FieldsProducer {
indexMetaIn = termsMetaIn = metaIn;
postingsReader.init(metaIn, state);
} else {
+ seekDir(termsIn);
seekDir(termsIn);
seekDir(indexIn);
indexMetaIn = indexIn;
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java
index 9ff51611991..dbb2892d012 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java
@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.CompoundDirectory;
import org.apache.lucene.index.CorruptIndexException;
@@ -74,6 +75,7 @@ final class Lucene50CompoundReader extends CompoundDirectory {
expectedLength += CodecUtil.footerLength();
handle = directory.openInput(dataFileName, context);
+ // DirectoryUtil.openInput(directory, dataFileName, context);
try {
CodecUtil.checkIndexHeader(
handle, Lucene50CompoundFormat.DATA_CODEC, version, version, si.getId(), "");
@@ -105,7 +107,7 @@ final class Lucene50CompoundReader extends CompoundDirectory {
byte[] segmentID, Directory dir, String entriesFileName) throws IOException {
Map<String, FileEntry> mapping = null;
try (ChecksumIndexInput entriesStream =
- dir.openChecksumInput(entriesFileName, IOContext.READONCE)) {
+ EndiannessReverserUtil.openChecksumInput(dir, entriesFileName, IOContext.READONCE)) {
Throwable priorE = null;
try {
version =
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50LiveDocsFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50LiveDocsFormat.java
index ebe76ae614e..5b1571a704c 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50LiveDocsFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50LiveDocsFormat.java
@@ -18,6 +18,7 @@ package org.apache.lucene.backward_codecs.lucene50;
import java.io.IOException;
import java.util.Collection;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.LiveDocsFormat;
import org.apache.lucene.index.CorruptIndexException;
@@ -68,7 +69,7 @@ public final class Lucene50LiveDocsFormat extends LiveDocsFormat {
long gen = info.getDelGen();
String name = IndexFileNames.fileNameFromGeneration(info.info.name, EXTENSION, gen);
final int length = info.info.maxDoc();
- try (ChecksumIndexInput input = dir.openChecksumInput(name, context)) {
+ try (ChecksumIndexInput input = EndiannessReverserUtil.openChecksumInput(dir, name, context)) {
Throwable priorE = null;
try {
CodecUtil.checkIndexHeader(
@@ -119,7 +120,7 @@ public final class Lucene50LiveDocsFormat extends LiveDocsFormat {
long gen = info.getNextDelGen();
String name = IndexFileNames.fileNameFromGeneration(info.info.name, EXTENSION, gen);
int delCount;
- try (IndexOutput output = dir.createOutput(name, context)) {
+ try (IndexOutput output = EndiannessReverserUtil.createOutput(dir, name, context)) {
CodecUtil.writeIndexHeader(
output,
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsReader.java
index 6156f3747b8..fcf700b4a16 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsReader.java
@@ -30,6 +30,7 @@ import static org.apache.lucene.backward_codecs.lucene50.Lucene50PostingsFormat.
import java.io.IOException;
import java.util.Arrays;
import org.apache.lucene.backward_codecs.lucene50.Lucene50PostingsFormat.IntBlockTermState;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.BlockTermState;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.PostingsReaderBase;
@@ -77,7 +78,7 @@ public final class Lucene50PostingsReader extends PostingsReaderBase {
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene50PostingsFormat.DOC_EXTENSION);
try {
- docIn = state.directory.openInput(docName, state.context);
+ docIn = EndiannessReverserUtil.openInput(state.directory, docName, state.context);
version =
CodecUtil.checkIndexHeader(
docIn,
@@ -93,7 +94,7 @@ public final class Lucene50PostingsReader extends PostingsReaderBase {
String proxName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene50PostingsFormat.POS_EXTENSION);
- posIn = state.directory.openInput(proxName, state.context);
+ posIn = EndiannessReverserUtil.openInput(state.directory, proxName, state.context);
CodecUtil.checkIndexHeader(
posIn, POS_CODEC, version, version, state.segmentInfo.getId(), state.segmentSuffix);
CodecUtil.retrieveChecksum(posIn);
@@ -104,7 +105,7 @@ public final class Lucene50PostingsReader extends PostingsReaderBase {
state.segmentInfo.name,
state.segmentSuffix,
Lucene50PostingsFormat.PAY_EXTENSION);
- payIn = state.directory.openInput(payName, state.context);
+ payIn = EndiannessReverserUtil.openInput(state.directory, payName, state.context);
CodecUtil.checkIndexHeader(
payIn, PAY_CODEC, version, version, state.segmentInfo.getId(), state.segmentSuffix);
CodecUtil.retrieveChecksum(payIn);
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50StoredFieldsFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50StoredFieldsFormat.java
index 0e5a6b5c451..05b6324dab5 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50StoredFieldsFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50StoredFieldsFormat.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene50;
import java.io.IOException;
import java.util.Objects;
import org.apache.lucene.backward_codecs.lucene50.compressing.Lucene50CompressingStoredFieldsFormat;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicWriter;
import org.apache.lucene.codecs.StoredFieldsFormat;
import org.apache.lucene.codecs.StoredFieldsReader;
import org.apache.lucene.codecs.StoredFieldsWriter;
@@ -28,7 +29,6 @@ import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.StoredFieldVisitor;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
-import org.apache.lucene.util.packed.DirectMonotonicWriter;
/**
* Lucene 5.0 stored fields format.
@@ -85,7 +85,7 @@ import org.apache.lucene.util.packed.DirectMonotonicWriter;
* </ul>
* <li><a id="field_index"></a>
* <p>A fields index file (extension <code>.fdx</code>). This file stores two {@link
- * DirectMonotonicWriter monotonic arrays}, one for the first doc IDs of each block of
+ * LegacyDirectMonotonicWriter monotonic arrays}, one for the first doc IDs of each block of
* compressed documents, and another one for the corresponding offsets on disk. At search
* time, the array containing doc IDs is binary-searched in order to find the block that
* contains the expected doc ID, and the associated offset on disk is retrieved from the
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexReader.java
index 286806c5eff..133acbcd581 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexReader.java
@@ -19,13 +19,14 @@ package org.apache.lucene.backward_codecs.lucene50.compressing;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Objects;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicReader;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.RandomAccessInput;
-import org.apache.lucene.util.packed.DirectMonotonicReader;
final class FieldsIndexReader extends FieldsIndex {
@@ -35,14 +36,14 @@ final class FieldsIndexReader extends FieldsIndex {
private final int maxDoc;
private final int blockShift;
private final int numChunks;
- private final DirectMonotonicReader.Meta docsMeta;
- private final DirectMonotonicReader.Meta startPointersMeta;
+ private final LegacyDirectMonotonicReader.Meta docsMeta;
+ private final LegacyDirectMonotonicReader.Meta startPointersMeta;
private final IndexInput indexInput;
private final long docsStartPointer,
docsEndPointer,
startPointersStartPointer,
startPointersEndPointer;
- private final DirectMonotonicReader docs, startPointers;
+ private final LegacyDirectMonotonicReader docs, startPointers;
private final long maxPointer;
FieldsIndexReader(
@@ -58,14 +59,15 @@ final class FieldsIndexReader extends FieldsIndex {
blockShift = metaIn.readInt();
numChunks = metaIn.readInt();
docsStartPointer = metaIn.readLong();
- docsMeta = DirectMonotonicReader.loadMeta(metaIn, numChunks, blockShift);
+ docsMeta = LegacyDirectMonotonicReader.loadMeta(metaIn, numChunks, blockShift);
docsEndPointer = startPointersStartPointer = metaIn.readLong();
- startPointersMeta = DirectMonotonicReader.loadMeta(metaIn, numChunks, blockShift);
+ startPointersMeta = LegacyDirectMonotonicReader.loadMeta(metaIn, numChunks, blockShift);
startPointersEndPointer = metaIn.readLong();
maxPointer = metaIn.readLong();
indexInput =
- dir.openInput(IndexFileNames.segmentFileName(name, suffix, extension), IOContext.READ);
+ EndiannessReverserUtil.openInput(
+ dir, IndexFileNames.segmentFileName(name, suffix, extension), IOContext.READ);
boolean success = false;
try {
CodecUtil.checkIndexHeader(
@@ -82,8 +84,8 @@ final class FieldsIndexReader extends FieldsIndex {
final RandomAccessInput startPointersSlice =
indexInput.randomAccessSlice(
startPointersStartPointer, startPointersEndPointer - startPointersStartPointer);
- docs = DirectMonotonicReader.getInstance(docsMeta, docsSlice);
- startPointers = DirectMonotonicReader.getInstance(startPointersMeta, startPointersSlice);
+ docs = LegacyDirectMonotonicReader.getInstance(docsMeta, docsSlice);
+ startPointers = LegacyDirectMonotonicReader.getInstance(startPointersMeta, startPointersSlice);
}
private FieldsIndexReader(FieldsIndexReader other) throws IOException {
@@ -103,8 +105,8 @@ final class FieldsIndexReader extends FieldsIndex {
final RandomAccessInput startPointersSlice =
indexInput.randomAccessSlice(
startPointersStartPointer, startPointersEndPointer - startPointersStartPointer);
- docs = DirectMonotonicReader.getInstance(docsMeta, docsSlice);
- startPointers = DirectMonotonicReader.getInstance(startPointersMeta, startPointersSlice);
+ docs = LegacyDirectMonotonicReader.getInstance(docsMeta, docsSlice);
+ startPointers = LegacyDirectMonotonicReader.getInstance(startPointersMeta, startPointersSlice);
}
@Override
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsFormat.java
index 982301b4a70..bdb3b4ecf35 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsFormat.java
@@ -17,6 +17,7 @@
package org.apache.lucene.backward_codecs.lucene50.compressing;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicWriter;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.StoredFieldsFormat;
import org.apache.lucene.codecs.StoredFieldsReader;
@@ -27,7 +28,6 @@ import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
-import org.apache.lucene.util.packed.DirectMonotonicWriter;
/**
* A {@link StoredFieldsFormat} that compresses documents in chunks in order to improve the
@@ -120,13 +120,13 @@ public class Lucene50CompressingStoredFieldsFormat extends StoredFieldsFormat {
throw new IllegalArgumentException("maxDocsPerChunk must be >= 1");
}
this.maxDocsPerChunk = maxDocsPerChunk;
- if (blockShift < DirectMonotonicWriter.MIN_BLOCK_SHIFT
- || blockShift > DirectMonotonicWriter.MAX_BLOCK_SHIFT) {
+ if (blockShift < LegacyDirectMonotonicWriter.MIN_BLOCK_SHIFT
+ || blockShift > LegacyDirectMonotonicWriter.MAX_BLOCK_SHIFT) {
throw new IllegalArgumentException(
"blockSize must be in "
- + DirectMonotonicWriter.MIN_BLOCK_SHIFT
+ + LegacyDirectMonotonicWriter.MIN_BLOCK_SHIFT
+ "-"
- + DirectMonotonicWriter.MAX_BLOCK_SHIFT
+ + LegacyDirectMonotonicWriter.MAX_BLOCK_SHIFT
+ ", got "
+ blockShift);
}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsReader.java
index d5b88afa6ba..fdda870dddc 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsReader.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene50.compressing;
import java.io.EOFException;
import java.io.IOException;
import java.util.Arrays;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.StoredFieldsReader;
import org.apache.lucene.codecs.compressing.CompressionMode;
@@ -143,7 +144,7 @@ public final class Lucene50CompressingStoredFieldsReader extends StoredFieldsRea
ChecksumIndexInput metaIn = null;
try {
// Open the data file
- fieldsStream = d.openInput(fieldsStreamFN, context);
+ fieldsStream = EndiannessReverserUtil.openInput(d, fieldsStreamFN, context);
version =
CodecUtil.checkIndexHeader(
fieldsStream, formatName, VERSION_START, VERSION_CURRENT, si.getId(), segmentSuffix);
@@ -153,7 +154,7 @@ public final class Lucene50CompressingStoredFieldsReader extends StoredFieldsRea
if (version >= VERSION_OFFHEAP_INDEX) {
final String metaStreamFN =
IndexFileNames.segmentFileName(segment, segmentSuffix, META_EXTENSION);
- metaIn = d.openChecksumInput(metaStreamFN, IOContext.READONCE);
+ metaIn = EndiannessReverserUtil.openChecksumInput(d, metaStreamFN, IOContext.READONCE);
CodecUtil.checkIndexHeader(
metaIn,
INDEX_CODEC_NAME + "Meta",
@@ -186,7 +187,8 @@ public final class Lucene50CompressingStoredFieldsReader extends StoredFieldsRea
if (version < VERSION_OFFHEAP_INDEX) {
// Load the index into memory
final String indexName = IndexFileNames.segmentFileName(segment, segmentSuffix, "fdx");
- try (ChecksumIndexInput indexStream = d.openChecksumInput(indexName, context)) {
+ try (ChecksumIndexInput indexStream =
+ EndiannessReverserUtil.openChecksumInput(d, indexName, context)) {
Throwable priorE = null;
try {
assert formatName.endsWith("Data");
@@ -682,7 +684,8 @@ public final class Lucene50CompressingStoredFieldsReader extends StoredFieldsRea
documentInput = new ByteArrayDataInput(bytes.bytes, bytes.offset, bytes.length);
}
- return new SerializedDocument(documentInput, length, numStoredFields);
+ return new SerializedDocument(
+ EndiannessReverserUtil.wrapDataInput(documentInput), length, numStoredFields);
}
}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsReader.java
index f21d8bb94af..fcd9756137b 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsReader.java
@@ -20,6 +20,7 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.apache.lucene.backward_codecs.packed.LegacyPackedInts;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.TermVectorsReader;
import org.apache.lucene.codecs.compressing.CompressionMode;
@@ -134,7 +135,7 @@ public final class Lucene50CompressingTermVectorsReader extends TermVectorsReade
// Open the data file
final String vectorsStreamFN =
IndexFileNames.segmentFileName(segment, segmentSuffix, VECTORS_EXTENSION);
- vectorsStream = d.openInput(vectorsStreamFN, context);
+ vectorsStream = EndiannessReverserUtil.openInput(d, vectorsStreamFN, context);
version =
CodecUtil.checkIndexHeader(
vectorsStream, formatName, VERSION_START, VERSION_CURRENT, si.getId(), segmentSuffix);
@@ -144,7 +145,7 @@ public final class Lucene50CompressingTermVectorsReader extends TermVectorsReade
if (version >= VERSION_OFFHEAP_INDEX) {
final String metaStreamFN =
IndexFileNames.segmentFileName(segment, segmentSuffix, VECTORS_META_EXTENSION);
- metaIn = d.openChecksumInput(metaStreamFN, IOContext.READONCE);
+ metaIn = EndiannessReverserUtil.openChecksumInput(d, metaStreamFN, IOContext.READONCE);
CodecUtil.checkIndexHeader(
metaIn,
VECTORS_INDEX_CODEC_NAME + "Meta",
@@ -174,7 +175,8 @@ public final class Lucene50CompressingTermVectorsReader extends TermVectorsReade
if (version < VERSION_OFFHEAP_INDEX) {
// Load the index into memory
final String indexName = IndexFileNames.segmentFileName(segment, segmentSuffix, "tvx");
- try (ChecksumIndexInput indexStream = d.openChecksumInput(indexName, context)) {
+ try (ChecksumIndexInput indexStream =
+ EndiannessReverserUtil.openChecksumInput(d, indexName, context)) {
Throwable priorE = null;
try {
assert formatName.endsWith("Data");
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60FieldInfosFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60FieldInfosFormat.java
index 67f530519b8..e3b5a9b8902 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60FieldInfosFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60FieldInfosFormat.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene60;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.FieldInfosFormat;
@@ -129,7 +130,8 @@ public final class Lucene60FieldInfosFormat extends FieldInfosFormat {
throws IOException {
final String fileName =
IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, EXTENSION);
- try (ChecksumIndexInput input = directory.openChecksumInput(fileName, context)) {
+ try (ChecksumIndexInput input =
+ EndiannessReverserUtil.openChecksumInput(directory, fileName, context)) {
Throwable priorE = null;
FieldInfo[] infos = null;
try {
@@ -326,7 +328,7 @@ public final class Lucene60FieldInfosFormat extends FieldInfosFormat {
throws IOException {
final String fileName =
IndexFileNames.segmentFileName(segmentInfo.name, segmentSuffix, EXTENSION);
- try (IndexOutput output = directory.createOutput(fileName, context)) {
+ try (IndexOutput output = EndiannessReverserUtil.createOutput(directory, fileName, context)) {
CodecUtil.writeIndexHeader(
output,
Lucene60FieldInfosFormat.CODEC_NAME,
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsReader.java
index deae623243e..c314a5d7844 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsReader.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene60;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.PointsReader;
import org.apache.lucene.index.FieldInfo;
@@ -50,7 +51,8 @@ public class Lucene60PointsReader extends PointsReader {
// Read index file
try (ChecksumIndexInput indexIn =
- readState.directory.openChecksumInput(indexFileName, readState.context)) {
+ EndiannessReverserUtil.openChecksumInput(
+ readState.directory, indexFileName, readState.context)) {
Throwable priorE = null;
try {
CodecUtil.checkIndexHeader(
@@ -79,7 +81,7 @@ public class Lucene60PointsReader extends PointsReader {
readState.segmentSuffix,
Lucene60PointsFormat.DATA_EXTENSION);
boolean success = false;
- dataIn = readState.directory.openInput(dataFileName, readState.context);
+ dataIn = EndiannessReverserUtil.openInput(readState.directory, dataFileName, readState.context);
try {
CodecUtil.checkIndexHeader(
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesConsumer.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesConsumer.java
index d1173b5b707..ec8909bac71 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesConsumer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesConsumer.java
@@ -26,6 +26,9 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicWriter;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectWriter;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesProducer;
@@ -49,8 +52,6 @@ import org.apache.lucene.util.BytesRefBuilder;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.MathUtil;
import org.apache.lucene.util.StringHelper;
-import org.apache.lucene.util.packed.DirectMonotonicWriter;
-import org.apache.lucene.util.packed.DirectWriter;
/** writer for {@link Lucene70DocValuesFormat} */
final class Lucene70DocValuesConsumer extends DocValuesConsumer {
@@ -71,7 +72,7 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
String dataName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, dataExtension);
- data = state.directory.createOutput(dataName, state.context);
+ data = EndiannessReverserUtil.createOutput(state.directory, dataName, state.context);
CodecUtil.writeIndexHeader(
data,
dataCodec,
@@ -81,7 +82,7 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
String metaName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, metaExtension);
- meta = state.directory.createOutput(metaName, state.context);
+ meta = EndiannessReverserUtil.createOutput(state.directory, metaName, state.context);
CodecUtil.writeIndexHeader(
meta,
metaCodec,
@@ -159,7 +160,7 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
/** Update the required space. */
void finish() {
if (max > min) {
- spaceInBits += DirectWriter.unsignedBitsRequired(max - min) * numValues;
+ spaceInBits += LegacyDirectWriter.unsignedBitsRequired(max - min) * numValues;
}
}
@@ -238,9 +239,9 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
} else {
if (uniqueValues != null
&& uniqueValues.size() > 1
- && DirectWriter.unsignedBitsRequired(uniqueValues.size() - 1)
- < DirectWriter.unsignedBitsRequired((max - min) / gcd)) {
- numBitsPerValue = DirectWriter.unsignedBitsRequired(uniqueValues.size() - 1);
+ && LegacyDirectWriter.unsignedBitsRequired(uniqueValues.size() - 1)
+ < LegacyDirectWriter.unsignedBitsRequired((max - min) / gcd)) {
+ numBitsPerValue = LegacyDirectWriter.unsignedBitsRequired(uniqueValues.size() - 1);
final Long[] sortedUniqueValues = uniqueValues.toArray(new Long[0]);
Arrays.sort(sortedUniqueValues);
meta.writeInt(sortedUniqueValues.length);
@@ -262,11 +263,11 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
numBitsPerValue = 0xFF;
meta.writeInt(-2 - NUMERIC_BLOCK_SHIFT);
} else {
- numBitsPerValue = DirectWriter.unsignedBitsRequired((max - min) / gcd);
+ numBitsPerValue = LegacyDirectWriter.unsignedBitsRequired((max - min) / gcd);
if (gcd == 1
&& min > 0
- && DirectWriter.unsignedBitsRequired(max)
- == DirectWriter.unsignedBitsRequired(max - min)) {
+ && LegacyDirectWriter.unsignedBitsRequired(max)
+ == LegacyDirectWriter.unsignedBitsRequired(max - min)) {
min = 0;
}
meta.writeInt(-1);
@@ -298,7 +299,7 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
long gcd,
Map<Long, Integer> encode)
throws IOException {
- DirectWriter writer = DirectWriter.getInstance(data, numValues, numBitsPerValue);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(data, numValues, numBitsPerValue);
for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
for (int i = 0, count = values.docValueCount(); i < count; ++i) {
long v = values.nextValue();
@@ -346,10 +347,10 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
data.writeByte((byte) 0);
data.writeLong(min);
} else {
- final int bitsPerValue = DirectWriter.unsignedBitsRequired(max - min);
+ final int bitsPerValue = LegacyDirectWriter.unsignedBitsRequired(max - min);
buffer.reset();
assert buffer.size() == 0;
- final DirectWriter w = DirectWriter.getInstance(buffer, length, bitsPerValue);
+ final LegacyDirectWriter w = LegacyDirectWriter.getInstance(buffer, length, bitsPerValue);
for (int i = 0; i < length; ++i) {
w.add((values[i] - min) / gcd);
}
@@ -405,8 +406,8 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(start);
meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
- final DirectMonotonicWriter writer =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter writer =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, numDocsWithField + 1, DIRECT_MONOTONIC_BLOCK_SHIFT);
long addr = 0;
writer.add(addr);
@@ -457,11 +458,12 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(0L);
meta.writeLong(0L);
} else {
- int numberOfBitsPerOrd = DirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
+ int numberOfBitsPerOrd = LegacyDirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
meta.writeByte((byte) numberOfBitsPerOrd);
long start = data.getFilePointer();
meta.writeLong(start);
- DirectWriter writer = DirectWriter.getInstance(data, numDocsWithField, numberOfBitsPerOrd);
+ LegacyDirectWriter writer =
+ LegacyDirectWriter.getInstance(data, numDocsWithField, numberOfBitsPerOrd);
values = valuesProducer.getSorted(field);
for (int doc = values.nextDoc();
doc != DocIdSetIterator.NO_MORE_DOCS;
@@ -487,8 +489,8 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
long numBlocks =
(size + Lucene70DocValuesFormat.TERMS_DICT_BLOCK_MASK)
>>> Lucene70DocValuesFormat.TERMS_DICT_BLOCK_SHIFT;
- DirectMonotonicWriter writer =
- DirectMonotonicWriter.getInstance(
+ LegacyDirectMonotonicWriter writer =
+ LegacyDirectMonotonicWriter.getInstance(
meta, addressIndexOut, numBlocks, DIRECT_MONOTONIC_BLOCK_SHIFT);
BytesRefBuilder previous = new BytesRefBuilder();
@@ -544,8 +546,8 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
ByteBuffersDataOutput addressBuffer = new ByteBuffersDataOutput();
ByteBuffersIndexOutput addressIndexOut =
new ByteBuffersIndexOutput(addressBuffer, "temp", "temp");
- DirectMonotonicWriter writer =
- DirectMonotonicWriter.getInstance(
+ LegacyDirectMonotonicWriter writer =
+ LegacyDirectMonotonicWriter.getInstance(
meta, addressIndexOut, numBlocks, DIRECT_MONOTONIC_BLOCK_SHIFT);
TermsEnum iterator = values.termsEnum();
@@ -597,8 +599,8 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(start);
meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
- final DirectMonotonicWriter addressesWriter =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter addressesWriter =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, numDocsWithField + 1L, DIRECT_MONOTONIC_BLOCK_SHIFT);
long addr = 0;
addressesWriter.add(addr);
@@ -659,11 +661,11 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(data.getFilePointer() - offset);
}
- int numberOfBitsPerOrd = DirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
+ int numberOfBitsPerOrd = LegacyDirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
meta.writeByte((byte) numberOfBitsPerOrd);
long start = data.getFilePointer();
meta.writeLong(start);
- DirectWriter writer = DirectWriter.getInstance(data, numOrds, numberOfBitsPerOrd);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(data, numOrds, numberOfBitsPerOrd);
values = valuesProducer.getSortedSet(field);
for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
for (long ord = values.nextOrd();
@@ -680,8 +682,8 @@ final class Lucene70DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(start);
meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
- final DirectMonotonicWriter addressesWriter =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter addressesWriter =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, numDocsWithField + 1, DIRECT_MONOTONIC_BLOCK_SHIFT);
long addr = 0;
addressesWriter.add(addr);
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesFormat.java
index 8cc25170450..f061dfc4d13 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesFormat.java
@@ -17,6 +17,7 @@
package org.apache.lucene.backward_codecs.lucene70;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectWriter;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.DocValuesProducer;
@@ -26,7 +27,6 @@ import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.store.DataOutput;
import org.apache.lucene.util.SmallFloat;
-import org.apache.lucene.util.packed.DirectWriter;
/**
* Lucene 7.0 DocValues format.
@@ -64,11 +64,11 @@ import org.apache.lucene.util.packed.DirectWriter;
*
* <ul>
* <li>Delta-compressed: per-document integers written as deltas from the minimum value,
- * compressed with bitpacking. For more information, see {@link DirectWriter}.
+ * compressed with bitpacking. For more information, see {@link LegacyDirectWriter}.
* <li>Table-compressed: when the number of unique values is very small (&lt; 256), and when there
* are unused "gaps" in the range of values used (such as {@link SmallFloat}), a lookup table
* is written instead. Each per-document entry is instead the ordinal to this table, and those
- * ordinals are compressed with bitpacking ({@link DirectWriter}).
+ * ordinals are compressed with bitpacking ({@link LegacyDirectWriter}).
* <li>GCD-compressed: when all numbers share a common divisor, such as dates, the greatest common
* denominator (GCD) is computed, and quotients are stored using Delta-compressed Numerics.
* <li>Monotonic-compressed: when all numbers are monotonically increasing offsets, they are
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesProducer.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesProducer.java
index bb8a89bd57f..dbe98037ea6 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesProducer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70DocValuesProducer.java
@@ -19,6 +19,9 @@ package org.apache.lucene.backward_codecs.lucene70;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicReader;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectReader;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BaseTermsEnum;
@@ -43,8 +46,6 @@ import org.apache.lucene.store.RandomAccessInput;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LongValues;
-import org.apache.lucene.util.packed.DirectMonotonicReader;
-import org.apache.lucene.util.packed.DirectReader;
/** reader for {@link Lucene70DocValuesFormat} */
final class Lucene70DocValuesProducer extends DocValuesProducer {
@@ -71,7 +72,8 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
int version = -1;
// read in the entries from the metadata file.
- try (ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context)) {
+ try (ChecksumIndexInput in =
+ EndiannessReverserUtil.openChecksumInput(state.directory, metaName, state.context)) {
Throwable priorE = null;
try {
version =
@@ -92,7 +94,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
String dataName =
IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
- this.data = state.directory.openInput(dataName, state.context);
+ this.data = EndiannessReverserUtil.openInput(state.directory, dataName, state.context);
boolean success = false;
try {
final int version2 =
@@ -190,7 +192,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
entry.addressesOffset = meta.readLong();
final int blockShift = meta.readVInt();
entry.addressesMeta =
- DirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1L, blockShift);
+ LegacyDirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1L, blockShift);
entry.addressesLength = meta.readLong();
}
return entry;
@@ -229,7 +231,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
entry.addressesOffset = meta.readLong();
final int blockShift = meta.readVInt();
entry.addressesMeta =
- DirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
+ LegacyDirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
entry.addressesLength = meta.readLong();
readTermDict(meta, entry);
return entry;
@@ -242,7 +244,8 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
final int blockShift = meta.readInt();
final long addressesSize =
(entry.termsDictSize + (1L << entry.termsDictBlockShift) - 1) >>> entry.termsDictBlockShift;
- entry.termsAddressesMeta = DirectMonotonicReader.loadMeta(meta, addressesSize, blockShift);
+ entry.termsAddressesMeta =
+ LegacyDirectMonotonicReader.loadMeta(meta, addressesSize, blockShift);
entry.maxTermLength = meta.readInt();
entry.termsDataOffset = meta.readLong();
entry.termsDataLength = meta.readLong();
@@ -251,7 +254,8 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
entry.termsDictIndexShift = meta.readInt();
final long indexSize =
(entry.termsDictSize + (1L << entry.termsDictIndexShift) - 1) >>> entry.termsDictIndexShift;
- entry.termsIndexAddressesMeta = DirectMonotonicReader.loadMeta(meta, 1 + indexSize, blockShift);
+ entry.termsIndexAddressesMeta =
+ LegacyDirectMonotonicReader.loadMeta(meta, 1 + indexSize, blockShift);
entry.termsIndexOffset = meta.readLong();
entry.termsIndexLength = meta.readLong();
entry.termsIndexAddressesOffset = meta.readLong();
@@ -266,7 +270,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
entry.addressesOffset = meta.readLong();
final int blockShift = meta.readVInt();
entry.addressesMeta =
- DirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
+ LegacyDirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
entry.addressesLength = meta.readLong();
}
return entry;
@@ -300,20 +304,20 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
int maxLength;
long addressesOffset;
long addressesLength;
- DirectMonotonicReader.Meta addressesMeta;
+ LegacyDirectMonotonicReader.Meta addressesMeta;
}
private static class TermsDictEntry {
long termsDictSize;
int termsDictBlockShift;
- DirectMonotonicReader.Meta termsAddressesMeta;
+ LegacyDirectMonotonicReader.Meta termsAddressesMeta;
int maxTermLength;
long termsDataOffset;
long termsDataLength;
long termsAddressesOffset;
long termsAddressesLength;
int termsDictIndexShift;
- DirectMonotonicReader.Meta termsIndexAddressesMeta;
+ LegacyDirectMonotonicReader.Meta termsIndexAddressesMeta;
long termsIndexOffset;
long termsIndexLength;
long termsIndexAddressesOffset;
@@ -337,14 +341,14 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
byte bitsPerValue;
long ordsOffset;
long ordsLength;
- DirectMonotonicReader.Meta addressesMeta;
+ LegacyDirectMonotonicReader.Meta addressesMeta;
long addressesOffset;
long addressesLength;
}
private static class SortedNumericEntry extends NumericEntry {
int numDocsWithField;
- DirectMonotonicReader.Meta addressesMeta;
+ LegacyDirectMonotonicReader.Meta addressesMeta;
long addressesOffset;
long addressesLength;
}
@@ -478,13 +482,13 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
values =
bitsPerValue == 0
? LongValues.ZEROES
- : DirectReader.getInstance(slice, bitsPerValue, offset);
+ : LegacyDirectReader.getInstance(slice, bitsPerValue, offset);
}
return mul * values.get(doc & mask) + delta;
}
};
} else {
- final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues values = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
if (entry.table != null) {
final long[] table = entry.table;
return new DenseNumericDocValues(maxDoc) {
@@ -555,13 +559,13 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
values =
bitsPerValue == 0
? LongValues.ZEROES
- : DirectReader.getInstance(slice, bitsPerValue, offset);
+ : LegacyDirectReader.getInstance(slice, bitsPerValue, offset);
}
return mul * values.get(index & mask) + delta;
}
};
} else {
- final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues values = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
if (entry.table != null) {
final long[] table = entry.table;
return new SparseNumericDocValues(disi) {
@@ -635,13 +639,13 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
values =
bitsPerValue == 0
? LongValues.ZEROES
- : DirectReader.getInstance(slice, bitsPerValue, offset);
+ : LegacyDirectReader.getInstance(slice, bitsPerValue, offset);
}
return mul * values.get(index & mask) + delta;
}
};
} else {
- final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues values = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
if (entry.table != null) {
final long[] table = entry.table;
return new LongValues() {
@@ -776,7 +780,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesData =
this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
return new DenseBinaryDocValues(maxDoc) {
final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
@@ -813,7 +817,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesData =
this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
return new SparseBinaryDocValues(disi) {
final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
@@ -853,7 +857,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
};
} else {
final RandomAccessInput slice = data.randomAccessSlice(entry.ordsOffset, entry.ordsLength);
- ords = DirectReader.getInstance(slice, entry.bitsPerValue);
+ ords = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
}
if (entry.docsWithFieldOffset == -1) {
@@ -1035,13 +1039,15 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
this.entry = entry;
RandomAccessInput addressesSlice =
data.randomAccessSlice(entry.termsAddressesOffset, entry.termsAddressesLength);
- blockAddresses = DirectMonotonicReader.getInstance(entry.termsAddressesMeta, addressesSlice);
+ blockAddresses =
+ LegacyDirectMonotonicReader.getInstance(entry.termsAddressesMeta, addressesSlice);
bytes = data.slice("terms", entry.termsDataOffset, entry.termsDataLength);
blockMask = (1L << entry.termsDictBlockShift) - 1;
RandomAccessInput indexAddressesSlice =
data.randomAccessSlice(entry.termsIndexAddressesOffset, entry.termsIndexAddressesLength);
indexAddresses =
- DirectMonotonicReader.getInstance(entry.termsIndexAddressesMeta, indexAddressesSlice);
+ LegacyDirectMonotonicReader.getInstance(
+ entry.termsIndexAddressesMeta, indexAddressesSlice);
indexBytes = data.slice("terms-index", entry.termsIndexOffset, entry.termsIndexLength);
term = new BytesRef(entry.maxTermLength);
}
@@ -1220,7 +1226,7 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesInput =
data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
final LongValues values = getNumericValues(entry);
@@ -1349,12 +1355,12 @@ final class Lucene70DocValuesProducer extends DocValuesProducer {
}
final RandomAccessInput slice = data.randomAccessSlice(entry.ordsOffset, entry.ordsLength);
- final LongValues ords = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues ords = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
final RandomAccessInput addressesInput =
data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
if (entry.docsWithFieldOffset == -1) {
// dense
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsProducer.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsProducer.java
index bf68c9e44e3..94dc70b0b14 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsProducer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsProducer.java
@@ -22,6 +22,7 @@ import static org.apache.lucene.backward_codecs.lucene70.Lucene70NormsFormat.VER
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.NormsProducer;
import org.apache.lucene.index.CorruptIndexException;
@@ -59,7 +60,8 @@ final class Lucene70NormsProducer extends NormsProducer implements Cloneable {
int version = -1;
// read in the entries from the metadata file.
- try (ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context)) {
+ try (ChecksumIndexInput in =
+ EndiannessReverserUtil.openChecksumInput(state.directory, metaName, state.context)) {
Throwable priorE = null;
try {
version =
@@ -80,7 +82,7 @@ final class Lucene70NormsProducer extends NormsProducer implements Cloneable {
String dataName =
IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
- data = state.directory.openInput(dataName, state.context);
+ data = EndiannessReverserUtil.openInput(state.directory, dataName, state.context);
boolean success = false;
try {
final int version2 =
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70SegmentInfoFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70SegmentInfoFormat.java
index b7f18194d20..d89350e9df4 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70SegmentInfoFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene70/Lucene70SegmentInfoFormat.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene70;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.index.CorruptIndexException;
@@ -102,7 +103,8 @@ public class Lucene70SegmentInfoFormat extends SegmentInfoFormat {
throws IOException {
final String fileName =
IndexFileNames.segmentFileName(segment, "", Lucene70SegmentInfoFormat.SI_EXTENSION);
- try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {
+ try (ChecksumIndexInput input =
+ EndiannessReverserUtil.openChecksumInput(dir, fileName, context)) {
Throwable priorE = null;
SegmentInfo si = null;
try {
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesConsumer.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesConsumer.java
index 12d97c008eb..1d3bc39ea89 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesConsumer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesConsumer.java
@@ -27,6 +27,9 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicWriter;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectWriter;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesProducer;
@@ -58,8 +61,6 @@ import org.apache.lucene.util.MathUtil;
import org.apache.lucene.util.StringHelper;
import org.apache.lucene.util.compress.LZ4;
import org.apache.lucene.util.compress.LZ4.FastCompressionHashTable;
-import org.apache.lucene.util.packed.DirectMonotonicWriter;
-import org.apache.lucene.util.packed.DirectWriter;
/** writer for {@link Lucene80DocValuesFormat} */
final class Lucene80DocValuesConsumer extends DocValuesConsumer {
@@ -89,7 +90,7 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
String dataName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, dataExtension);
- data = state.directory.createOutput(dataName, state.context);
+ data = EndiannessReverserUtil.createOutput(state.directory, dataName, state.context);
CodecUtil.writeIndexHeader(
data,
dataCodec,
@@ -99,7 +100,7 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
String metaName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, metaExtension);
- meta = state.directory.createOutput(metaName, state.context);
+ meta = EndiannessReverserUtil.createOutput(state.directory, metaName, state.context);
CodecUtil.writeIndexHeader(
meta,
metaCodec,
@@ -177,7 +178,7 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
/** Update the required space. */
void finish() {
if (max > min) {
- spaceInBits += DirectWriter.unsignedBitsRequired(max - min) * numValues;
+ spaceInBits += LegacyDirectWriter.unsignedBitsRequired(max - min) * numValues;
}
}
@@ -263,9 +264,9 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
} else {
if (uniqueValues != null
&& uniqueValues.size() > 1
- && DirectWriter.unsignedBitsRequired(uniqueValues.size() - 1)
- < DirectWriter.unsignedBitsRequired((max - min) / gcd)) {
- numBitsPerValue = DirectWriter.unsignedBitsRequired(uniqueValues.size() - 1);
+ && LegacyDirectWriter.unsignedBitsRequired(uniqueValues.size() - 1)
+ < LegacyDirectWriter.unsignedBitsRequired((max - min) / gcd)) {
+ numBitsPerValue = LegacyDirectWriter.unsignedBitsRequired(uniqueValues.size() - 1);
final Long[] sortedUniqueValues = uniqueValues.toArray(new Long[0]);
Arrays.sort(sortedUniqueValues);
meta.writeInt(sortedUniqueValues.length); // tablesize
@@ -287,11 +288,11 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
numBitsPerValue = 0xFF;
meta.writeInt(-2 - NUMERIC_BLOCK_SHIFT); // tablesize
} else {
- numBitsPerValue = DirectWriter.unsignedBitsRequired((max - min) / gcd);
+ numBitsPerValue = LegacyDirectWriter.unsignedBitsRequired((max - min) / gcd);
if (gcd == 1
&& min > 0
- && DirectWriter.unsignedBitsRequired(max)
- == DirectWriter.unsignedBitsRequired(max - min)) {
+ && LegacyDirectWriter.unsignedBitsRequired(max)
+ == LegacyDirectWriter.unsignedBitsRequired(max - min)) {
min = 0;
}
meta.writeInt(-1); // tablesize
@@ -324,7 +325,7 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
long gcd,
Map<Long, Integer> encode)
throws IOException {
- DirectWriter writer = DirectWriter.getInstance(data, numValues, numBitsPerValue);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(data, numValues, numBitsPerValue);
for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
for (int i = 0, count = values.docValueCount(); i < count; ++i) {
long v = values.nextValue();
@@ -387,10 +388,10 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
data.writeByte((byte) 0);
data.writeLong(min);
} else {
- final int bitsPerValue = DirectWriter.unsignedBitsRequired(max - min);
+ final int bitsPerValue = LegacyDirectWriter.unsignedBitsRequired(max - min);
buffer.reset();
assert buffer.size() == 0;
- final DirectWriter w = DirectWriter.getInstance(buffer, length, bitsPerValue);
+ final LegacyDirectWriter w = LegacyDirectWriter.getInstance(buffer, length, bitsPerValue);
for (int i = 0; i < length; ++i) {
w.add((values[i] - min) / gcd);
}
@@ -417,8 +418,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
public CompressedBinaryBlockWriter() throws IOException {
tempBinaryOffsets =
- state.directory.createTempOutput(
- state.segmentInfo.name, "binary_pointers", state.context);
+ EndiannessReverserUtil.createTempOutput(
+ state.directory, state.segmentInfo.name, "binary_pointers", state.context);
boolean success = false;
try {
CodecUtil.writeHeader(
@@ -502,7 +503,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
IOUtils.close(tempBinaryOffsets);
// write the compressed block offsets info to the meta file by reading from temp file
try (ChecksumIndexInput filePointersIn =
- state.directory.openChecksumInput(tempBinaryOffsets.getName(), IOContext.READONCE)) {
+ EndiannessReverserUtil.openChecksumInput(
+ state.directory, tempBinaryOffsets.getName(), IOContext.READONCE)) {
CodecUtil.checkHeader(
filePointersIn,
Lucene80DocValuesFormat.META_CODEC + "FilePointers",
@@ -510,8 +512,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
Lucene80DocValuesFormat.VERSION_CURRENT);
Throwable priorE = null;
try {
- final DirectMonotonicWriter filePointers =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter filePointers =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, totalChunks, DIRECT_MONOTONIC_BLOCK_SHIFT);
long fp = blockAddressesStart;
for (int i = 0; i < totalChunks; ++i) {
@@ -609,8 +611,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(start);
meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
- final DirectMonotonicWriter writer =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter writer =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, numDocsWithField + 1, DIRECT_MONOTONIC_BLOCK_SHIFT);
long addr = 0;
writer.add(addr);
@@ -721,11 +723,12 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(0L); // ordsOffset
meta.writeLong(0L); // ordsLength
} else {
- int numberOfBitsPerOrd = DirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
+ int numberOfBitsPerOrd = LegacyDirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
meta.writeByte((byte) numberOfBitsPerOrd); // bitsPerValue
long start = data.getFilePointer();
meta.writeLong(start); // ordsOffset
- DirectWriter writer = DirectWriter.getInstance(data, numDocsWithField, numberOfBitsPerOrd);
+ LegacyDirectWriter writer =
+ LegacyDirectWriter.getInstance(data, numDocsWithField, numberOfBitsPerOrd);
values = valuesProducer.getSorted(field);
for (int doc = values.nextDoc();
doc != DocIdSetIterator.NO_MORE_DOCS;
@@ -762,8 +765,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
ByteBuffersIndexOutput addressOutput =
new ByteBuffersIndexOutput(addressBuffer, "temp", "temp");
long numBlocks = (size + blockMask) >>> shift;
- DirectMonotonicWriter writer =
- DirectMonotonicWriter.getInstance(
+ LegacyDirectMonotonicWriter writer =
+ LegacyDirectMonotonicWriter.getInstance(
meta, addressOutput, numBlocks, DIRECT_MONOTONIC_BLOCK_SHIFT);
BytesRefBuilder previous = new BytesRefBuilder();
@@ -870,11 +873,11 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
+ ((size + Lucene80DocValuesFormat.TERMS_DICT_REVERSE_INDEX_MASK)
>>> Lucene80DocValuesFormat.TERMS_DICT_REVERSE_INDEX_SHIFT);
ByteBuffersDataOutput addressBuffer = new ByteBuffersDataOutput();
- DirectMonotonicWriter writer;
+ LegacyDirectMonotonicWriter writer;
try (ByteBuffersIndexOutput addressOutput =
new ByteBuffersIndexOutput(addressBuffer, "temp", "temp")) {
writer =
- DirectMonotonicWriter.getInstance(
+ LegacyDirectMonotonicWriter.getInstance(
meta, addressOutput, numBlocks, DIRECT_MONOTONIC_BLOCK_SHIFT);
TermsEnum iterator = values.termsEnum();
BytesRefBuilder previous = new BytesRefBuilder();
@@ -926,8 +929,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(start);
meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
- final DirectMonotonicWriter addressesWriter =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter addressesWriter =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, numDocsWithField + 1L, DIRECT_MONOTONIC_BLOCK_SHIFT);
long addr = 0;
addressesWriter.add(addr);
@@ -993,11 +996,11 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
meta.writeByte(IndexedDISI.DEFAULT_DENSE_RANK_POWER);
}
- int numberOfBitsPerOrd = DirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
+ int numberOfBitsPerOrd = LegacyDirectWriter.unsignedBitsRequired(values.getValueCount() - 1);
meta.writeByte((byte) numberOfBitsPerOrd); // bitsPerValue
long start = data.getFilePointer();
meta.writeLong(start); // ordsOffset
- DirectWriter writer = DirectWriter.getInstance(data, numOrds, numberOfBitsPerOrd);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(data, numOrds, numberOfBitsPerOrd);
values = valuesProducer.getSortedSet(field);
for (int doc = values.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = values.nextDoc()) {
for (long ord = values.nextOrd();
@@ -1014,8 +1017,8 @@ final class Lucene80DocValuesConsumer extends DocValuesConsumer {
meta.writeLong(start); // addressesOffset
meta.writeVInt(DIRECT_MONOTONIC_BLOCK_SHIFT);
- final DirectMonotonicWriter addressesWriter =
- DirectMonotonicWriter.getInstance(
+ final LegacyDirectMonotonicWriter addressesWriter =
+ LegacyDirectMonotonicWriter.getInstance(
meta, data, numDocsWithField + 1, DIRECT_MONOTONIC_BLOCK_SHIFT);
long addr = 0;
addressesWriter.add(addr);
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesFormat.java
index 3dde8a74c7c..4ddfeffc049 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesFormat.java
@@ -18,6 +18,7 @@ package org.apache.lucene.backward_codecs.lucene80;
import java.io.IOException;
import java.util.Objects;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectWriter;
import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.DocValuesProducer;
@@ -27,7 +28,6 @@ import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
import org.apache.lucene.store.DataOutput;
import org.apache.lucene.util.SmallFloat;
-import org.apache.lucene.util.packed.DirectWriter;
/**
* Lucene 8.0 DocValues format.
@@ -74,11 +74,11 @@ import org.apache.lucene.util.packed.DirectWriter;
*
* <ul>
* <li>Delta-compressed: per-document integers written as deltas from the minimum value,
- * compressed with bitpacking. For more information, see {@link DirectWriter}.
+ * compressed with bitpacking. For more information, see {@link LegacyDirectWriter}.
* <li>Table-compressed: when the number of unique values is very small (&lt; 256), and when there
* are unused "gaps" in the range of values used (such as {@link SmallFloat}), a lookup table
* is written instead. Each per-document entry is instead the ordinal to this table, and those
- * ordinals are compressed with bitpacking ({@link DirectWriter}).
+ * ordinals are compressed with bitpacking ({@link LegacyDirectWriter}).
* <li>GCD-compressed: when all numbers share a common divisor, such as dates, the greatest common
* denominator (GCD) is computed, and quotients are stored using Delta-compressed Numerics.
* <li>Monotonic-compressed: when all numbers are monotonically increasing offsets, they are
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesProducer.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesProducer.java
index 2eb536647e9..98b4a8a08ad 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesProducer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80DocValuesProducer.java
@@ -19,6 +19,9 @@ package org.apache.lucene.backward_codecs.lucene80;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicReader;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectReader;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.index.BaseTermsEnum;
@@ -46,8 +49,6 @@ import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LongValues;
import org.apache.lucene.util.compress.LZ4;
-import org.apache.lucene.util.packed.DirectMonotonicReader;
-import org.apache.lucene.util.packed.DirectReader;
/** reader for {@link Lucene80DocValuesFormat} */
final class Lucene80DocValuesProducer extends DocValuesProducer {
@@ -73,7 +74,8 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
this.maxDoc = state.segmentInfo.maxDoc();
// read in the entries from the metadata file.
- try (ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context)) {
+ try (ChecksumIndexInput in =
+ EndiannessReverserUtil.openChecksumInput(state.directory, metaName, state.context)) {
Throwable priorE = null;
try {
@@ -97,7 +99,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
String dataName =
IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
- this.data = state.directory.openInput(dataName, state.context);
+ this.data = EndiannessReverserUtil.openInput(state.directory, dataName, state.context);
boolean success = false;
try {
final int version2 =
@@ -229,7 +231,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
}
final int blockShift = meta.readVInt();
- entry.addressesMeta = DirectMonotonicReader.loadMeta(meta, numAddresses, blockShift);
+ entry.addressesMeta = LegacyDirectMonotonicReader.loadMeta(meta, numAddresses, blockShift);
entry.addressesLength = meta.readLong();
}
return entry;
@@ -272,7 +274,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
entry.addressesOffset = meta.readLong();
final int blockShift = meta.readVInt();
entry.addressesMeta =
- DirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
+ LegacyDirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
entry.addressesLength = meta.readLong();
readTermDict(meta, entry);
return entry;
@@ -292,7 +294,8 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
final int blockShift = meta.readInt();
final long addressesSize =
(entry.termsDictSize + (1L << entry.termsDictBlockShift) - 1) >>> entry.termsDictBlockShift;
- entry.termsAddressesMeta = DirectMonotonicReader.loadMeta(meta, addressesSize, blockShift);
+ entry.termsAddressesMeta =
+ LegacyDirectMonotonicReader.loadMeta(meta, addressesSize, blockShift);
entry.maxTermLength = meta.readInt();
// Read one more int for compressed term dict.
if (entry.compressed) {
@@ -305,7 +308,8 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
entry.termsDictIndexShift = meta.readInt();
final long indexSize =
(entry.termsDictSize + (1L << entry.termsDictIndexShift) - 1) >>> entry.termsDictIndexShift;
- entry.termsIndexAddressesMeta = DirectMonotonicReader.loadMeta(meta, 1 + indexSize, blockShift);
+ entry.termsIndexAddressesMeta =
+ LegacyDirectMonotonicReader.loadMeta(meta, 1 + indexSize, blockShift);
entry.termsIndexOffset = meta.readLong();
entry.termsIndexLength = meta.readLong();
entry.termsIndexAddressesOffset = meta.readLong();
@@ -320,7 +324,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
entry.addressesOffset = meta.readLong();
final int blockShift = meta.readVInt();
entry.addressesMeta =
- DirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
+ LegacyDirectMonotonicReader.loadMeta(meta, entry.numDocsWithField + 1, blockShift);
entry.addressesLength = meta.readLong();
}
return entry;
@@ -360,7 +364,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
int maxLength;
long addressesOffset;
long addressesLength;
- DirectMonotonicReader.Meta addressesMeta;
+ LegacyDirectMonotonicReader.Meta addressesMeta;
int numCompressedChunks;
int docsPerChunkShift;
int maxUncompressedChunkSize;
@@ -369,14 +373,14 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
private static class TermsDictEntry {
long termsDictSize;
int termsDictBlockShift;
- DirectMonotonicReader.Meta termsAddressesMeta;
+ LegacyDirectMonotonicReader.Meta termsAddressesMeta;
int maxTermLength;
long termsDataOffset;
long termsDataLength;
long termsAddressesOffset;
long termsAddressesLength;
int termsDictIndexShift;
- DirectMonotonicReader.Meta termsIndexAddressesMeta;
+ LegacyDirectMonotonicReader.Meta termsIndexAddressesMeta;
long termsIndexOffset;
long termsIndexLength;
long termsIndexAddressesOffset;
@@ -407,14 +411,14 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
byte bitsPerValue;
long ordsOffset;
long ordsLength;
- DirectMonotonicReader.Meta addressesMeta;
+ LegacyDirectMonotonicReader.Meta addressesMeta;
long addressesOffset;
long addressesLength;
}
private static class SortedNumericEntry extends NumericEntry {
int numDocsWithField;
- DirectMonotonicReader.Meta addressesMeta;
+ LegacyDirectMonotonicReader.Meta addressesMeta;
long addressesOffset;
long addressesLength;
}
@@ -525,7 +529,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
}
};
} else {
- final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues values = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
if (entry.table != null) {
final long[] table = entry.table;
return new DenseNumericDocValues(maxDoc) {
@@ -578,7 +582,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
}
};
} else {
- final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues values = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
if (entry.table != null) {
final long[] table = entry.table;
return new SparseNumericDocValues(disi) {
@@ -627,7 +631,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
}
};
} else {
- final LongValues values = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues values = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
if (entry.table != null) {
final long[] table = entry.table;
return new LongValues() {
@@ -760,7 +764,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesData =
this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
return new DenseBinaryDocValues(maxDoc) {
final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
@@ -802,7 +806,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesData =
this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
return new SparseBinaryDocValues(disi) {
final BytesRef bytes = new BytesRef(new byte[entry.maxLength], 0, entry.maxLength);
@@ -924,7 +928,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesData =
this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
return new DenseBinaryDocValues(maxDoc) {
BinaryDecoder decoder =
new BinaryDecoder(
@@ -948,7 +952,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesData =
this.data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesData);
return new SparseBinaryDocValues(disi) {
BinaryDecoder decoder =
new BinaryDecoder(
@@ -984,7 +988,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
};
} else {
final RandomAccessInput slice = data.randomAccessSlice(entry.ordsOffset, entry.ordsLength);
- ords = DirectReader.getInstance(slice, entry.bitsPerValue);
+ ords = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
}
if (entry.docsWithFieldOffset == -1) {
@@ -1177,13 +1181,15 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
this.entry = entry;
RandomAccessInput addressesSlice =
data.randomAccessSlice(entry.termsAddressesOffset, entry.termsAddressesLength);
- blockAddresses = DirectMonotonicReader.getInstance(entry.termsAddressesMeta, addressesSlice);
+ blockAddresses =
+ LegacyDirectMonotonicReader.getInstance(entry.termsAddressesMeta, addressesSlice);
bytes = data.slice("terms", entry.termsDataOffset, entry.termsDataLength);
blockMask = (1L << entry.termsDictBlockShift) - 1;
RandomAccessInput indexAddressesSlice =
data.randomAccessSlice(entry.termsIndexAddressesOffset, entry.termsIndexAddressesLength);
indexAddresses =
- DirectMonotonicReader.getInstance(entry.termsIndexAddressesMeta, indexAddressesSlice);
+ LegacyDirectMonotonicReader.getInstance(
+ entry.termsIndexAddressesMeta, indexAddressesSlice);
indexBytes = data.slice("terms-index", entry.termsIndexOffset, entry.termsIndexLength);
term = new BytesRef(entry.maxTermLength);
@@ -1403,7 +1409,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
final RandomAccessInput addressesInput =
data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
final LongValues values = getNumericValues(entry);
@@ -1537,12 +1543,12 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
}
final RandomAccessInput slice = data.randomAccessSlice(entry.ordsOffset, entry.ordsLength);
- final LongValues ords = DirectReader.getInstance(slice, entry.bitsPerValue);
+ final LongValues ords = LegacyDirectReader.getInstance(slice, entry.bitsPerValue);
final RandomAccessInput addressesInput =
data.randomAccessSlice(entry.addressesOffset, entry.addressesLength);
final LongValues addresses =
- DirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
+ LegacyDirectMonotonicReader.getInstance(entry.addressesMeta, addressesInput);
if (entry.docsWithFieldOffset == -1) {
// dense
@@ -1722,7 +1728,7 @@ final class Lucene80DocValuesProducer extends DocValuesProducer {
values =
bitsPerValue == 0
? LongValues.ZEROES
- : DirectReader.getInstance(slice, bitsPerValue, offset);
+ : LegacyDirectReader.getInstance(slice, bitsPerValue, offset);
}
return mul * values.get(index & mask) + delta;
}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsProducer.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsProducer.java
index 42450bf8a15..cf4d8df66ee 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsProducer.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsProducer.java
@@ -22,6 +22,7 @@ import static org.apache.lucene.backward_codecs.lucene80.Lucene80NormsFormat.VER
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.NormsProducer;
import org.apache.lucene.index.CorruptIndexException;
@@ -60,7 +61,8 @@ final class Lucene80NormsProducer extends NormsProducer implements Cloneable {
int version = -1;
// read in the entries from the metadata file.
- try (ChecksumIndexInput in = state.directory.openChecksumInput(metaName, state.context)) {
+ try (ChecksumIndexInput in =
+ EndiannessReverserUtil.openChecksumInput(state.directory, metaName, state.context)) {
Throwable priorE = null;
try {
version =
@@ -81,7 +83,7 @@ final class Lucene80NormsProducer extends NormsProducer implements Cloneable {
String dataName =
IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, dataExtension);
- data = state.directory.openInput(dataName, state.context);
+ data = EndiannessReverserUtil.openInput(state.directory, dataName, state.context);
boolean success = false;
try {
final int version2 =
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/ForUtil.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/ForUtil.java
index 6350c914b46..25408e46ffe 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/ForUtil.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/ForUtil.java
@@ -306,7 +306,7 @@ final class ForUtil {
private static void decodeSlow(int bitsPerValue, DataInput in, long[] tmp, long[] longs)
throws IOException {
final int numLongs = bitsPerValue << 1;
- in.readLELongs(tmp, 0, numLongs);
+ in.readLongs(tmp, 0, numLongs);
final long mask = MASKS32[bitsPerValue];
int longsIdx = 0;
int shift = 32 - bitsPerValue;
@@ -621,7 +621,7 @@ final class ForUtil {
}
private static void decode1(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 2);
+ in.readLongs(tmp, 0, 2);
shiftLongs(tmp, 2, longs, 0, 7, MASK8_1);
shiftLongs(tmp, 2, longs, 2, 6, MASK8_1);
shiftLongs(tmp, 2, longs, 4, 5, MASK8_1);
@@ -633,7 +633,7 @@ final class ForUtil {
}
private static void decode2(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 4);
+ in.readLongs(tmp, 0, 4);
shiftLongs(tmp, 4, longs, 0, 6, MASK8_2);
shiftLongs(tmp, 4, longs, 4, 4, MASK8_2);
shiftLongs(tmp, 4, longs, 8, 2, MASK8_2);
@@ -641,7 +641,7 @@ final class ForUtil {
}
private static void decode3(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 6);
+ in.readLongs(tmp, 0, 6);
shiftLongs(tmp, 6, longs, 0, 5, MASK8_3);
shiftLongs(tmp, 6, longs, 6, 2, MASK8_3);
for (int iter = 0, tmpIdx = 0, longsIdx = 12; iter < 2; ++iter, tmpIdx += 3, longsIdx += 2) {
@@ -655,13 +655,13 @@ final class ForUtil {
}
private static void decode4(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 8);
+ in.readLongs(tmp, 0, 8);
shiftLongs(tmp, 8, longs, 0, 4, MASK8_4);
shiftLongs(tmp, 8, longs, 8, 0, MASK8_4);
}
private static void decode5(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 10);
+ in.readLongs(tmp, 0, 10);
shiftLongs(tmp, 10, longs, 0, 3, MASK8_5);
for (int iter = 0, tmpIdx = 0, longsIdx = 10; iter < 2; ++iter, tmpIdx += 5, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK8_3) << 2;
@@ -678,7 +678,7 @@ final class ForUtil {
}
private static void decode6(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 12);
+ in.readLongs(tmp, 0, 12);
shiftLongs(tmp, 12, longs, 0, 2, MASK8_6);
shiftLongs(tmp, 12, tmp, 0, 0, MASK8_2);
for (int iter = 0, tmpIdx = 0, longsIdx = 12; iter < 4; ++iter, tmpIdx += 3, longsIdx += 1) {
@@ -690,7 +690,7 @@ final class ForUtil {
}
private static void decode7(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 14);
+ in.readLongs(tmp, 0, 14);
shiftLongs(tmp, 14, longs, 0, 1, MASK8_7);
shiftLongs(tmp, 14, tmp, 0, 0, MASK8_1);
for (int iter = 0, tmpIdx = 0, longsIdx = 14; iter < 2; ++iter, tmpIdx += 7, longsIdx += 1) {
@@ -706,11 +706,11 @@ final class ForUtil {
}
private static void decode8(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(longs, 0, 16);
+ in.readLongs(longs, 0, 16);
}
private static void decode9(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 18);
+ in.readLongs(tmp, 0, 18);
shiftLongs(tmp, 18, longs, 0, 7, MASK16_9);
for (int iter = 0, tmpIdx = 0, longsIdx = 18; iter < 2; ++iter, tmpIdx += 9, longsIdx += 7) {
long l0 = (tmp[tmpIdx + 0] & MASK16_7) << 2;
@@ -739,7 +739,7 @@ final class ForUtil {
}
private static void decode10(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 20);
+ in.readLongs(tmp, 0, 20);
shiftLongs(tmp, 20, longs, 0, 6, MASK16_10);
for (int iter = 0, tmpIdx = 0, longsIdx = 20; iter < 4; ++iter, tmpIdx += 5, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK16_6) << 4;
@@ -756,7 +756,7 @@ final class ForUtil {
}
private static void decode11(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 22);
+ in.readLongs(tmp, 0, 22);
shiftLongs(tmp, 22, longs, 0, 5, MASK16_11);
for (int iter = 0, tmpIdx = 0, longsIdx = 22; iter < 2; ++iter, tmpIdx += 11, longsIdx += 5) {
long l0 = (tmp[tmpIdx + 0] & MASK16_5) << 6;
@@ -783,7 +783,7 @@ final class ForUtil {
}
private static void decode12(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 24);
+ in.readLongs(tmp, 0, 24);
shiftLongs(tmp, 24, longs, 0, 4, MASK16_12);
shiftLongs(tmp, 24, tmp, 0, 0, MASK16_4);
for (int iter = 0, tmpIdx = 0, longsIdx = 24; iter < 8; ++iter, tmpIdx += 3, longsIdx += 1) {
@@ -795,7 +795,7 @@ final class ForUtil {
}
private static void decode13(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 26);
+ in.readLongs(tmp, 0, 26);
shiftLongs(tmp, 26, longs, 0, 3, MASK16_13);
for (int iter = 0, tmpIdx = 0, longsIdx = 26; iter < 2; ++iter, tmpIdx += 13, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK16_3) << 10;
@@ -820,7 +820,7 @@ final class ForUtil {
}
private static void decode14(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 28);
+ in.readLongs(tmp, 0, 28);
shiftLongs(tmp, 28, longs, 0, 2, MASK16_14);
shiftLongs(tmp, 28, tmp, 0, 0, MASK16_2);
for (int iter = 0, tmpIdx = 0, longsIdx = 28; iter < 4; ++iter, tmpIdx += 7, longsIdx += 1) {
@@ -836,7 +836,7 @@ final class ForUtil {
}
private static void decode15(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 30);
+ in.readLongs(tmp, 0, 30);
shiftLongs(tmp, 30, longs, 0, 1, MASK16_15);
shiftLongs(tmp, 30, tmp, 0, 0, MASK16_1);
for (int iter = 0, tmpIdx = 0, longsIdx = 30; iter < 2; ++iter, tmpIdx += 15, longsIdx += 1) {
@@ -860,11 +860,11 @@ final class ForUtil {
}
private static void decode16(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(longs, 0, 32);
+ in.readLongs(longs, 0, 32);
}
private static void decode17(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 34);
+ in.readLongs(tmp, 0, 34);
shiftLongs(tmp, 34, longs, 0, 15, MASK32_17);
for (int iter = 0, tmpIdx = 0, longsIdx = 34; iter < 2; ++iter, tmpIdx += 17, longsIdx += 15) {
long l0 = (tmp[tmpIdx + 0] & MASK32_15) << 2;
@@ -917,7 +917,7 @@ final class ForUtil {
}
private static void decode18(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 36);
+ in.readLongs(tmp, 0, 36);
shiftLongs(tmp, 36, longs, 0, 14, MASK32_18);
for (int iter = 0, tmpIdx = 0, longsIdx = 36; iter < 4; ++iter, tmpIdx += 9, longsIdx += 7) {
long l0 = (tmp[tmpIdx + 0] & MASK32_14) << 4;
@@ -946,7 +946,7 @@ final class ForUtil {
}
private static void decode19(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 38);
+ in.readLongs(tmp, 0, 38);
shiftLongs(tmp, 38, longs, 0, 13, MASK32_19);
for (int iter = 0, tmpIdx = 0, longsIdx = 38; iter < 2; ++iter, tmpIdx += 19, longsIdx += 13) {
long l0 = (tmp[tmpIdx + 0] & MASK32_13) << 6;
@@ -997,7 +997,7 @@ final class ForUtil {
}
private static void decode20(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 40);
+ in.readLongs(tmp, 0, 40);
shiftLongs(tmp, 40, longs, 0, 12, MASK32_20);
for (int iter = 0, tmpIdx = 0, longsIdx = 40; iter < 8; ++iter, tmpIdx += 5, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK32_12) << 8;
@@ -1014,7 +1014,7 @@ final class ForUtil {
}
private static void decode21(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 42);
+ in.readLongs(tmp, 0, 42);
shiftLongs(tmp, 42, longs, 0, 11, MASK32_21);
for (int iter = 0, tmpIdx = 0, longsIdx = 42; iter < 2; ++iter, tmpIdx += 21, longsIdx += 11) {
long l0 = (tmp[tmpIdx + 0] & MASK32_11) << 10;
@@ -1063,7 +1063,7 @@ final class ForUtil {
}
private static void decode22(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 44);
+ in.readLongs(tmp, 0, 44);
shiftLongs(tmp, 44, longs, 0, 10, MASK32_22);
for (int iter = 0, tmpIdx = 0, longsIdx = 44; iter < 4; ++iter, tmpIdx += 11, longsIdx += 5) {
long l0 = (tmp[tmpIdx + 0] & MASK32_10) << 12;
@@ -1090,7 +1090,7 @@ final class ForUtil {
}
private static void decode23(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 46);
+ in.readLongs(tmp, 0, 46);
shiftLongs(tmp, 46, longs, 0, 9, MASK32_23);
for (int iter = 0, tmpIdx = 0, longsIdx = 46; iter < 2; ++iter, tmpIdx += 23, longsIdx += 9) {
long l0 = (tmp[tmpIdx + 0] & MASK32_9) << 14;
@@ -1137,7 +1137,7 @@ final class ForUtil {
}
private static void decode24(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 48);
+ in.readLongs(tmp, 0, 48);
shiftLongs(tmp, 48, longs, 0, 8, MASK32_24);
shiftLongs(tmp, 48, tmp, 0, 0, MASK32_8);
for (int iter = 0, tmpIdx = 0, longsIdx = 48; iter < 16; ++iter, tmpIdx += 3, longsIdx += 1) {
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsReader.java
index ee51a04ca1f..9709c7aa9d7 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsReader.java
@@ -29,6 +29,7 @@ import static org.apache.lucene.backward_codecs.lucene84.Lucene84PostingsFormat.
import java.io.IOException;
import java.util.Arrays;
import org.apache.lucene.backward_codecs.lucene84.Lucene84PostingsFormat.IntBlockTermState;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.BlockTermState;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.PostingsReaderBase;
@@ -76,7 +77,7 @@ public final class Lucene84PostingsReader extends PostingsReaderBase {
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene84PostingsFormat.DOC_EXTENSION);
try {
- docIn = state.directory.openInput(docName, state.context);
+ docIn = EndiannessReverserUtil.openInput(state.directory, docName, state.context);
version =
CodecUtil.checkIndexHeader(
docIn,
@@ -91,7 +92,7 @@ public final class Lucene84PostingsReader extends PostingsReaderBase {
String proxName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene84PostingsFormat.POS_EXTENSION);
- posIn = state.directory.openInput(proxName, state.context);
+ posIn = EndiannessReverserUtil.openInput(state.directory, proxName, state.context);
CodecUtil.checkIndexHeader(
posIn, POS_CODEC, version, version, state.segmentInfo.getId(), state.segmentSuffix);
CodecUtil.retrieveChecksum(posIn);
@@ -102,7 +103,7 @@ public final class Lucene84PostingsReader extends PostingsReaderBase {
state.segmentInfo.name,
state.segmentSuffix,
Lucene84PostingsFormat.PAY_EXTENSION);
- payIn = state.directory.openInput(payName, state.context);
+ payIn = EndiannessReverserUtil.openInput(state.directory, payName, state.context);
CodecUtil.checkIndexHeader(
payIn, PAY_CODEC, version, version, state.segmentInfo.getId(), state.segmentSuffix);
CodecUtil.retrieveChecksum(payIn);
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsReader.java
index ee1ca3c5898..e49562a8247 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsReader.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsReader.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene86;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.PointsReader;
import org.apache.lucene.index.CorruptIndexException;
@@ -59,7 +60,8 @@ public class Lucene86PointsReader extends PointsReader {
boolean success = false;
try {
- indexIn = readState.directory.openInput(indexFileName, readState.context);
+ indexIn =
+ EndiannessReverserUtil.openInput(readState.directory, indexFileName, readState.context);
CodecUtil.checkIndexHeader(
indexIn,
Lucene86PointsFormat.INDEX_CODEC_NAME,
@@ -68,7 +70,8 @@ public class Lucene86PointsReader extends PointsReader {
readState.segmentInfo.getId(),
readState.segmentSuffix);
- dataIn = readState.directory.openInput(dataFileName, readState.context);
+ dataIn =
+ EndiannessReverserUtil.openInput(readState.directory, dataFileName, readState.context);
CodecUtil.checkIndexHeader(
dataIn,
Lucene86PointsFormat.DATA_CODEC_NAME,
@@ -79,7 +82,8 @@ public class Lucene86PointsReader extends PointsReader {
long indexLength = -1, dataLength = -1;
try (ChecksumIndexInput metaIn =
- readState.directory.openChecksumInput(metaFileName, readState.context)) {
+ EndiannessReverserUtil.openChecksumInput(
+ readState.directory, metaFileName, readState.context)) {
Throwable priorE = null;
try {
CodecUtil.checkIndexHeader(
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86SegmentInfoFormat.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86SegmentInfoFormat.java
index 528010ed88c..35879f62dc4 100644
--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86SegmentInfoFormat.java
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene86/Lucene86SegmentInfoFormat.java
@@ -20,6 +20,7 @@ package org.apache.lucene.backward_codecs.lucene86;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.SegmentInfoFormat;
import org.apache.lucene.index.CorruptIndexException;
@@ -97,7 +98,8 @@ public class Lucene86SegmentInfoFormat extends SegmentInfoFormat {
public SegmentInfo read(Directory dir, String segment, byte[] segmentID, IOContext context)
throws IOException {
final String fileName = IndexFileNames.segmentFileName(segment, "", SI_EXTENSION);
- try (ChecksumIndexInput input = dir.openChecksumInput(fileName, context)) {
+ try (ChecksumIndexInput input =
+ EndiannessReverserUtil.openChecksumInput(dir, fileName, context)) {
Throwable priorE = null;
SegmentInfo si = null;
try {
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectMonotonicReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectMonotonicReader.java
new file mode 100644
index 00000000000..4b942a4f3d3
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectMonotonicReader.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.packed;
+
+import java.io.IOException;
+import java.util.Arrays;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.RandomAccessInput;
+import org.apache.lucene.util.Accountable;
+import org.apache.lucene.util.LongValues;
+import org.apache.lucene.util.RamUsageEstimator;
+
+/**
+ * Retrieves an instance previously written by {@link LegacyDirectMonotonicWriter}.
+ *
+ * @see LegacyDirectMonotonicWriter
+ */
+public final class LegacyDirectMonotonicReader extends LongValues implements Accountable {
+
+ private static final long BASE_RAM_BYTES_USED =
+ RamUsageEstimator.shallowSizeOfInstance(LegacyDirectMonotonicReader.class);
+
+ /** An instance that always returns {@code 0}. */
+ private static final LongValues EMPTY =
+ new LongValues() {
+
+ @Override
+ public long get(long index) {
+ return 0;
+ }
+ };
+
+ /**
+ * In-memory metadata that needs to be kept around for {@link LegacyDirectMonotonicReader} to read
+ * data from disk.
+ */
+ public static class Meta implements Accountable {
+ private static final long BASE_RAM_BYTES_USED =
+ RamUsageEstimator.shallowSizeOfInstance(Meta.class);
+
+ final int blockShift;
+ final int numBlocks;
+ final long[] mins;
+ final float[] avgs;
+ final byte[] bpvs;
+ final long[] offsets;
+
+ Meta(long numValues, int blockShift) {
+ this.blockShift = blockShift;
+ long numBlocks = numValues >>> blockShift;
+ if ((numBlocks << blockShift) < numValues) {
+ numBlocks += 1;
+ }
+ this.numBlocks = (int) numBlocks;
+ this.mins = new long[this.numBlocks];
+ this.avgs = new float[this.numBlocks];
+ this.bpvs = new byte[this.numBlocks];
+ this.offsets = new long[this.numBlocks];
+ }
+
+ @Override
+ public long ramBytesUsed() {
+ return BASE_RAM_BYTES_USED
+ + RamUsageEstimator.sizeOf(mins)
+ + RamUsageEstimator.sizeOf(avgs)
+ + RamUsageEstimator.sizeOf(bpvs)
+ + RamUsageEstimator.sizeOf(offsets);
+ }
+ }
+
+ /**
+ * Load metadata from the given {@link IndexInput}.
+ *
+ * @see LegacyDirectMonotonicReader#getInstance(Meta, RandomAccessInput)
+ */
+ public static Meta loadMeta(IndexInput metaIn, long numValues, int blockShift)
+ throws IOException {
+ Meta meta = new Meta(numValues, blockShift);
+ for (int i = 0; i < meta.numBlocks; ++i) {
+ meta.mins[i] = metaIn.readLong();
+ meta.avgs[i] = Float.intBitsToFloat(metaIn.readInt());
+ meta.offsets[i] = metaIn.readLong();
+ meta.bpvs[i] = metaIn.readByte();
+ }
+ return meta;
+ }
+
+ /** Retrieves an instance from the specified slice. */
+ public static LegacyDirectMonotonicReader getInstance(Meta meta, RandomAccessInput data)
+ throws IOException {
+ final LongValues[] readers = new LongValues[meta.numBlocks];
+ for (int i = 0; i < meta.mins.length; ++i) {
+ if (meta.bpvs[i] == 0) {
+ readers[i] = EMPTY;
+ } else {
+ readers[i] = LegacyDirectReader.getInstance(data, meta.bpvs[i], meta.offsets[i]);
+ }
+ }
+
+ return new LegacyDirectMonotonicReader(
+ meta.blockShift, readers, meta.mins, meta.avgs, meta.bpvs);
+ }
+
+ private final int blockShift;
+ private final LongValues[] readers;
+ private final long[] mins;
+ private final float[] avgs;
+ private final byte[] bpvs;
+ private final int nonZeroBpvs;
+
+ private LegacyDirectMonotonicReader(
+ int blockShift, LongValues[] readers, long[] mins, float[] avgs, byte[] bpvs) {
+ this.blockShift = blockShift;
+ this.readers = readers;
+ this.mins = mins;
+ this.avgs = avgs;
+ this.bpvs = bpvs;
+ if (readers.length != mins.length
+ || readers.length != avgs.length
+ || readers.length != bpvs.length) {
+ throw new IllegalArgumentException();
+ }
+ int nonZeroBpvs = 0;
+ for (byte b : bpvs) {
+ if (b != 0) {
+ nonZeroBpvs++;
+ }
+ }
+ this.nonZeroBpvs = nonZeroBpvs;
+ }
+
+ @Override
+ public long get(long index) {
+ final int block = (int) (index >>> blockShift);
+ final long blockIndex = index & ((1 << blockShift) - 1);
+ final long delta = readers[block].get(blockIndex);
+ return mins[block] + (long) (avgs[block] * blockIndex) + delta;
+ }
+
+ /** Get lower/upper bounds for the value at a given index without hitting the direct reader. */
+ private long[] getBounds(long index) {
+ final int block = Math.toIntExact(index >>> blockShift);
+ final long blockIndex = index & ((1 << blockShift) - 1);
+ final long lowerBound = mins[block] + (long) (avgs[block] * blockIndex);
+ final long upperBound = lowerBound + (1L << bpvs[block]) - 1;
+ if (bpvs[block] == 64 || upperBound < lowerBound) { // overflow
+ return new long[] {Long.MIN_VALUE, Long.MAX_VALUE};
+ } else {
+ return new long[] {lowerBound, upperBound};
+ }
+ }
+
+ /**
+ * Return the index of a key if it exists, or its insertion point otherwise like {@link
+ * Arrays#binarySearch(long[], int, int, long)}.
+ *
+ * @see Arrays#binarySearch(long[], int, int, long)
+ */
+ public long binarySearch(long fromIndex, long toIndex, long key) {
+ if (fromIndex < 0 || fromIndex > toIndex) {
+ throw new IllegalArgumentException("fromIndex=" + fromIndex + ",toIndex=" + toIndex);
+ }
+ long lo = fromIndex;
+ long hi = toIndex - 1;
+
+ while (lo <= hi) {
+ final long mid = (lo + hi) >>> 1;
+ // Try to run as many iterations of the binary search as possible without
+ // hitting the direct readers, since they might hit a page fault.
+ final long[] bounds = getBounds(mid);
+ if (bounds[1] < key) {
+ lo = mid + 1;
+ } else if (bounds[0] > key) {
+ hi = mid - 1;
+ } else {
+ final long midVal = get(mid);
+ if (midVal < key) {
+ lo = mid + 1;
+ } else if (midVal > key) {
+ hi = mid - 1;
+ } else {
+ return mid;
+ }
+ }
+ }
+
+ return -1 - lo;
+ }
+
+ @Override
+ public long ramBytesUsed() {
+ // Don't include meta, which should be accounted separately
+ return BASE_RAM_BYTES_USED
+ + RamUsageEstimator.shallowSizeOf(readers)
+ +
+ // Assume empty objects for the readers
+ nonZeroBpvs * RamUsageEstimator.alignObjectSize(RamUsageEstimator.NUM_BYTES_ARRAY_HEADER);
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectMonotonicWriter.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectMonotonicWriter.java
new file mode 100644
index 00000000000..b630644fe7e
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectMonotonicWriter.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.packed;
+
+import java.io.IOException;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.ArrayUtil;
+
+/**
+ * Write monotonically-increasing sequences of integers. This writer splits data into blocks and
+ * then for each block, computes the average slope, the minimum value and only encode the delta from
+ * the expected value using a {@link LegacyDirectWriter}.
+ *
+ * @see LegacyDirectMonotonicReader
+ * @lucene.internal
+ */
+public final class LegacyDirectMonotonicWriter {
+
+ /** min block shift */
+ public static final int MIN_BLOCK_SHIFT = 2;
+ /** max block shift */
+ public static final int MAX_BLOCK_SHIFT = 22;
+
+ final IndexOutput meta;
+ final IndexOutput data;
+ final long numValues;
+ final long baseDataPointer;
+ final long[] buffer;
+ int bufferSize;
+ long count;
+ boolean finished;
+
+ LegacyDirectMonotonicWriter(
+ IndexOutput metaOut, IndexOutput dataOut, long numValues, int blockShift) {
+ if (blockShift < MIN_BLOCK_SHIFT || blockShift > MAX_BLOCK_SHIFT) {
+ throw new IllegalArgumentException(
+ "blockShift must be in ["
+ + MIN_BLOCK_SHIFT
+ + "-"
+ + MAX_BLOCK_SHIFT
+ + "], got "
+ + blockShift);
+ }
+ if (numValues < 0) {
+ throw new IllegalArgumentException("numValues can't be negative, got " + numValues);
+ }
+ final long numBlocks = numValues == 0 ? 0 : ((numValues - 1) >>> blockShift) + 1;
+ if (numBlocks > ArrayUtil.MAX_ARRAY_LENGTH) {
+ throw new IllegalArgumentException(
+ "blockShift is too low for the provided number of values: blockShift="
+ + blockShift
+ + ", numValues="
+ + numValues
+ + ", MAX_ARRAY_LENGTH="
+ + ArrayUtil.MAX_ARRAY_LENGTH);
+ }
+ this.meta = metaOut;
+ this.data = dataOut;
+ this.numValues = numValues;
+ final int blockSize = 1 << blockShift;
+ this.buffer = new long[(int) Math.min(numValues, blockSize)];
+ this.bufferSize = 0;
+ this.baseDataPointer = dataOut.getFilePointer();
+ }
+
+ private void flush() throws IOException {
+ assert bufferSize != 0;
+
+ final float avgInc =
+ (float) ((double) (buffer[bufferSize - 1] - buffer[0]) / Math.max(1, bufferSize - 1));
+ for (int i = 0; i < bufferSize; ++i) {
+ final long expected = (long) (avgInc * (long) i);
+ buffer[i] -= expected;
+ }
+
+ long min = buffer[0];
+ for (int i = 1; i < bufferSize; ++i) {
+ min = Math.min(buffer[i], min);
+ }
+
+ long maxDelta = 0;
+ for (int i = 0; i < bufferSize; ++i) {
+ buffer[i] -= min;
+ // use | will change nothing when it comes to computing required bits
+ // but has the benefit of working fine with negative values too
+ // (in case of overflow)
+ maxDelta |= buffer[i];
+ }
+
+ meta.writeLong(min);
+ meta.writeInt(Float.floatToIntBits(avgInc));
+ meta.writeLong(data.getFilePointer() - baseDataPointer);
+ if (maxDelta == 0) {
+ meta.writeByte((byte) 0);
+ } else {
+ final int bitsRequired = LegacyDirectWriter.unsignedBitsRequired(maxDelta);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(data, bufferSize, bitsRequired);
+ for (int i = 0; i < bufferSize; ++i) {
+ writer.add(buffer[i]);
+ }
+ writer.finish();
+ meta.writeByte((byte) bitsRequired);
+ }
+ bufferSize = 0;
+ }
+
+ long previous = Long.MIN_VALUE;
+
+ /**
+ * Write a new value. Note that data might not make it to storage until {@link #finish()} is
+ * called.
+ *
+ * @throws IllegalArgumentException if values don't come in order
+ */
+ public void add(long v) throws IOException {
+ if (v < previous) {
+ throw new IllegalArgumentException("Values do not come in order: " + previous + ", " + v);
+ }
+ if (bufferSize == buffer.length) {
+ flush();
+ }
+ buffer[bufferSize++] = v;
+ previous = v;
+ count++;
+ }
+
+ /** This must be called exactly once after all values have been {@link #add(long) added}. */
+ public void finish() throws IOException {
+ if (count != numValues) {
+ throw new IllegalStateException(
+ "Wrong number of values added, expected: " + numValues + ", got: " + count);
+ }
+ if (finished) {
+ throw new IllegalStateException("#finish has been called already");
+ }
+ if (bufferSize > 0) {
+ flush();
+ }
+ finished = true;
+ }
+
+ /**
+ * Returns an instance suitable for encoding {@code numValues} into monotonic blocks of
+ * 2<sup>{@code blockShift}</sup> values. Metadata will be written to {@code metaOut} and actual
+ * data to {@code dataOut}.
+ */
+ public static LegacyDirectMonotonicWriter getInstance(
+ IndexOutput metaOut, IndexOutput dataOut, long numValues, int blockShift) {
+ return new LegacyDirectMonotonicWriter(metaOut, dataOut, numValues, blockShift);
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectReader.java
new file mode 100644
index 00000000000..d738e74953e
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectReader.java
@@ -0,0 +1,368 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.packed;
+
+import java.io.IOException;
+import org.apache.lucene.store.RandomAccessInput;
+import org.apache.lucene.util.LongValues;
+
+/**
+ * Retrieves an instance previously written by {@link LegacyDirectWriter}
+ *
+ * <p>Example usage:
+ *
+ * <pre class="prettyprint">
+ * int bitsPerValue = 100;
+ * IndexInput in = dir.openInput("packed", IOContext.DEFAULT);
+ * LongValues values = LegacyDirectReader.getInstance(in.randomAccessSlice(start, end), bitsPerValue);
+ * for (int i = 0; i &lt; numValues; i++) {
+ * long value = values.get(i);
+ * }
+ * </pre>
+ *
+ * @see LegacyDirectWriter
+ */
+public class LegacyDirectReader {
+
+ private LegacyDirectReader() {
+ // no instances
+ }
+
+ /**
+ * Retrieves an instance from the specified slice written decoding {@code bitsPerValue} for each
+ * value
+ */
+ public static LongValues getInstance(RandomAccessInput slice, int bitsPerValue) {
+ return getInstance(slice, bitsPerValue, 0);
+ }
+
+ /**
+ * Retrieves an instance from the specified {@code offset} of the given slice decoding {@code
+ * bitsPerValue} for each value
+ */
+ public static LongValues getInstance(RandomAccessInput slice, int bitsPerValue, long offset) {
+ switch (bitsPerValue) {
+ case 1:
+ return new DirectPackedReader1(slice, offset);
+ case 2:
+ return new DirectPackedReader2(slice, offset);
+ case 4:
+ return new DirectPackedReader4(slice, offset);
+ case 8:
+ return new DirectPackedReader8(slice, offset);
+ case 12:
+ return new DirectPackedReader12(slice, offset);
+ case 16:
+ return new DirectPackedReader16(slice, offset);
+ case 20:
+ return new DirectPackedReader20(slice, offset);
+ case 24:
+ return new DirectPackedReader24(slice, offset);
+ case 28:
+ return new DirectPackedReader28(slice, offset);
+ case 32:
+ return new DirectPackedReader32(slice, offset);
+ case 40:
+ return new DirectPackedReader40(slice, offset);
+ case 48:
+ return new DirectPackedReader48(slice, offset);
+ case 56:
+ return new DirectPackedReader56(slice, offset);
+ case 64:
+ return new DirectPackedReader64(slice, offset);
+ default:
+ throw new IllegalArgumentException("unsupported bitsPerValue: " + bitsPerValue);
+ }
+ }
+
+ static final class DirectPackedReader1 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader1(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ int shift = 7 - (int) (index & 7);
+ return (in.readByte(offset + (index >>> 3)) >>> shift) & 0x1;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader2 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader2(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ int shift = (3 - (int) (index & 3)) << 1;
+ return (in.readByte(offset + (index >>> 2)) >>> shift) & 0x3;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader4 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader4(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ int shift = (int) ((index + 1) & 1) << 2;
+ return (in.readByte(offset + (index >>> 1)) >>> shift) & 0xF;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader8 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader8(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readByte(offset + index) & 0xFF;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader12 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader12(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ long offset = (index * 12) >>> 3;
+ int shift = (int) ((index + 1) & 1) << 2;
+ return (in.readShort(this.offset + offset) >>> shift) & 0xFFF;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader16 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader16(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readShort(offset + (index << 1)) & 0xFFFF;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader20 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader20(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ long offset = (index * 20) >>> 3;
+ // TODO: clean this up...
+ int v = in.readInt(this.offset + offset) >>> 8;
+ int shift = (int) ((index + 1) & 1) << 2;
+ return (v >>> shift) & 0xFFFFF;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader24 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader24(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readInt(offset + index * 3) >>> 8;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader28 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader28(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ long offset = (index * 28) >>> 3;
+ int shift = (int) ((index + 1) & 1) << 2;
+ return (in.readInt(this.offset + offset) >>> shift) & 0xFFFFFFFL;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader32 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader32(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readInt(this.offset + (index << 2)) & 0xFFFFFFFFL;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader40 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader40(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readLong(this.offset + index * 5) >>> 24;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader48 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader48(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readLong(this.offset + index * 6) >>> 16;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader56 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader56(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readLong(this.offset + index * 7) >>> 8;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ static final class DirectPackedReader64 extends LongValues {
+ final RandomAccessInput in;
+ final long offset;
+
+ DirectPackedReader64(RandomAccessInput in, long offset) {
+ this.in = in;
+ this.offset = offset;
+ }
+
+ @Override
+ public long get(long index) {
+ try {
+ return in.readLong(offset + (index << 3));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectWriter.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectWriter.java
new file mode 100644
index 00000000000..320fc2b1c1e
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/packed/LegacyDirectWriter.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.packed;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.util.Arrays;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.util.packed.PackedInts;
+
+/**
+ * Class for writing packed integers to be directly read from Directory. Integers can be read
+ * on-the-fly via {@link LegacyDirectReader}.
+ *
+ * <p>Unlike PackedInts, it optimizes for read i/o operations and supports &gt; 2B values. Example
+ * usage:
+ *
+ * <pre class="prettyprint">
+ * int bitsPerValue = LegacyDirectWriter.bitsRequired(100); // values up to and including 100
+ * IndexOutput output = dir.createOutput("packed", IOContext.DEFAULT);
+ * DirectWriter writer = LegacyDirectWriter.getInstance(output, numberOfValues, bitsPerValue);
+ * for (int i = 0; i &lt; numberOfValues; i++) {
+ * writer.add(value);
+ * }
+ * writer.finish();
+ * output.close();
+ * </pre>
+ *
+ * @see LegacyDirectReader
+ */
+public final class LegacyDirectWriter {
+ final int bitsPerValue;
+ final long numValues;
+ final DataOutput output;
+
+ long count;
+ boolean finished;
+
+ // for now, just use the existing writer under the hood
+ int off;
+ final byte[] nextBlocks;
+ final long[] nextValues;
+ final PackedInts.Encoder encoder;
+ final int iterations;
+
+ LegacyDirectWriter(DataOutput output, long numValues, int bitsPerValue) {
+ this.output = output;
+ this.numValues = numValues;
+ this.bitsPerValue = bitsPerValue;
+ encoder =
+ PackedInts.getEncoder(PackedInts.Format.PACKED, PackedInts.VERSION_CURRENT, bitsPerValue);
+ iterations =
+ computeIterations(
+ encoder, (int) Math.min(numValues, Integer.MAX_VALUE), PackedInts.DEFAULT_BUFFER_SIZE);
+ nextBlocks = new byte[iterations * encoder.byteBlockCount()];
+ nextValues = new long[iterations * encoder.byteValueCount()];
+ }
+
+ // copied from bulk operation
+ private static int computeIterations(PackedInts.Encoder encoder, int valueCount, int ramBudget) {
+ final int iterations = ramBudget / (encoder.byteBlockCount() + 8 * encoder.byteValueCount());
+ if (iterations == 0) {
+ // at least 1
+ return 1;
+ } else if ((iterations - 1) * encoder.byteValueCount() >= valueCount) {
+ // don't allocate for more than the size of the reader
+ return (int) Math.ceil((double) valueCount / encoder.byteValueCount());
+ } else {
+ return iterations;
+ }
+ }
+
+ /** Adds a value to this writer */
+ public void add(long l) throws IOException {
+ assert bitsPerValue == 64 || (l >= 0 && l <= PackedInts.maxValue(bitsPerValue)) : bitsPerValue;
+ assert !finished;
+ if (count >= numValues) {
+ throw new EOFException("Writing past end of stream");
+ }
+ nextValues[off++] = l;
+ if (off == nextValues.length) {
+ flush();
+ }
+ count++;
+ }
+
+ private void flush() throws IOException {
+ encoder.encode(nextValues, 0, nextBlocks, 0, iterations);
+ final int blockCount =
+ (int) PackedInts.Format.PACKED.byteCount(PackedInts.VERSION_CURRENT, off, bitsPerValue);
+ output.writeBytes(nextBlocks, blockCount);
+ Arrays.fill(nextValues, 0L);
+ off = 0;
+ }
+
+ /** finishes writing */
+ public void finish() throws IOException {
+ if (count != numValues) {
+ throw new IllegalStateException(
+ "Wrong number of values added, expected: " + numValues + ", got: " + count);
+ }
+ assert !finished;
+ flush();
+ // pad for fast io: we actually only need this for certain BPV, but its just 3 bytes...
+ for (int i = 0; i < 3; i++) {
+ output.writeByte((byte) 0);
+ }
+ finished = true;
+ }
+
+ /** Returns an instance suitable for encoding {@code numValues} using {@code bitsPerValue} */
+ public static LegacyDirectWriter getInstance(
+ DataOutput output, long numValues, int bitsPerValue) {
+ if (Arrays.binarySearch(SUPPORTED_BITS_PER_VALUE, bitsPerValue) < 0) {
+ throw new IllegalArgumentException(
+ "Unsupported bitsPerValue " + bitsPerValue + ". Did you use bitsRequired?");
+ }
+ return new LegacyDirectWriter(output, numValues, bitsPerValue);
+ }
+
+ /**
+ * Round a number of bits per value to the next amount of bits per value that is supported by this
+ * writer.
+ *
+ * @param bitsRequired the amount of bits required
+ * @return the next number of bits per value that is gte the provided value and supported by this
+ * writer
+ */
+ private static int roundBits(int bitsRequired) {
+ int index = Arrays.binarySearch(SUPPORTED_BITS_PER_VALUE, bitsRequired);
+ if (index < 0) {
+ return SUPPORTED_BITS_PER_VALUE[-index - 1];
+ } else {
+ return bitsRequired;
+ }
+ }
+
+ /**
+ * Returns how many bits are required to hold values up to and including maxValue
+ *
+ * @param maxValue the maximum value that should be representable.
+ * @return the amount of bits needed to represent values from 0 to maxValue.
+ * @see PackedInts#bitsRequired(long)
+ */
+ public static int bitsRequired(long maxValue) {
+ return roundBits(PackedInts.bitsRequired(maxValue));
+ }
+
+ /**
+ * Returns how many bits are required to hold values up to and including maxValue, interpreted as
+ * an unsigned value.
+ *
+ * @param maxValue the maximum value that should be representable.
+ * @return the amount of bits needed to represent values from 0 to maxValue.
+ * @see PackedInts#unsignedBitsRequired(long)
+ */
+ public static int unsignedBitsRequired(long maxValue) {
+ return roundBits(PackedInts.unsignedBitsRequired(maxValue));
+ }
+
+ static final int SUPPORTED_BITS_PER_VALUE[] =
+ new int[] {1, 2, 4, 8, 12, 16, 20, 24, 28, 32, 40, 48, 56, 64};
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserChecksumIndexInput.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserChecksumIndexInput.java
new file mode 100644
index 00000000000..b4107b4004d
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserChecksumIndexInput.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import org.apache.lucene.store.BufferedChecksumIndexInput;
+import org.apache.lucene.store.ChecksumIndexInput;
+import org.apache.lucene.store.IndexInput;
+
+/**
+ * A {@link ChecksumIndexInput} wrapper that changes the endianness of the provided index output.
+ */
+final class EndiannessReverserChecksumIndexInput extends ChecksumIndexInput {
+
+ private final ChecksumIndexInput in;
+
+ EndiannessReverserChecksumIndexInput(IndexInput in) {
+ super("Endianness reverser Checksum Index Input wrapper");
+ this.in = new BufferedChecksumIndexInput(in);
+ }
+
+ @Override
+ public long getChecksum() throws IOException {
+ return in.getChecksum();
+ }
+
+ @Override
+ public byte readByte() throws IOException {
+ return in.readByte();
+ }
+
+ @Override
+ public void readBytes(byte[] b, int offset, int len) throws IOException {
+ in.readBytes(b, offset, len);
+ }
+
+ @Override
+ public short readShort() throws IOException {
+ return Short.reverseBytes(in.readShort());
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ return Integer.reverseBytes(in.readInt());
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ return Long.reverseBytes(in.readLong());
+ }
+
+ @Override
+ public void close() throws IOException {
+ in.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return in.getFilePointer();
+ }
+
+ @Override
+ public long length() {
+ return in.length();
+ }
+
+ @Override
+ public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
+ return new EndiannessReverserIndexInput(in.slice(sliceDescription, offset, length));
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserDataInput.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserDataInput.java
new file mode 100644
index 00000000000..0d9ccd345fc
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserDataInput.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import org.apache.lucene.store.DataInput;
+
+class EndiannessReverserDataInput extends DataInput {
+
+ private final DataInput in;
+
+ EndiannessReverserDataInput(DataInput in) {
+ this.in = in;
+ }
+
+ @Override
+ public byte readByte() throws IOException {
+ return in.readByte();
+ }
+
+ @Override
+ public void readBytes(byte[] b, int offset, int len) throws IOException {
+ in.readBytes(b, offset, len);
+ }
+
+ @Override
+ public short readShort() throws IOException {
+ return Short.reverseBytes(in.readShort());
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ return Integer.reverseBytes(in.readInt());
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ return Long.reverseBytes(in.readLong());
+ }
+
+ @Override
+ public void skipBytes(long numBytes) throws IOException {
+ in.skipBytes(numBytes);
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserDataOutput.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserDataOutput.java
new file mode 100644
index 00000000000..c042ed7a8ad
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserDataOutput.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
+
+class EndiannessReverserDataOutput extends DataOutput {
+
+ private final DataOutput out;
+
+ EndiannessReverserDataOutput(DataOutput out) {
+ this.out = out;
+ }
+
+ @Override
+ public void writeByte(byte b) throws IOException {
+ out.writeByte(b);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int length) throws IOException {
+ out.writeBytes(b, length);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int offset, int length) throws IOException {
+ out.writeBytes(b, offset, length);
+ }
+
+ @Override
+ public void writeInt(int i) throws IOException {
+ out.writeInt(Integer.reverseBytes(i));
+ }
+
+ @Override
+ public void writeShort(short i) throws IOException {
+ out.writeShort(Short.reverseBytes(i));
+ }
+
+ @Override
+ public void writeLong(long i) throws IOException {
+ out.writeLong(Long.reverseBytes(i));
+ }
+
+ @Override
+ public void writeString(String s) throws IOException {
+ out.writeString(s);
+ }
+
+ @Override
+ public void copyBytes(DataInput input, long numBytes) throws IOException {
+ out.copyBytes(input, numBytes);
+ }
+
+ @Override
+ public void writeMapOfStrings(Map<String, String> map) throws IOException {
+ out.writeMapOfStrings(map);
+ }
+
+ @Override
+ public void writeSetOfStrings(Set<String> set) throws IOException {
+ out.writeSetOfStrings(set);
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserIndexInput.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserIndexInput.java
new file mode 100644
index 00000000000..1bfc3c08a9b
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserIndexInput.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.RandomAccessInput;
+
+/** A {@link IndexInput} wrapper that changes the endianness of the provided index input. */
+final class EndiannessReverserIndexInput extends IndexInput {
+
+ private final IndexInput in;
+
+ EndiannessReverserIndexInput(IndexInput in) {
+ super("Endianness reverser Index Input wrapper");
+ this.in = in;
+ }
+
+ @Override
+ public byte readByte() throws IOException {
+ return in.readByte();
+ }
+
+ @Override
+ public void readBytes(byte[] b, int offset, int len) throws IOException {
+ in.readBytes(b, offset, len);
+ }
+
+ @Override
+ public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOException {
+ in.readBytes(b, offset, len, useBuffer);
+ }
+
+ @Override
+ public short readShort() throws IOException {
+ return Short.reverseBytes(in.readShort());
+ }
+
+ @Override
+ public int readInt() throws IOException {
+ return Integer.reverseBytes(in.readInt());
+ }
+
+ @Override
+ public int readVInt() throws IOException {
+ return in.readVInt();
+ }
+
+ @Override
+ public int readZInt() throws IOException {
+ return in.readZInt();
+ }
+
+ @Override
+ public long readLong() throws IOException {
+ return Long.reverseBytes(in.readLong());
+ }
+
+ @Override
+ public void readLongs(long[] dst, int offset, int length) throws IOException {
+ // used to be called readLELongs
+ in.readLongs(dst, offset, length);
+ }
+
+ @Override
+ public void readFloats(float[] dst, int offset, int length) throws IOException {
+ // used to be called readLEFloats
+ in.readFloats(dst, offset, length);
+ }
+
+ @Override
+ public long readVLong() throws IOException {
+ return in.readVLong();
+ }
+
+ @Override
+ public long readZLong() throws IOException {
+ return in.readZLong();
+ }
+
+ @Override
+ public String readString() throws IOException {
+ return in.readString();
+ }
+
+ @Override
+ public IndexInput clone() {
+ return new EndiannessReverserIndexInput(in.clone());
+ }
+
+ @Override
+ public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
+ return new EndiannessReverserIndexInput(in.slice(sliceDescription, offset, length));
+ }
+
+ @Override
+ public Map<String, String> readMapOfStrings() throws IOException {
+ return in.readMapOfStrings();
+ }
+
+ @Override
+ public Set<String> readSetOfStrings() throws IOException {
+ return in.readSetOfStrings();
+ }
+
+ @Override
+ public void skipBytes(final long numBytes) throws IOException {
+ in.skipBytes(numBytes);
+ }
+
+ @Override
+ public void close() throws IOException {
+ in.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return in.getFilePointer();
+ }
+
+ @Override
+ public void seek(long pos) throws IOException {
+ in.seek(pos);
+ }
+
+ @Override
+ public long length() {
+ return in.length();
+ }
+
+ @Override
+ public String toString() {
+ return in.toString();
+ }
+
+ @Override
+ public RandomAccessInput randomAccessSlice(long offset, long length) throws IOException {
+ return new EndiannessReverserRandomAccessInput(in.randomAccessSlice(offset, length));
+ }
+
+ /**
+ * A {@link RandomAccessInput} wrapper that changes the endianness of the provided index input.
+ *
+ * @lucene.internal
+ */
+ public static class EndiannessReverserRandomAccessInput implements RandomAccessInput {
+
+ private final RandomAccessInput in;
+
+ public EndiannessReverserRandomAccessInput(RandomAccessInput in) {
+ this.in = in;
+ }
+
+ @Override
+ public byte readByte(long pos) throws IOException {
+ return in.readByte(pos);
+ }
+
+ @Override
+ public short readShort(long pos) throws IOException {
+ return Short.reverseBytes(in.readShort(pos));
+ }
+
+ @Override
+ public int readInt(long pos) throws IOException {
+ return Integer.reverseBytes(in.readInt(pos));
+ }
+
+ @Override
+ public long readLong(long pos) throws IOException {
+ return Long.reverseBytes(in.readLong(pos));
+ }
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserIndexOutput.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserIndexOutput.java
new file mode 100644
index 00000000000..53b65a1aff4
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserIndexOutput.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.IndexOutput;
+
+/** A {@link IndexOutput} wrapper that changes the endianness of the provided index output. */
+final class EndiannessReverserIndexOutput extends IndexOutput {
+
+ private final IndexOutput out;
+
+ EndiannessReverserIndexOutput(IndexOutput out) {
+ super("Endianness reverser Index Output wrapper", out.getName());
+ this.out = out;
+ }
+
+ @Override
+ public String getName() {
+ return out.getName();
+ }
+
+ /** Closes this stream to further operations. */
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return out.getFilePointer();
+ }
+
+ @Override
+ public long getChecksum() throws IOException {
+ return out.getChecksum();
+ }
+
+ @Override
+ public String toString() {
+ return out.getName();
+ }
+
+ @Override
+ public void writeByte(byte b) throws IOException {
+ out.writeByte(b);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int length) throws IOException {
+ writeBytes(b, 0, length);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int offset, int length) throws IOException {
+ out.writeBytes(b, offset, length);
+ }
+
+ @Override
+ public void writeInt(int i) throws IOException {
+ out.writeInt(Integer.reverseBytes(i));
+ }
+
+ @Override
+ public void writeShort(short i) throws IOException {
+ out.writeShort(Short.reverseBytes(i));
+ }
+
+ @Override
+ public void writeLong(long i) throws IOException {
+ out.writeLong(Long.reverseBytes(i));
+ }
+
+ @Override
+ public void writeString(String s) throws IOException {
+ out.writeString(s);
+ }
+
+ @Override
+ public void copyBytes(DataInput input, long numBytes) throws IOException {
+ out.copyBytes(input, numBytes);
+ }
+
+ @Override
+ public void writeMapOfStrings(Map<String, String> map) throws IOException {
+ out.writeMapOfStrings(map);
+ }
+
+ @Override
+ public void writeSetOfStrings(Set<String> set) throws IOException {
+ out.writeSetOfStrings(set);
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserUtil.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserUtil.java
new file mode 100644
index 00000000000..4a4829a1b99
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/EndiannessReverserUtil.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import org.apache.lucene.store.ChecksumIndexInput;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+
+/**
+ * Utility class to wrap open files
+ *
+ * @lucene.internal
+ */
+public final class EndiannessReverserUtil {
+
+ private EndiannessReverserUtil() {
+ // no instances
+ }
+
+ /** Open an index input */
+ public static IndexInput openInput(Directory directory, String name, IOContext context)
+ throws IOException {
+ return new EndiannessReverserIndexInput(directory.openInput(name, context));
+ }
+
+ /** Open a checksum index input */
+ public static ChecksumIndexInput openChecksumInput(
+ Directory directory, String name, IOContext context) throws IOException {
+ return new EndiannessReverserChecksumIndexInput(directory.openChecksumInput(name, context));
+ }
+
+ /** Open an index output */
+ public static IndexOutput createOutput(Directory directory, String name, IOContext context)
+ throws IOException {
+ return new EndiannessReverserIndexOutput(directory.createOutput(name, context));
+ }
+
+ /** Open a temp index output */
+ public static IndexOutput createTempOutput(
+ Directory directory, String prefix, String suffix, IOContext context) throws IOException {
+ return new EndiannessReverserIndexOutput(directory.createTempOutput(prefix, suffix, context));
+ }
+
+ /** wraps a data output */
+ public static DataOutput wrapDataOutput(DataOutput dataOutput) {
+ return new EndiannessReverserDataOutput(dataOutput);
+ }
+
+ /** wraps a data input */
+ public static DataInput wrapDataInput(DataInput dataInput) {
+ return new EndiannessReverserDataInput(dataInput);
+ }
+}
diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/package-info.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/package-info.java
new file mode 100644
index 00000000000..5804e871264
--- /dev/null
+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/store/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** Lucene 8.7 file format. */
+/** store helper */
+package org.apache.lucene.backward_codecs.store;
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsWriter.java
index 43878fce198..8a129e437ff 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsWriter.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.BlockTermState;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.FieldsConsumer;
@@ -251,7 +252,7 @@ public final class Lucene40BlockTreeTermsWriter extends FieldsConsumer {
state.segmentInfo.name,
state.segmentSuffix,
Lucene40BlockTreeTermsReader.TERMS_EXTENSION);
- termsOut = state.directory.createOutput(termsName, state.context);
+ termsOut = EndiannessReverserUtil.createOutput(state.directory, termsName, state.context);
boolean success = false;
IndexOutput metaOut = null, indexOut = null;
try {
@@ -267,7 +268,7 @@ public final class Lucene40BlockTreeTermsWriter extends FieldsConsumer {
state.segmentInfo.name,
state.segmentSuffix,
Lucene40BlockTreeTermsReader.TERMS_INDEX_EXTENSION);
- indexOut = state.directory.createOutput(indexName, state.context);
+ indexOut = EndiannessReverserUtil.createOutput(state.directory, indexName, state.context);
CodecUtil.writeIndexHeader(
indexOut,
Lucene40BlockTreeTermsReader.TERMS_INDEX_CODEC_NAME,
@@ -281,7 +282,7 @@ public final class Lucene40BlockTreeTermsWriter extends FieldsConsumer {
state.segmentInfo.name,
state.segmentSuffix,
Lucene40BlockTreeTermsReader.TERMS_META_EXTENSION);
- metaOut = state.directory.createOutput(metaName, state.context);
+ metaOut = EndiannessReverserUtil.createOutput(state.directory, metaName, state.context);
CodecUtil.writeIndexHeader(
metaOut,
Lucene40BlockTreeTermsReader.TERMS_META_CODEC_NAME,
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsWriter.java
index ccfcf9a5aa6..ad44548942b 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50PostingsWriter.java
@@ -28,6 +28,7 @@ import static org.apache.lucene.backward_codecs.lucene50.Lucene50PostingsFormat.
import java.io.IOException;
import org.apache.lucene.backward_codecs.lucene50.Lucene50PostingsFormat.IntBlockTermState;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.BlockTermState;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.CompetitiveImpactAccumulator;
@@ -108,7 +109,7 @@ public final class Lucene50PostingsWriter extends PushPostingsWriterBase {
String docFileName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene50PostingsFormat.DOC_EXTENSION);
- docOut = state.directory.createOutput(docFileName, state.context);
+ docOut = EndiannessReverserUtil.createOutput(state.directory, docFileName, state.context);
IndexOutput posOut = null;
IndexOutput payOut = null;
boolean success = false;
@@ -121,7 +122,7 @@ public final class Lucene50PostingsWriter extends PushPostingsWriterBase {
String posFileName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene50PostingsFormat.POS_EXTENSION);
- posOut = state.directory.createOutput(posFileName, state.context);
+ posOut = EndiannessReverserUtil.createOutput(state.directory, posFileName, state.context);
CodecUtil.writeIndexHeader(
posOut, POS_CODEC, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
@@ -147,7 +148,7 @@ public final class Lucene50PostingsWriter extends PushPostingsWriterBase {
state.segmentInfo.name,
state.segmentSuffix,
Lucene50PostingsFormat.PAY_EXTENSION);
- payOut = state.directory.createOutput(payFileName, state.context);
+ payOut = EndiannessReverserUtil.createOutput(state.directory, payFileName, state.context);
CodecUtil.writeIndexHeader(
payOut, PAY_CODEC, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50RWCompoundFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50RWCompoundFormat.java
index 7e9b2a6abeb..346a3f6b30f 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50RWCompoundFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/Lucene50RWCompoundFormat.java
@@ -17,6 +17,7 @@
package org.apache.lucene.backward_codecs.lucene50;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.CompoundDirectory;
import org.apache.lucene.codecs.CompoundFormat;
@@ -89,8 +90,8 @@ public final class Lucene50RWCompoundFormat extends CompoundFormat {
String dataFile = IndexFileNames.segmentFileName(si.name, "", DATA_EXTENSION);
String entriesFile = IndexFileNames.segmentFileName(si.name, "", ENTRIES_EXTENSION);
- try (IndexOutput data = dir.createOutput(dataFile, context);
- IndexOutput entries = dir.createOutput(entriesFile, context)) {
+ try (IndexOutput data = EndiannessReverserUtil.createOutput(dir, dataFile, context);
+ IndexOutput entries = EndiannessReverserUtil.createOutput(dir, entriesFile, context)) {
CodecUtil.writeIndexHeader(data, DATA_CODEC, VERSION_CURRENT, si.getId(), "");
CodecUtil.writeIndexHeader(entries, ENTRY_CODEC, VERSION_CURRENT, si.getId(), "");
@@ -108,7 +109,8 @@ public final class Lucene50RWCompoundFormat extends CompoundFormat {
for (String file : si.files()) {
// write bytes for file
long startOffset = data.getFilePointer();
- try (ChecksumIndexInput in = dir.openChecksumInput(file, IOContext.READONCE)) {
+ try (ChecksumIndexInput in =
+ EndiannessReverserUtil.openChecksumInput(dir, file, IOContext.READONCE)) {
// just copies the index header, verifying that its id matches what we expect
CodecUtil.verifyAndCopyIndexHeader(in, data, si.getId());
@@ -123,9 +125,9 @@ public final class Lucene50RWCompoundFormat extends CompoundFormat {
// this is poached from CodecUtil.writeFooter, but we need to use our own checksum, not
// data.getChecksum(), but I think
// adding a public method to CodecUtil to do that is somewhat dangerous:
- data.writeInt(CodecUtil.FOOTER_MAGIC);
- data.writeInt(0);
- data.writeLong(checksum);
+ CodecUtil.writeBEInt(data, CodecUtil.FOOTER_MAGIC);
+ CodecUtil.writeBEInt(data, 0);
+ CodecUtil.writeBELong(data, checksum);
}
long endOffset = data.getFilePointer();
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestBlockPostingsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestBlockPostingsFormat.java
index bb2bffa6a74..dfc48061ea4 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestBlockPostingsFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestBlockPostingsFormat.java
@@ -24,6 +24,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.backward_codecs.lucene40.blocktree.FieldReader;
import org.apache.lucene.backward_codecs.lucene40.blocktree.Stats;
import org.apache.lucene.backward_codecs.lucene50.Lucene50ScoreSkipReader.MutableImpactList;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.CompetitiveImpactAccumulator;
import org.apache.lucene.document.Document;
@@ -115,10 +116,10 @@ public class TestBlockPostingsFormat extends BasePostingsFormatTestCase {
acc.add(impact.freq, impact.norm);
}
try (Directory dir = newDirectory()) {
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
Lucene50SkipWriter.writeImpacts(acc, out);
}
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
byte[] b = new byte[Math.toIntExact(in.length())];
in.readBytes(b, 0, b.length);
List<Impact> impacts2 =
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestForUtil.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestForUtil.java
index 824a669007c..4293586dd36 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestForUtil.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/TestForUtil.java
@@ -22,6 +22,7 @@ import static org.apache.lucene.backward_codecs.lucene50.Lucene50PostingsFormat.
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -57,7 +58,7 @@ public class TestForUtil extends LuceneTestCase {
{
// encode
- IndexOutput out = d.createOutput("test.bin", IOContext.DEFAULT);
+ IndexOutput out = EndiannessReverserUtil.createOutput(d, "test.bin", IOContext.DEFAULT);
final ForUtil forUtil = new ForUtil(acceptableOverheadRatio, out);
for (int i = 0; i < iterations; ++i) {
@@ -73,7 +74,7 @@ public class TestForUtil extends LuceneTestCase {
{
// decode
- IndexInput in = d.openInput("test.bin", IOContext.READONCE);
+ IndexInput in = EndiannessReverserUtil.openInput(d, "test.bin", IOContext.READONCE);
final ForUtil forUtil = new ForUtil(in);
for (int i = 0; i < iterations; ++i) {
if (random().nextBoolean()) {
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexWriter.java
index c7ae5c1fcd5..857505fd1f2 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/FieldsIndexWriter.java
@@ -22,6 +22,9 @@ import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicReader;
+import org.apache.lucene.backward_codecs.packed.LegacyDirectMonotonicWriter;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.CorruptIndexException;
@@ -31,17 +34,15 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.packed.DirectMonotonicReader;
-import org.apache.lucene.util.packed.DirectMonotonicWriter;
/**
* Efficient index format for block-based {@link Codec}s.
*
* <p>For each block of compressed stored fields, this stores the first document of the block and
- * the start pointer of the block in a {@link DirectMonotonicWriter}. At read time, the docID is
- * binary-searched in the {@link DirectMonotonicReader} that records doc IDS, and the returned index
- * is used to look up the start pointer in the {@link DirectMonotonicReader} that records start
- * pointers.
+ * the start pointer of the block in a {@link LegacyDirectMonotonicWriter}. At read time, the docID
+ * is binary-searched in the {@link LegacyDirectMonotonicWriter} that records doc IDS, and the
+ * returned index is used to look up the start pointer in the {@link LegacyDirectMonotonicReader}
+ * that records start pointers.
*
* @lucene.internal
*/
@@ -79,11 +80,14 @@ public final class FieldsIndexWriter implements Closeable {
this.id = id;
this.blockShift = blockShift;
this.ioContext = ioContext;
- this.docsOut = dir.createTempOutput(name, codecName + "-doc_ids", ioContext);
+ this.docsOut =
+ EndiannessReverserUtil.createTempOutput(dir, name, codecName + "-doc_ids", ioContext);
boolean success = false;
try {
CodecUtil.writeHeader(docsOut, codecName + "Docs", VERSION_CURRENT);
- filePointersOut = dir.createTempOutput(name, codecName + "file_pointers", ioContext);
+ filePointersOut =
+ EndiannessReverserUtil.createTempOutput(
+ dir, name, codecName + "file_pointers", ioContext);
CodecUtil.writeHeader(filePointersOut, codecName + "FilePointers", VERSION_CURRENT);
success = true;
} finally {
@@ -111,7 +115,8 @@ public final class FieldsIndexWriter implements Closeable {
IOUtils.close(docsOut, filePointersOut);
try (IndexOutput dataOut =
- dir.createOutput(IndexFileNames.segmentFileName(name, suffix, extension), ioContext)) {
+ EndiannessReverserUtil.createOutput(
+ dir, IndexFileNames.segmentFileName(name, suffix, extension), ioContext)) {
CodecUtil.writeIndexHeader(dataOut, codecName + "Idx", VERSION_CURRENT, id, suffix);
metaOut.writeInt(numDocs);
@@ -120,12 +125,13 @@ public final class FieldsIndexWriter implements Closeable {
metaOut.writeLong(dataOut.getFilePointer());
try (ChecksumIndexInput docsIn =
- dir.openChecksumInput(docsOut.getName(), IOContext.READONCE)) {
+ EndiannessReverserUtil.openChecksumInput(dir, docsOut.getName(), IOContext.READONCE)) {
CodecUtil.checkHeader(docsIn, codecName + "Docs", VERSION_CURRENT, VERSION_CURRENT);
Throwable priorE = null;
try {
- final DirectMonotonicWriter docs =
- DirectMonotonicWriter.getInstance(metaOut, dataOut, totalChunks + 1, blockShift);
+ final LegacyDirectMonotonicWriter docs =
+ LegacyDirectMonotonicWriter.getInstance(
+ metaOut, dataOut, totalChunks + 1, blockShift);
long doc = 0;
docs.add(doc);
for (int i = 0; i < totalChunks; ++i) {
@@ -147,13 +153,15 @@ public final class FieldsIndexWriter implements Closeable {
metaOut.writeLong(dataOut.getFilePointer());
try (ChecksumIndexInput filePointersIn =
- dir.openChecksumInput(filePointersOut.getName(), IOContext.READONCE)) {
+ EndiannessReverserUtil.openChecksumInput(
+ dir, filePointersOut.getName(), IOContext.READONCE)) {
CodecUtil.checkHeader(
filePointersIn, codecName + "FilePointers", VERSION_CURRENT, VERSION_CURRENT);
Throwable priorE = null;
try {
- final DirectMonotonicWriter filePointers =
- DirectMonotonicWriter.getInstance(metaOut, dataOut, totalChunks + 1, blockShift);
+ final LegacyDirectMonotonicWriter filePointers =
+ LegacyDirectMonotonicWriter.getInstance(
+ metaOut, dataOut, totalChunks + 1, blockShift);
long fp = 0;
for (int i = 0; i < totalChunks; ++i) {
fp += filePointersIn.readVLong();
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsWriter.java
index 464c296580e..914df59314d 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingStoredFieldsWriter.java
@@ -33,6 +33,7 @@ import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.StoredFieldsReader;
import org.apache.lucene.codecs.StoredFieldsWriter;
@@ -112,16 +113,20 @@ public final class Lucene50CompressingStoredFieldsWriter extends StoredFieldsWri
boolean success = false;
try {
metaStream =
- directory.createOutput(
- IndexFileNames.segmentFileName(segment, segmentSuffix, META_EXTENSION), context);
+ EndiannessReverserUtil.createOutput(
+ directory,
+ IndexFileNames.segmentFileName(segment, segmentSuffix, META_EXTENSION),
+ context);
CodecUtil.writeIndexHeader(
metaStream, INDEX_CODEC_NAME + "Meta", VERSION_CURRENT, si.getId(), segmentSuffix);
assert CodecUtil.indexHeaderLength(INDEX_CODEC_NAME + "Meta", segmentSuffix)
== metaStream.getFilePointer();
fieldsStream =
- directory.createOutput(
- IndexFileNames.segmentFileName(segment, segmentSuffix, FIELDS_EXTENSION), context);
+ EndiannessReverserUtil.createOutput(
+ directory,
+ IndexFileNames.segmentFileName(segment, segmentSuffix, FIELDS_EXTENSION),
+ context);
CodecUtil.writeIndexHeader(
fieldsStream, formatName, VERSION_CURRENT, si.getId(), segmentSuffix);
assert CodecUtil.indexHeaderLength(formatName, segmentSuffix)
@@ -325,11 +330,11 @@ public final class Lucene50CompressingStoredFieldsWriter extends StoredFieldsWri
if (number instanceof Byte || number instanceof Short || number instanceof Integer) {
bufferedDocs.writeZInt(number.intValue());
} else if (number instanceof Long) {
- writeTLong(bufferedDocs, number.longValue());
+ writeTLong(EndiannessReverserUtil.wrapDataOutput(bufferedDocs), number.longValue());
} else if (number instanceof Float) {
- writeZFloat(bufferedDocs, number.floatValue());
+ writeZFloat(EndiannessReverserUtil.wrapDataOutput(bufferedDocs), number.floatValue());
} else if (number instanceof Double) {
- writeZDouble(bufferedDocs, number.doubleValue());
+ writeZDouble(EndiannessReverserUtil.wrapDataOutput(bufferedDocs), number.doubleValue());
} else {
throw new AssertionError("Cannot get here");
}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsWriter.java
index ba3bc3e115e..12341fe49f0 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene50/compressing/Lucene50CompressingTermVectorsWriter.java
@@ -37,6 +37,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.TermVectorsReader;
import org.apache.lucene.codecs.TermVectorsWriter;
@@ -244,7 +245,8 @@ public final class Lucene50CompressingTermVectorsWriter extends TermVectorsWrite
boolean success = false;
try {
metaStream =
- directory.createOutput(
+ EndiannessReverserUtil.createOutput(
+ directory,
IndexFileNames.segmentFileName(segment, segmentSuffix, VECTORS_META_EXTENSION),
context);
CodecUtil.writeIndexHeader(
@@ -257,8 +259,10 @@ public final class Lucene50CompressingTermVectorsWriter extends TermVectorsWrite
== metaStream.getFilePointer();
vectorsStream =
- directory.createOutput(
- IndexFileNames.segmentFileName(segment, segmentSuffix, VECTORS_EXTENSION), context);
+ EndiannessReverserUtil.createOutput(
+ directory,
+ IndexFileNames.segmentFileName(segment, segmentSuffix, VECTORS_EXTENSION),
+ context);
CodecUtil.writeIndexHeader(
vectorsStream, formatName, VERSION_CURRENT, si.getId(), segmentSuffix);
assert CodecUtil.indexHeaderLength(formatName, segmentSuffix)
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsWriter.java
index 90d44f3d4cc..c0276f9fd71 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene60/Lucene60PointsWriter.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.MutablePointValues;
import org.apache.lucene.codecs.PointsReader;
@@ -66,7 +67,8 @@ public class Lucene60PointsWriter extends PointsWriter {
writeState.segmentInfo.name,
writeState.segmentSuffix,
Lucene60PointsFormat.DATA_EXTENSION);
- dataOut = writeState.directory.createOutput(dataFileName, writeState.context);
+ dataOut =
+ EndiannessReverserUtil.createOutput(writeState.directory, dataFileName, writeState.context);
boolean success = false;
try {
CodecUtil.writeIndexHeader(
@@ -270,7 +272,8 @@ public class Lucene60PointsWriter extends PointsWriter {
Lucene60PointsFormat.INDEX_EXTENSION);
// Write index file
try (IndexOutput indexOut =
- writeState.directory.createOutput(indexFileName, writeState.context)) {
+ EndiannessReverserUtil.createOutput(
+ writeState.directory, indexFileName, writeState.context)) {
CodecUtil.writeIndexHeader(
indexOut,
Lucene60PointsFormat.META_CODEC_NAME,
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsConsumer.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsConsumer.java
index 23141831ed9..05dc6618480 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsConsumer.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70NormsConsumer.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene70;
import static org.apache.lucene.backward_codecs.lucene70.Lucene70NormsFormat.VERSION_CURRENT;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.NormsConsumer;
import org.apache.lucene.codecs.NormsProducer;
@@ -47,13 +48,13 @@ final class Lucene70NormsConsumer extends NormsConsumer {
String dataName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, dataExtension);
- data = state.directory.createOutput(dataName, state.context);
+ data = EndiannessReverserUtil.createOutput(state.directory, dataName, state.context);
CodecUtil.writeIndexHeader(
data, dataCodec, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
String metaName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, metaExtension);
- meta = state.directory.createOutput(metaName, state.context);
+ meta = EndiannessReverserUtil.createOutput(state.directory, metaName, state.context);
CodecUtil.writeIndexHeader(
meta, metaCodec, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
maxDoc = state.segmentInfo.maxDoc();
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70RWSegmentInfoFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70RWSegmentInfoFormat.java
index e0eaa477048..cf267f03c5a 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70RWSegmentInfoFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/Lucene70RWSegmentInfoFormat.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene70;
import java.io.IOException;
import java.util.Set;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.SegmentInfo;
@@ -41,7 +42,7 @@ public class Lucene70RWSegmentInfoFormat extends Lucene70SegmentInfoFormat {
final String fileName =
IndexFileNames.segmentFileName(si.name, "", Lucene70SegmentInfoFormat.SI_EXTENSION);
- try (IndexOutput output = dir.createOutput(fileName, ioContext)) {
+ try (IndexOutput output = EndiannessReverserUtil.createOutput(dir, fileName, ioContext)) {
// Only add the file once we've successfully created it, else IFD assert can trip:
si.addFile(fileName);
CodecUtil.writeIndexHeader(
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/TestIndexedDISI.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/TestIndexedDISI.java
index 2a71222d7c2..cd7d5b1e0fa 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/TestIndexedDISI.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene70/TestIndexedDISI.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene70;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -99,11 +100,12 @@ public class TestIndexedDISI extends LuceneTestCase {
// we set MAX_ARRAY_LENGTH bits so the encoding will be sparse
set.set(start, start + IndexedDISI.MAX_ARRAY_LENGTH);
long length;
- try (IndexOutput out = dir.createOutput("sparse", IOContext.DEFAULT)) {
+ try (IndexOutput out =
+ EndiannessReverserUtil.createOutput(dir, "sparse", IOContext.DEFAULT)) {
IndexedDISI.writeBitSet(new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH), out);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("sparse", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "sparse", IOContext.DEFAULT)) {
IndexedDISI disi = new IndexedDISI(in, 0L, length, IndexedDISI.MAX_ARRAY_LENGTH);
assertEquals(start, disi.nextDoc());
assertEquals(IndexedDISI.Method.SPARSE, disi.method);
@@ -112,11 +114,11 @@ public class TestIndexedDISI extends LuceneTestCase {
// now we set one more bit so the encoding will be dense
set.set(start + IndexedDISI.MAX_ARRAY_LENGTH + random().nextInt(100));
- try (IndexOutput out = dir.createOutput("bar", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "bar", IOContext.DEFAULT)) {
IndexedDISI.writeBitSet(new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH + 1), out);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("bar", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "bar", IOContext.DEFAULT)) {
IndexedDISI disi = new IndexedDISI(in, 0L, length, IndexedDISI.MAX_ARRAY_LENGTH + 1);
assertEquals(start, disi.nextDoc());
assertEquals(IndexedDISI.Method.DENSE, disi.method);
@@ -182,12 +184,12 @@ public class TestIndexedDISI extends LuceneTestCase {
private void doTest(FixedBitSet set, Directory dir) throws IOException {
final int cardinality = set.cardinality();
long length;
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi = new IndexedDISI(in, 0L, length, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
int i = 0;
@@ -199,7 +201,7 @@ public class TestIndexedDISI extends LuceneTestCase {
}
for (int step : new int[] {1, 10, 100, 1000, 10000, 100000}) {
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi = new IndexedDISI(in, 0L, length, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
int index = -1;
@@ -220,7 +222,7 @@ public class TestIndexedDISI extends LuceneTestCase {
}
for (int step : new int[] {10, 100, 1000, 10000, 100000}) {
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi = new IndexedDISI(in, 0L, length, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
int index = -1;
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsConsumer.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsConsumer.java
index ea5c4df34a1..aa16a8916ee 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsConsumer.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/Lucene80NormsConsumer.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene80;
import static org.apache.lucene.backward_codecs.lucene80.Lucene80NormsFormat.VERSION_CURRENT;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.NormsConsumer;
import org.apache.lucene.codecs.NormsProducer;
@@ -47,13 +48,13 @@ final class Lucene80NormsConsumer extends NormsConsumer {
String dataName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, dataExtension);
- data = state.directory.createOutput(dataName, state.context);
+ data = EndiannessReverserUtil.createOutput(state.directory, dataName, state.context);
CodecUtil.writeIndexHeader(
data, dataCodec, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
String metaName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, metaExtension);
- meta = state.directory.createOutput(metaName, state.context);
+ meta = EndiannessReverserUtil.createOutput(state.directory, metaName, state.context);
CodecUtil.writeIndexHeader(
meta, metaCodec, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
maxDoc = state.segmentInfo.maxDoc();
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java
index fb18da540e1..d5f0bc03e06 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestIndexedDISI.java
@@ -18,6 +18,7 @@ package org.apache.lucene.backward_codecs.lucene80;
import java.io.IOException;
import java.util.Random;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -98,12 +99,12 @@ public class TestIndexedDISI extends LuceneTestCase {
final int cardinality = set.cardinality();
final byte denseRankPower = 9; // Not tested here so fixed to isolate factors
int jumpTableentryCount;
- try (IndexOutput out = dir.createOutput("bar", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "bar", IOContext.DEFAULT)) {
jumpTableentryCount =
IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out, denseRankPower);
}
- try (IndexInput in = dir.openInput("bar", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "bar", IOContext.DEFAULT)) {
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
int doc = disi2.docID();
int index = 0;
@@ -148,11 +149,11 @@ public class TestIndexedDISI extends LuceneTestCase {
try (Directory dir = newDirectory()) {
final int cardinality = set.cardinality();
int jumpTableEntryCount;
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
jumpTableEntryCount =
IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out, denseRankPower);
}
- try (IndexInput fullInput = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput fullInput = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexInput blockData =
IndexedDISI.createBlockSlice(
fullInput, "blocks", 0, fullInput.length(), jumpTableEntryCount);
@@ -213,13 +214,13 @@ public class TestIndexedDISI extends LuceneTestCase {
rarely() ? -1 : (byte) (random().nextInt(7) + 7); // sane + chance of disable
long length;
int jumpTableentryCount;
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
jumpTableentryCount =
IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out, denseRankPower);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
for (int i = 0; i < set.length(); i++) {
IndexedDISI disi =
new IndexedDISI(in, 0L, length, jumpTableentryCount, denseRankPower, cardinality);
@@ -312,13 +313,14 @@ public class TestIndexedDISI extends LuceneTestCase {
set.set(start, start + IndexedDISI.MAX_ARRAY_LENGTH);
long length;
int jumpTableEntryCount;
- try (IndexOutput out = dir.createOutput("sparse", IOContext.DEFAULT)) {
+ try (IndexOutput out =
+ EndiannessReverserUtil.createOutput(dir, "sparse", IOContext.DEFAULT)) {
jumpTableEntryCount =
IndexedDISI.writeBitSet(
new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH), out, denseRankPower);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("sparse", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "sparse", IOContext.DEFAULT)) {
IndexedDISI disi =
new IndexedDISI(
in, 0L, length, jumpTableEntryCount, denseRankPower, IndexedDISI.MAX_ARRAY_LENGTH);
@@ -329,12 +331,12 @@ public class TestIndexedDISI extends LuceneTestCase {
// now we set one more bit so the encoding will be dense
set.set(start + IndexedDISI.MAX_ARRAY_LENGTH + random().nextInt(100));
- try (IndexOutput out = dir.createOutput("bar", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "bar", IOContext.DEFAULT)) {
IndexedDISI.writeBitSet(
new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH + 1), out, denseRankPower);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("bar", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "bar", IOContext.DEFAULT)) {
IndexedDISI disi =
new IndexedDISI(
in,
@@ -419,13 +421,13 @@ public class TestIndexedDISI extends LuceneTestCase {
try (Directory dir = newDirectory()) {
long length;
int jumpTableEntryCount = -1;
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
jumpTableEntryCount =
IndexedDISI.writeBitSet(
new BitSetIterator(set, set.cardinality()), out, denseRankPowerWrite);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
new IndexedDISI(in, 0L, length, jumpTableEntryCount, denseRankPowerRead, set.cardinality());
}
// This tests the legality of the denseRankPower only, so we don't do anything with the disi
@@ -444,14 +446,14 @@ public class TestIndexedDISI extends LuceneTestCase {
final int cardinality = set.cardinality();
long length;
int jumpTableentryCount;
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
jumpTableentryCount =
IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out, denseRankPower);
length = out.getFilePointer();
}
int step = 16000;
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi =
new IndexedDISI(in, 0L, length, jumpTableentryCount, denseRankPower, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
@@ -492,13 +494,13 @@ public class TestIndexedDISI extends LuceneTestCase {
rarely() ? -1 : (byte) (random().nextInt(7) + 7); // sane + chance of disable
long length;
int jumpTableentryCount;
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
jumpTableentryCount =
IndexedDISI.writeBitSet(new BitSetIterator(set, cardinality), out, denseRankPower);
length = out.getFilePointer();
}
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi =
new IndexedDISI(in, 0L, length, jumpTableentryCount, denseRankPower, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
@@ -506,7 +508,7 @@ public class TestIndexedDISI extends LuceneTestCase {
}
for (int step : new int[] {1, 10, 100, 1000, 10000, 100000}) {
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi =
new IndexedDISI(in, 0L, length, jumpTableentryCount, denseRankPower, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
@@ -515,7 +517,7 @@ public class TestIndexedDISI extends LuceneTestCase {
}
for (int step : new int[] {10, 100, 1000, 10000, 100000}) {
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
IndexedDISI disi =
new IndexedDISI(in, 0L, length, jumpTableentryCount, denseRankPower, cardinality);
BitSetIterator disi2 = new BitSetIterator(set, cardinality);
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsWriter.java
index 67ab62feae3..3fa503c033e 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/Lucene84PostingsWriter.java
@@ -27,6 +27,7 @@ import static org.apache.lucene.backward_codecs.lucene84.Lucene84PostingsFormat.
import java.io.IOException;
import java.nio.ByteOrder;
import org.apache.lucene.backward_codecs.lucene84.Lucene84PostingsFormat.IntBlockTermState;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.BlockTermState;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.CompetitiveImpactAccumulator;
@@ -105,7 +106,7 @@ public final class Lucene84PostingsWriter extends PushPostingsWriterBase {
String docFileName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene84PostingsFormat.DOC_EXTENSION);
- docOut = state.directory.createOutput(docFileName, state.context);
+ docOut = EndiannessReverserUtil.createOutput(state.directory, docFileName, state.context);
IndexOutput posOut = null;
IndexOutput payOut = null;
boolean success = false;
@@ -128,7 +129,7 @@ public final class Lucene84PostingsWriter extends PushPostingsWriterBase {
String posFileName =
IndexFileNames.segmentFileName(
state.segmentInfo.name, state.segmentSuffix, Lucene84PostingsFormat.POS_EXTENSION);
- posOut = state.directory.createOutput(posFileName, state.context);
+ posOut = EndiannessReverserUtil.createOutput(state.directory, posFileName, state.context);
CodecUtil.writeIndexHeader(
posOut, POS_CODEC, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
@@ -154,7 +155,7 @@ public final class Lucene84PostingsWriter extends PushPostingsWriterBase {
state.segmentInfo.name,
state.segmentSuffix,
Lucene84PostingsFormat.PAY_EXTENSION);
- payOut = state.directory.createOutput(payFileName, state.context);
+ payOut = EndiannessReverserUtil.createOutput(state.directory, payFileName, state.context);
CodecUtil.writeIndexHeader(
payOut, PAY_CODEC, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForDeltaUtil.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForDeltaUtil.java
index 3023c236f54..2a36971e9af 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForDeltaUtil.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForDeltaUtil.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene84;
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.io.IOException;
import java.util.Arrays;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -47,7 +48,7 @@ public class TestForDeltaUtil extends LuceneTestCase {
{
// encode
- IndexOutput out = d.createOutput("test.bin", IOContext.DEFAULT);
+ IndexOutput out = EndiannessReverserUtil.createOutput(d, "test.bin", IOContext.DEFAULT);
final ForDeltaUtil forDeltaUtil = new ForDeltaUtil(new ForUtil());
for (int i = 0; i < iterations; ++i) {
@@ -63,7 +64,7 @@ public class TestForDeltaUtil extends LuceneTestCase {
{
// decode
- IndexInput in = d.openInput("test.bin", IOContext.READONCE);
+ IndexInput in = EndiannessReverserUtil.openInput(d, "test.bin", IOContext.READONCE);
final ForDeltaUtil forDeltaUtil = new ForDeltaUtil(new ForUtil());
for (int i = 0; i < iterations; ++i) {
if (random().nextInt(5) == 0) {
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForUtil.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForUtil.java
index 5cfc142c70f..9ec7d00a13d 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForUtil.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestForUtil.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene84;
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.io.IOException;
import java.util.Arrays;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -48,7 +49,7 @@ public class TestForUtil extends LuceneTestCase {
{
// encode
- IndexOutput out = d.createOutput("test.bin", IOContext.DEFAULT);
+ IndexOutput out = EndiannessReverserUtil.createOutput(d, "test.bin", IOContext.DEFAULT);
final ForUtil forUtil = new ForUtil();
for (int i = 0; i < iterations; ++i) {
@@ -68,7 +69,7 @@ public class TestForUtil extends LuceneTestCase {
{
// decode
- IndexInput in = d.openInput("test.bin", IOContext.READONCE);
+ IndexInput in = EndiannessReverserUtil.openInput(d, "test.bin", IOContext.READONCE);
final ForUtil forUtil = new ForUtil();
for (int i = 0; i < iterations; ++i) {
final int bitsPerValue = in.readByte();
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestLucene84PostingsFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestLucene84PostingsFormat.java
index e1d8b3e9743..821ad32be20 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestLucene84PostingsFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestLucene84PostingsFormat.java
@@ -24,6 +24,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.backward_codecs.lucene40.blocktree.FieldReader;
import org.apache.lucene.backward_codecs.lucene40.blocktree.Stats;
import org.apache.lucene.backward_codecs.lucene84.Lucene84ScoreSkipReader.MutableImpactList;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.CompetitiveImpactAccumulator;
import org.apache.lucene.document.Document;
@@ -114,10 +115,10 @@ public class TestLucene84PostingsFormat extends BasePostingsFormatTestCase {
acc.add(impact.freq, impact.norm);
}
try (Directory dir = newDirectory()) {
- try (IndexOutput out = dir.createOutput("foo", IOContext.DEFAULT)) {
+ try (IndexOutput out = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT)) {
Lucene84SkipWriter.writeImpacts(acc, out);
}
- try (IndexInput in = dir.openInput("foo", IOContext.DEFAULT)) {
+ try (IndexInput in = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT)) {
byte[] b = new byte[Math.toIntExact(in.length())];
in.readBytes(b, 0, b.length);
List<Impact> impacts2 =
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestPForUtil.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestPForUtil.java
index 733974caa06..1bfad8b760d 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestPForUtil.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene84/TestPForUtil.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene84;
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.io.IOException;
import java.util.Arrays;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
@@ -57,7 +58,7 @@ public class TestPForUtil extends LuceneTestCase {
{
// encode
- IndexOutput out = d.createOutput("test.bin", IOContext.DEFAULT);
+ IndexOutput out = EndiannessReverserUtil.createOutput(d, "test.bin", IOContext.DEFAULT);
final PForUtil pforUtil = new PForUtil(new ForUtil());
for (int i = 0; i < iterations; ++i) {
@@ -73,7 +74,7 @@ public class TestPForUtil extends LuceneTestCase {
{
// decode
- IndexInput in = d.openInput("test.bin", IOContext.READONCE);
+ IndexInput in = EndiannessReverserUtil.openInput(d, "test.bin", IOContext.READONCE);
final PForUtil pforUtil = new PForUtil(new ForUtil());
for (int i = 0; i < iterations; ++i) {
if (random().nextInt(5) == 0) {
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsWriter.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsWriter.java
index f98bbcb9961..a342f777048 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsWriter.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86PointsWriter.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene86;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.codecs.MutablePointValues;
import org.apache.lucene.codecs.PointsReader;
@@ -61,7 +62,8 @@ public class Lucene86PointsWriter extends PointsWriter {
writeState.segmentInfo.name,
writeState.segmentSuffix,
Lucene86PointsFormat.DATA_EXTENSION);
- dataOut = writeState.directory.createOutput(dataFileName, writeState.context);
+ dataOut =
+ EndiannessReverserUtil.createOutput(writeState.directory, dataFileName, writeState.context);
boolean success = false;
try {
CodecUtil.writeIndexHeader(
@@ -76,7 +78,9 @@ public class Lucene86PointsWriter extends PointsWriter {
writeState.segmentInfo.name,
writeState.segmentSuffix,
Lucene86PointsFormat.META_EXTENSION);
- metaOut = writeState.directory.createOutput(metaFileName, writeState.context);
+ metaOut =
+ EndiannessReverserUtil.createOutput(
+ writeState.directory, metaFileName, writeState.context);
CodecUtil.writeIndexHeader(
metaOut,
Lucene86PointsFormat.META_CODEC_NAME,
@@ -89,7 +93,9 @@ public class Lucene86PointsWriter extends PointsWriter {
writeState.segmentInfo.name,
writeState.segmentSuffix,
Lucene86PointsFormat.INDEX_EXTENSION);
- indexOut = writeState.directory.createOutput(indexFileName, writeState.context);
+ indexOut =
+ EndiannessReverserUtil.createOutput(
+ writeState.directory, indexFileName, writeState.context);
CodecUtil.writeIndexHeader(
indexOut,
Lucene86PointsFormat.INDEX_CODEC_NAME,
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86RWSegmentInfoFormat.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86RWSegmentInfoFormat.java
index fedc5c6bfb7..ca90cec4c6a 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86RWSegmentInfoFormat.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene86/Lucene86RWSegmentInfoFormat.java
@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene86;
import java.io.IOException;
import java.util.Set;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.codecs.CodecUtil;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexSorter;
@@ -42,7 +43,7 @@ public class Lucene86RWSegmentInfoFormat extends Lucene86SegmentInfoFormat {
public void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {
final String fileName = IndexFileNames.segmentFileName(si.name, "", SI_EXTENSION);
- try (IndexOutput output = dir.createOutput(fileName, ioContext)) {
+ try (IndexOutput output = EndiannessReverserUtil.createOutput(dir, fileName, ioContext)) {
// Only add the file once we've successfully created it, else IFD assert can trip:
si.addFile(fileName);
CodecUtil.writeIndexHeader(output, CODEC_NAME, VERSION_CURRENT, si.getId(), "");
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyDirectMonotonic.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyDirectMonotonic.java
new file mode 100644
index 00000000000..1f55d255169
--- /dev/null
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyDirectMonotonic.java
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.packed;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Random;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.LongValues;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+
+public class TestLegacyDirectMonotonic extends LuceneTestCase {
+
+ public void testValidation() {
+ IllegalArgumentException e =
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> LegacyDirectMonotonicWriter.getInstance(null, null, -1, 10));
+ assertEquals("numValues can't be negative, got -1", e.getMessage());
+
+ e =
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> LegacyDirectMonotonicWriter.getInstance(null, null, 10, 1));
+ assertEquals("blockShift must be in [2-22], got 1", e.getMessage());
+
+ e =
+ expectThrows(
+ IllegalArgumentException.class,
+ () -> LegacyDirectMonotonicWriter.getInstance(null, null, 1L << 40, 5));
+ assertEquals(
+ "blockShift is too low for the provided number of values: blockShift=5, numValues=1099511627776, MAX_ARRAY_LENGTH="
+ + ArrayUtil.MAX_ARRAY_LENGTH,
+ e.getMessage());
+ }
+
+ public void testEmpty() throws IOException {
+ Directory dir = newDirectory();
+ final int blockShift =
+ TestUtil.nextInt(
+ random(),
+ LegacyDirectMonotonicWriter.MIN_BLOCK_SHIFT,
+ LegacyDirectMonotonicWriter.MAX_BLOCK_SHIFT);
+
+ final long dataLength;
+ try (IndexOutput metaOut = EndiannessReverserUtil.createOutput(dir, "meta", IOContext.DEFAULT);
+ IndexOutput dataOut = EndiannessReverserUtil.createOutput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicWriter w =
+ LegacyDirectMonotonicWriter.getInstance(metaOut, dataOut, 0, blockShift);
+ w.finish();
+ dataLength = dataOut.getFilePointer();
+ }
+
+ try (IndexInput metaIn = EndiannessReverserUtil.openInput(dir, "meta", IOContext.READONCE);
+ IndexInput dataIn = EndiannessReverserUtil.openInput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicReader.Meta meta =
+ LegacyDirectMonotonicReader.loadMeta(metaIn, 0, blockShift);
+ LegacyDirectMonotonicReader.getInstance(meta, dataIn.randomAccessSlice(0, dataLength));
+ // no exception
+ }
+
+ dir.close();
+ }
+
+ public void testSimple() throws IOException {
+ Directory dir = newDirectory();
+ final int blockShift = 2;
+
+ List<Long> actualValues = Arrays.asList(1L, 2L, 5L, 7L, 8L, 100L);
+ final int numValues = actualValues.size();
+
+ final long dataLength;
+ try (IndexOutput metaOut = EndiannessReverserUtil.createOutput(dir, "meta", IOContext.DEFAULT);
+ IndexOutput dataOut = EndiannessReverserUtil.createOutput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicWriter w =
+ LegacyDirectMonotonicWriter.getInstance(metaOut, dataOut, numValues, blockShift);
+ for (long v : actualValues) {
+ w.add(v);
+ }
+ w.finish();
+ dataLength = dataOut.getFilePointer();
+ }
+
+ try (IndexInput metaIn = EndiannessReverserUtil.openInput(dir, "meta", IOContext.READONCE);
+ IndexInput dataIn = EndiannessReverserUtil.openInput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicReader.Meta meta =
+ LegacyDirectMonotonicReader.loadMeta(metaIn, numValues, blockShift);
+ LongValues values =
+ LegacyDirectMonotonicReader.getInstance(meta, dataIn.randomAccessSlice(0, dataLength));
+ for (int i = 0; i < numValues; ++i) {
+ final long v = values.get(i);
+ assertEquals(actualValues.get(i).longValue(), v);
+ }
+ }
+
+ dir.close();
+ }
+
+ public void testConstantSlope() throws IOException {
+ Directory dir = newDirectory();
+ final int blockShift =
+ TestUtil.nextInt(
+ random(),
+ LegacyDirectMonotonicWriter.MIN_BLOCK_SHIFT,
+ LegacyDirectMonotonicWriter.MAX_BLOCK_SHIFT);
+ final int numValues = TestUtil.nextInt(random(), 1, 1 << 20);
+ final long min = random().nextLong();
+ final long inc = random().nextInt(1 << random().nextInt(20));
+
+ List<Long> actualValues = new ArrayList<>();
+ for (int i = 0; i < numValues; ++i) {
+ actualValues.add(min + inc * i);
+ }
+
+ final long dataLength;
+ try (IndexOutput metaOut = EndiannessReverserUtil.createOutput(dir, "meta", IOContext.DEFAULT);
+ IndexOutput dataOut = EndiannessReverserUtil.createOutput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicWriter w =
+ LegacyDirectMonotonicWriter.getInstance(metaOut, dataOut, numValues, blockShift);
+ for (long v : actualValues) {
+ w.add(v);
+ }
+ w.finish();
+ dataLength = dataOut.getFilePointer();
+ }
+
+ try (IndexInput metaIn = EndiannessReverserUtil.openInput(dir, "meta", IOContext.READONCE);
+ IndexInput dataIn = EndiannessReverserUtil.openInput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicReader.Meta meta =
+ LegacyDirectMonotonicReader.loadMeta(metaIn, numValues, blockShift);
+ LongValues values =
+ LegacyDirectMonotonicReader.getInstance(meta, dataIn.randomAccessSlice(0, dataLength));
+ for (int i = 0; i < numValues; ++i) {
+ assertEquals(actualValues.get(i).longValue(), values.get(i));
+ }
+ assertEquals(0, dataIn.getFilePointer());
+ }
+
+ dir.close();
+ }
+
+ public void testRandom() throws IOException {
+ Random random = random();
+ final int iters = atLeast(random, 3);
+ for (int iter = 0; iter < iters; ++iter) {
+ Directory dir = newDirectory();
+ final int blockShift =
+ TestUtil.nextInt(
+ random,
+ LegacyDirectMonotonicWriter.MIN_BLOCK_SHIFT,
+ LegacyDirectMonotonicWriter.MAX_BLOCK_SHIFT);
+ final int maxNumValues = 1 << 20;
+ final int numValues;
+ if (random.nextBoolean()) {
+ // random number
+ numValues = TestUtil.nextInt(random, 1, maxNumValues);
+ } else {
+ // multiple of the block size
+ final int numBlocks = TestUtil.nextInt(random, 0, maxNumValues >>> blockShift);
+ numValues = TestUtil.nextInt(random, 0, numBlocks) << blockShift;
+ }
+ List<Long> actualValues = new ArrayList<>();
+ long previous = random.nextLong();
+ if (numValues > 0) {
+ actualValues.add(previous);
+ }
+ for (int i = 1; i < numValues; ++i) {
+ previous += random.nextInt(1 << random.nextInt(20));
+ actualValues.add(previous);
+ }
+
+ final long dataLength;
+ try (IndexOutput metaOut =
+ EndiannessReverserUtil.createOutput(dir, "meta", IOContext.DEFAULT);
+ IndexOutput dataOut =
+ EndiannessReverserUtil.createOutput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicWriter w =
+ LegacyDirectMonotonicWriter.getInstance(metaOut, dataOut, numValues, blockShift);
+ for (long v : actualValues) {
+ w.add(v);
+ }
+ w.finish();
+ dataLength = dataOut.getFilePointer();
+ }
+
+ try (IndexInput metaIn = EndiannessReverserUtil.openInput(dir, "meta", IOContext.READONCE);
+ IndexInput dataIn = EndiannessReverserUtil.openInput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicReader.Meta meta =
+ LegacyDirectMonotonicReader.loadMeta(metaIn, numValues, blockShift);
+ LongValues values =
+ LegacyDirectMonotonicReader.getInstance(meta, dataIn.randomAccessSlice(0, dataLength));
+ for (int i = 0; i < numValues; ++i) {
+ assertEquals(actualValues.get(i).longValue(), values.get(i));
+ }
+ }
+
+ dir.close();
+ }
+ }
+
+ public void testMonotonicBinarySearch() throws IOException {
+ try (Directory dir = newDirectory()) {
+ doTestMonotonicBinarySearchAgainstLongArray(
+ dir, new long[] {4, 7, 8, 10, 19, 30, 55, 78, 100}, 2);
+ }
+ }
+
+ public void testMonotonicBinarySearchRandom() throws IOException {
+ try (Directory dir = newDirectory()) {
+ final int iters = atLeast(100);
+ for (int iter = 0; iter < iters; ++iter) {
+ final int arrayLength = random().nextInt(1 << random().nextInt(14));
+ final long[] array = new long[arrayLength];
+ final long base = random().nextLong();
+ final int bpv = TestUtil.nextInt(random(), 4, 61);
+ for (int i = 0; i < array.length; ++i) {
+ array[i] = base + TestUtil.nextLong(random(), 0, (1L << bpv) - 1);
+ }
+ Arrays.sort(array);
+ doTestMonotonicBinarySearchAgainstLongArray(dir, array, TestUtil.nextInt(random(), 2, 10));
+ }
+ }
+ }
+
+ private void doTestMonotonicBinarySearchAgainstLongArray(
+ Directory dir, long[] array, int blockShift) throws IOException {
+ try (IndexOutput metaOut = EndiannessReverserUtil.createOutput(dir, "meta", IOContext.DEFAULT);
+ IndexOutput dataOut = EndiannessReverserUtil.createOutput(dir, "data", IOContext.DEFAULT)) {
+ LegacyDirectMonotonicWriter writer =
+ LegacyDirectMonotonicWriter.getInstance(metaOut, dataOut, array.length, blockShift);
+ for (long l : array) {
+ writer.add(l);
+ }
+ writer.finish();
+ }
+
+ try (IndexInput metaIn = EndiannessReverserUtil.openInput(dir, "meta", IOContext.READONCE);
+ IndexInput dataIn = EndiannessReverserUtil.openInput(dir, "data", IOContext.READ)) {
+ LegacyDirectMonotonicReader.Meta meta =
+ LegacyDirectMonotonicReader.loadMeta(metaIn, array.length, blockShift);
+ LegacyDirectMonotonicReader reader =
+ LegacyDirectMonotonicReader.getInstance(
+ meta, dataIn.randomAccessSlice(0L, dir.fileLength("data")));
+
+ if (array.length == 0) {
+ assertEquals(-1, reader.binarySearch(0, array.length, 42L));
+ } else {
+ for (int i = 0; i < array.length; ++i) {
+ final long index = reader.binarySearch(0, array.length, array[i]);
+ assertTrue(index >= 0);
+ assertTrue(index < array.length);
+ assertEquals(array[i], array[(int) index]);
+ }
+ if (array[0] != Long.MIN_VALUE) {
+ assertEquals(-1, reader.binarySearch(0, array.length, array[0] - 1));
+ }
+ if (array[array.length - 1] != Long.MAX_VALUE) {
+ assertEquals(
+ -1 - array.length, reader.binarySearch(0, array.length, array[array.length - 1] + 1));
+ }
+ for (int i = 0; i < array.length - 2; ++i) {
+ if (array[i] + 1 < array[i + 1]) {
+ final long intermediate = random().nextBoolean() ? array[i] + 1 : array[i + 1] - 1;
+ final long index = reader.binarySearch(0, array.length, intermediate);
+ assertTrue(index < 0);
+ final int insertionPoint = Math.toIntExact(-1 - index);
+ assertTrue(insertionPoint > 0);
+ assertTrue(insertionPoint < array.length);
+ assertTrue(array[insertionPoint] > intermediate);
+ assertTrue(array[insertionPoint - 1] < intermediate);
+ }
+ }
+ }
+ }
+ dir.deleteFile("meta");
+ dir.deleteFile("data");
+ }
+}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyDirectPacked.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyDirectPacked.java
new file mode 100644
index 00000000000..eb71a8b5201
--- /dev/null
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyDirectPacked.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.packed;
+
+import java.util.Random;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
+import org.apache.lucene.store.ByteArrayDataInput;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.LongValues;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+
+public class TestLegacyDirectPacked extends LuceneTestCase {
+
+ /** simple encode/decode */
+ public void testSimple() throws Exception {
+ Directory dir = newDirectory();
+ int bitsPerValue = LegacyDirectWriter.bitsRequired(2);
+ IndexOutput output = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(output, 5, bitsPerValue);
+ writer.add(1);
+ writer.add(0);
+ writer.add(2);
+ writer.add(1);
+ writer.add(2);
+ writer.finish();
+ output.close();
+ IndexInput input = EndiannessReverserUtil.openInput(dir, "foo", IOContext.DEFAULT);
+ LongValues reader =
+ LegacyDirectReader.getInstance(input.randomAccessSlice(0, input.length()), bitsPerValue, 0);
+ assertEquals(1, reader.get(0));
+ assertEquals(0, reader.get(1));
+ assertEquals(2, reader.get(2));
+ assertEquals(1, reader.get(3));
+ assertEquals(2, reader.get(4));
+ input.close();
+ dir.close();
+ }
+
+ /** test exception is delivered if you add the wrong number of values */
+ public void testNotEnoughValues() throws Exception {
+ Directory dir = newDirectory();
+ int bitsPerValue = LegacyDirectWriter.bitsRequired(2);
+ IndexOutput output = EndiannessReverserUtil.createOutput(dir, "foo", IOContext.DEFAULT);
+ LegacyDirectWriter writer = LegacyDirectWriter.getInstance(output, 5, bitsPerValue);
+ writer.add(1);
+ writer.add(0);
+ writer.add(2);
+ writer.add(1);
+ IllegalStateException expected =
+ expectThrows(
+ IllegalStateException.class,
+ () -> {
+ writer.finish();
+ });
+ assertTrue(expected.getMessage().startsWith("Wrong number of values added"));
+
+ output.close();
+ dir.close();
+ }
+
+ public void testRandom() throws Exception {
+ Directory dir = newDirectory();
+ for (int bpv = 1; bpv <= 64; bpv++) {
+ doTestBpv(dir, bpv, 0);
+ }
+ dir.close();
+ }
+
+ public void testRandomWithOffset() throws Exception {
+ Directory dir = newDirectory();
+ final int offset = TestUtil.nextInt(random(), 1, 100);
+ for (int bpv = 1; bpv <= 64; bpv++) {
+ doTestBpv(dir, bpv, offset);
+ }
+ dir.close();
+ }
+
+ private void doTestBpv(Directory directory, int bpv, long offset) throws Exception {
+ MyRandom random = new MyRandom(random().nextLong());
+ int numIters = TEST_NIGHTLY ? 100 : 10;
+ for (int i = 0; i < numIters; i++) {
+ long original[] = randomLongs(random, bpv);
+ int bitsRequired = bpv == 64 ? 64 : LegacyDirectWriter.bitsRequired(1L << (bpv - 1));
+ String name = "bpv" + bpv + "_" + i;
+ IndexOutput output = EndiannessReverserUtil.createOutput(directory, name, IOContext.DEFAULT);
+ for (long j = 0; j < offset; ++j) {
+ output.writeByte((byte) random.nextInt());
+ }
+ LegacyDirectWriter writer =
+ LegacyDirectWriter.getInstance(output, original.length, bitsRequired);
+ for (int j = 0; j < original.length; j++) {
+ writer.add(original[j]);
+ }
+ writer.finish();
+ output.close();
+ IndexInput input = EndiannessReverserUtil.openInput(directory, name, IOContext.DEFAULT);
+ LongValues reader =
+ LegacyDirectReader.getInstance(
+ input.randomAccessSlice(0, input.length()), bitsRequired, offset);
+ for (int j = 0; j < original.length; j++) {
+ assertEquals("bpv=" + bpv, original[j], reader.get(j));
+ }
+ input.close();
+ }
+ }
+
+ private long[] randomLongs(MyRandom random, int bpv) {
+ int amount = random.nextInt(5000);
+ long longs[] = new long[amount];
+ for (int i = 0; i < longs.length; i++) {
+ longs[i] = random.nextLong(bpv);
+ }
+ return longs;
+ }
+
+ // java.util.Random only returns 48bits of randomness in nextLong...
+ static class MyRandom extends Random {
+ byte buffer[] = new byte[8];
+ ByteArrayDataInput input = new ByteArrayDataInput();
+
+ MyRandom(long seed) {
+ super(seed);
+ }
+
+ public synchronized long nextLong(int bpv) {
+ nextBytes(buffer);
+ input.reset(buffer);
+ long bits = input.readLong();
+ return bits >>> (64 - bpv);
+ }
+ }
+}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyPackedInts.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyPackedInts.java
index 4049738a215..4ab2a93678f 100644
--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyPackedInts.java
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/packed/TestLegacyPackedInts.java
@@ -18,6 +18,7 @@ package org.apache.lucene.backward_codecs.packed;
import com.carrotsearch.randomizedtesting.generators.RandomNumbers;
import java.io.IOException;
+import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
@@ -37,7 +38,7 @@ public class TestLegacyPackedInts extends LuceneTestCase {
final int valueCount = TestUtil.nextInt(random(), 1, 600);
final Directory d = newDirectory();
- IndexOutput out = d.createOutput("out.bin", newIOContext(random()));
+ IndexOutput out = EndiannessReverserUtil.createOutput(d, "out.bin", newIOContext(random()));
final int mem = random().nextInt(2 * PackedInts.DEFAULT_BUFFER_SIZE);
PackedInts.Writer w =
PackedInts.getWriterNoHeader(out, PackedInts.Format.PACKED, valueCount, nbits, mem);
@@ -65,7 +66,7 @@ public class TestLegacyPackedInts extends LuceneTestCase {
assertEquals(bytes, fp - startFp);
{ // test reader
- IndexInput in = d.openInput("out.bin", newIOContext(random()));
+ IndexInput in = EndiannessReverserUtil.openInput(d, "out.bin", newIOContext(random()));
PackedInts.Reader r =
LegacyPackedInts.getReaderNoHeader(
in, PackedInts.Format.PACKED, PackedInts.VERSION_CURRENT, valueCount, nbits);
@@ -99,12 +100,14 @@ public class TestLegacyPackedInts extends LuceneTestCase {
public void testEndPointer() throws IOException {
final Directory dir = newDirectory();
final int valueCount = RandomNumbers.randomIntBetween(random(), 1, 1000);
- final IndexOutput out = dir.createOutput("tests.bin", newIOContext(random()));
+ final IndexOutput out =
+ EndiannessReverserUtil.createOutput(dir, "tests.bin", newIOContext(random()));
for (int i = 0; i < valueCount; ++i) {
out.writeLong(0);
}
out.close();
- final IndexInput in = dir.openInput("tests.bin", newIOContext(random()));
+ final IndexInput in =
+ EndiannessReverserUtil.openInput(dir, "tests.bin", newIOContext(random()));
for (int version = PackedInts.VERSION_START; version <= PackedInts.VERSION_CURRENT; ++version) {
for (int bpv = 1; bpv <= 64; ++bpv) {
for (PackedInts.Format format : PackedInts.Format.values()) {
@@ -135,7 +138,7 @@ public class TestLegacyPackedInts extends LuceneTestCase {
public void testSingleValue() throws Exception {
for (int bitsPerValue = 1; bitsPerValue <= 64; ++bitsPerValue) {
Directory dir = newDirectory();
- IndexOutput out = dir.createOutput("out", newIOContext(random()));
+ IndexOutput out = EndiannessReverserUtil.createOutput(dir, "out", newIOContext(random()));
PackedInts.Writer w =
PackedInts.getWriterNoHeader(
out, PackedInts.Format.PACKED, 1, bitsPerValue, PackedInts.DEFAULT_BUFFER_SIZE);
@@ -145,7 +148,7 @@ public class TestLegacyPackedInts extends LuceneTestCase {
final long end = out.getFilePointer();
out.close();
- IndexInput in = dir.openInput("out", newIOContext(random()));
+ IndexInput in = EndiannessReverserUtil.openInput(dir, "out", newIOContext(random()));
Reader reader =
LegacyPackedInts.getReaderNoHeader(
in, PackedInts.Format.PACKED, PackedInts.VERSION_CURRENT, 1, bitsPerValue);
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/EndiannessReverserTestCase.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/EndiannessReverserTestCase.java
new file mode 100644
index 00000000000..93c2063d4d1
--- /dev/null
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/EndiannessReverserTestCase.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.store.RandomAccessInput;
+import org.apache.lucene.util.LuceneTestCase;
+
+public abstract class EndiannessReverserTestCase extends LuceneTestCase {
+
+ protected abstract IndexInput getEndiannessReverserInput(
+ Directory directory, String name, IOContext context) throws IOException;
+
+ protected abstract IndexOutput getEndiannessReverserOutput(
+ Directory directory, String name, IOContext context) throws IOException;
+
+ protected abstract boolean supportSlice();
+
+ public void testReadShort() throws IOException {
+ final Directory directory = newDirectory();
+ final IndexOutput output;
+ if (random().nextBoolean()) {
+ output = getEndiannessReverserOutput(directory, "endianness", IOContext.DEFAULT);
+ } else {
+ output = directory.createOutput("endianness", IOContext.DEFAULT);
+ }
+ int values = atLeast(30);
+ for (int i = 0; i < values; i++) {
+ output.writeShort((short) random().nextInt());
+ }
+ long len = output.getFilePointer();
+ output.close();
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ for (int i = 0; i < values; i++) {
+ assertEquals(input.readShort(), Short.reverseBytes(wrapped.readShort()));
+ }
+ input.close();
+ wrapped.close();
+ }
+ if (supportSlice()) {
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ IndexInput slice = wrapped.slice("slice", 0, len);
+ for (int i = 0; i < values; i++) {
+ assertEquals(input.readShort(), Short.reverseBytes(slice.readShort()));
+ }
+ slice.close();
+ input.close();
+ wrapped.close();
+ }
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ RandomAccessInput randomAccessInput = input.randomAccessSlice(0, len);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ RandomAccessInput randomAccessWrapped = wrapped.randomAccessSlice(0, len);
+ for (int i = 0; i < values; i++) {
+ assertEquals(
+ randomAccessInput.readShort(2 * i),
+ Short.reverseBytes(randomAccessWrapped.readShort(2 * i)));
+ }
+ input.close();
+ wrapped.close();
+ }
+ }
+ directory.close();
+ }
+
+ public void testReadInt() throws IOException {
+ Directory directory = newDirectory();
+ IndexOutput output;
+ if (random().nextBoolean()) {
+ output = getEndiannessReverserOutput(directory, "endianness", IOContext.DEFAULT);
+ } else {
+ output = directory.createOutput("endianness", IOContext.DEFAULT);
+ }
+ int values = atLeast(30);
+ for (int i = 0; i < values; i++) {
+ output.writeInt(random().nextInt());
+ }
+ long len = output.getFilePointer();
+ output.close();
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ for (int i = 0; i < values; i++) {
+ assertEquals(input.readInt(), Integer.reverseBytes(wrapped.readInt()));
+ }
+ input.close();
+ wrapped.close();
+ }
+ if (supportSlice()) {
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ IndexInput slice = wrapped.slice("slice", 0, len);
+ for (int i = 0; i < values; i++) {
+ assertEquals(input.readInt(), Integer.reverseBytes(slice.readInt()));
+ }
+ slice.close();
+ input.close();
+ wrapped.close();
+ }
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ RandomAccessInput randomAccessInput = input.randomAccessSlice(0, len);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ RandomAccessInput randomAccessWrapped = wrapped.randomAccessSlice(0, len);
+ for (int i = 0; i < values; i++) {
+ assertEquals(
+ randomAccessInput.readInt(4 * i),
+ Integer.reverseBytes(randomAccessWrapped.readInt(4 * i)));
+ }
+ input.close();
+ wrapped.close();
+ }
+ }
+ directory.close();
+ }
+
+ public void testReadLong() throws IOException {
+ Directory directory = newDirectory();
+ IndexOutput output;
+ if (random().nextBoolean()) {
+ output = getEndiannessReverserOutput(directory, "endianness", IOContext.DEFAULT);
+ } else {
+ output = directory.createOutput("endianness", IOContext.DEFAULT);
+ }
+ int values = atLeast(30);
+ for (int i = 0; i < values; i++) {
+ output.writeLong(random().nextLong());
+ }
+ long len = output.getFilePointer();
+ output.close();
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ for (int i = 0; i < values; i++) {
+ assertEquals(input.readLong(), Long.reverseBytes(wrapped.readLong()));
+ }
+ input.close();
+ wrapped.close();
+ }
+ if (supportSlice()) {
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ IndexInput slice = wrapped.slice("slice", 0, len);
+ for (int i = 0; i < values; i++) {
+ assertEquals(input.readLong(), Long.reverseBytes(slice.readLong()));
+ }
+ slice.close();
+ input.close();
+ wrapped.close();
+ }
+ {
+ IndexInput input = directory.openInput("endianness", IOContext.DEFAULT);
+ RandomAccessInput randomAccessInput = input.randomAccessSlice(0, len);
+ IndexInput wrapped = getEndiannessReverserInput(directory, "endianness", IOContext.DEFAULT);
+ RandomAccessInput randomAccessWrapped = wrapped.randomAccessSlice(0, len);
+ for (int i = 0; i < values; i++) {
+ assertEquals(
+ randomAccessInput.readLong(8 * i),
+ Long.reverseBytes(randomAccessWrapped.readLong(8 * i)));
+ }
+ input.close();
+ wrapped.close();
+ }
+ }
+ directory.close();
+ }
+}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/TestEndiannessReverserCheckSumIndexInput.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/TestEndiannessReverserCheckSumIndexInput.java
new file mode 100644
index 00000000000..345fd0aa7a2
--- /dev/null
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/TestEndiannessReverserCheckSumIndexInput.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+
+public class TestEndiannessReverserCheckSumIndexInput extends EndiannessReverserTestCase {
+
+ @Override
+ protected IndexInput getEndiannessReverserInput(Directory dir, String name, IOContext context)
+ throws IOException {
+ return new EndiannessReverserChecksumIndexInput(dir.openChecksumInput(name, context));
+ }
+
+ @Override
+ protected IndexOutput getEndiannessReverserOutput(Directory dir, String name, IOContext context)
+ throws IOException {
+ return new EndiannessReverserIndexOutput(dir.createOutput(name, context));
+ }
+
+ @Override
+ protected boolean supportSlice() {
+ return false;
+ }
+}
diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/TestEndiannessReverserIndexInput.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/TestEndiannessReverserIndexInput.java
new file mode 100644
index 00000000000..8de2ef9db6e
--- /dev/null
+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/store/TestEndiannessReverserIndexInput.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.backward_codecs.store;
+
+import java.io.IOException;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+
+public class TestEndiannessReverserIndexInput extends EndiannessReverserTestCase {
+
+ @Override
+ protected IndexInput getEndiannessReverserInput(Directory dir, String name, IOContext context)
+ throws IOException {
+ return new EndiannessReverserIndexInput(dir.openInput(name, context));
+ }
+
+ @Override
+ protected IndexOutput getEndiannessReverserOutput(Directory dir, String name, IOContext context)
+ throws IOException {
+ return new EndiannessReverserIndexOutput(dir.createOutput(name, context));
+ }
+
+ @Override
+ protected boolean supportSlice() {
+ return true;
+ }
+}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java b/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
index 3dc46deba5c..a0a3f906260 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/CodecUtil.java
@@ -79,9 +79,9 @@ public final class CodecUtil {
throw new IllegalArgumentException(
"codec must be simple ASCII, less than 128 characters in length [got " + codec + "]");
}
- out.writeInt(CODEC_MAGIC);
+ writeBEInt(out, CODEC_MAGIC);
out.writeString(codec);
- out.writeInt(version);
+ writeBEInt(out, version);
}
/**
@@ -181,7 +181,7 @@ public final class CodecUtil {
public static int checkHeader(DataInput in, String codec, int minVersion, int maxVersion)
throws IOException {
// Safety to guard against reading a bogus string:
- final int actualHeader = in.readInt();
+ final int actualHeader = readBEInt(in);
if (actualHeader != CODEC_MAGIC) {
throw new CorruptIndexException(
"codec header mismatch: actual header="
@@ -205,7 +205,7 @@ public final class CodecUtil {
"codec mismatch: actual codec=" + actualCodec + " vs expected codec=" + codec, in);
}
- final int actualVersion = in.readInt();
+ final int actualVersion = readBEInt(in);
if (actualVersion < minVersion) {
throw new IndexFormatTooOldException(in, actualVersion, minVersion, maxVersion);
}
@@ -281,7 +281,7 @@ public final class CodecUtil {
in);
}
- int actualHeader = in.readInt();
+ int actualHeader = readBEInt(in);
if (actualHeader != CODEC_MAGIC) {
throw new CorruptIndexException(
"compound sub-files must have a valid codec header and footer: codec header mismatch: actual header="
@@ -293,7 +293,7 @@ public final class CodecUtil {
// we can't verify these, so we pass-through:
String codec = in.readString();
- int version = in.readInt();
+ int version = readBEInt(in);
// verify id:
checkIndexHeaderID(in, expectedID);
@@ -304,9 +304,9 @@ public final class CodecUtil {
in.readBytes(suffixBytes, 0, suffixLength);
// now write the header we just verified
- out.writeInt(CodecUtil.CODEC_MAGIC);
+ writeBEInt(out, CodecUtil.CODEC_MAGIC);
out.writeString(codec);
- out.writeInt(version);
+ writeBEInt(out, version);
out.writeBytes(expectedID, 0, expectedID.length);
out.writeByte((byte) suffixLength);
out.writeBytes(suffixBytes, 0, suffixLength);
@@ -318,7 +318,7 @@ public final class CodecUtil {
*/
public static byte[] readIndexHeader(IndexInput in) throws IOException {
in.seek(0);
- final int actualHeader = in.readInt();
+ final int actualHeader = readBEInt(in);
if (actualHeader != CODEC_MAGIC) {
throw new CorruptIndexException(
"codec header mismatch: actual header="
@@ -328,7 +328,7 @@ public final class CodecUtil {
in);
}
String codec = in.readString();
- in.readInt();
+ readBEInt(in);
in.seek(in.getFilePointer() + StringHelper.ID_LENGTH);
int suffixLength = in.readByte() & 0xFF;
byte[] bytes = new byte[headerLength(codec) + StringHelper.ID_LENGTH + 1 + suffixLength];
@@ -406,8 +406,8 @@ public final class CodecUtil {
* @throws IOException If there is an I/O error writing to the underlying medium.
*/
public static void writeFooter(IndexOutput out) throws IOException {
- out.writeInt(FOOTER_MAGIC);
- out.writeInt(0);
+ writeBEInt(out, FOOTER_MAGIC);
+ writeBEInt(out, 0);
writeCRC(out);
}
@@ -574,7 +574,7 @@ public final class CodecUtil {
in);
}
- final int magic = in.readInt();
+ final int magic = readBEInt(in);
if (magic != FOOTER_MAGIC) {
throw new CorruptIndexException(
"codec footer mismatch (file truncated?): actual footer="
@@ -584,7 +584,7 @@ public final class CodecUtil {
in);
}
- final int algorithmID = in.readInt();
+ final int algorithmID = readBEInt(in);
if (algorithmID != 0) {
throw new CorruptIndexException(
"codec footer mismatch: unknown algorithmID: " + algorithmID, in);
@@ -621,7 +621,7 @@ public final class CodecUtil {
* @throws IOException if an i/o error occurs
*/
static long readCRC(IndexInput input) throws IOException {
- long value = input.readLong();
+ long value = readBELong(input);
if ((value & 0xFFFFFFFF00000000L) != 0) {
throw new CorruptIndexException("Illegal CRC-32 checksum: " + value, input);
}
@@ -640,6 +640,33 @@ public final class CodecUtil {
throw new IllegalStateException(
"Illegal CRC-32 checksum: " + value + " (resource=" + output + ")");
}
- output.writeLong(value);
+ writeBELong(output, value);
+ }
+
+ /** write int value on header / footer with big endian order */
+ public static void writeBEInt(DataOutput out, int i) throws IOException {
+ out.writeByte((byte) (i >> 24));
+ out.writeByte((byte) (i >> 16));
+ out.writeByte((byte) (i >> 8));
+ out.writeByte((byte) i);
+ }
+
+ /** write long value on header / footer with big endian order */
+ public static void writeBELong(DataOutput out, long l) throws IOException {
+ writeBEInt(out, (int) (l >> 32));
+ writeBEInt(out, (int) l);
+ }
+
+ /** read int value from header / footer with big endian order */
+ public static int readBEInt(DataInput in) throws IOException {
+ return ((in.readByte() & 0xFF) << 24)
+ | ((in.readByte() & 0xFF) << 16)
+ | ((in.readByte() & 0xFF) << 8)
+ | (in.readByte() & 0xFF);
+ }
+
+ /** read long value from header / footer with big endian order */
+ public static long readBELong(DataInput in) throws IOException {
+ return (((long) readBEInt(in)) << 32) | (readBEInt(in) & 0xFFFFFFFFL);
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/ForUtil.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/ForUtil.java
index bb56e6e497b..a4de8c525ef 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/ForUtil.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/ForUtil.java
@@ -203,10 +203,7 @@ final class ForUtil {
}
for (int i = 0; i < numLongsPerShift; ++i) {
- // Java longs are big endian and we want to read little endian longs, so we need to reverse
- // bytes
- long l = Long.reverseBytes(tmp[i]);
- out.writeLong(l);
+ out.writeLong(tmp[i]);
}
}
@@ -218,7 +215,7 @@ final class ForUtil {
private static void decodeSlow(int bitsPerValue, DataInput in, long[] tmp, long[] longs)
throws IOException {
final int numLongs = bitsPerValue << 1;
- in.readLELongs(tmp, 0, numLongs);
+ in.readLongs(tmp, 0, numLongs);
final long mask = MASKS32[bitsPerValue];
int longsIdx = 0;
int shift = 32 - bitsPerValue;
@@ -528,7 +525,7 @@ final class ForUtil {
}
private static void decode1(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 2);
+ in.readLongs(tmp, 0, 2);
shiftLongs(tmp, 2, longs, 0, 7, MASK8_1);
shiftLongs(tmp, 2, longs, 2, 6, MASK8_1);
shiftLongs(tmp, 2, longs, 4, 5, MASK8_1);
@@ -540,7 +537,7 @@ final class ForUtil {
}
private static void decode2(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 4);
+ in.readLongs(tmp, 0, 4);
shiftLongs(tmp, 4, longs, 0, 6, MASK8_2);
shiftLongs(tmp, 4, longs, 4, 4, MASK8_2);
shiftLongs(tmp, 4, longs, 8, 2, MASK8_2);
@@ -548,7 +545,7 @@ final class ForUtil {
}
private static void decode3(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 6);
+ in.readLongs(tmp, 0, 6);
shiftLongs(tmp, 6, longs, 0, 5, MASK8_3);
shiftLongs(tmp, 6, longs, 6, 2, MASK8_3);
for (int iter = 0, tmpIdx = 0, longsIdx = 12; iter < 2; ++iter, tmpIdx += 3, longsIdx += 2) {
@@ -562,13 +559,13 @@ final class ForUtil {
}
private static void decode4(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 8);
+ in.readLongs(tmp, 0, 8);
shiftLongs(tmp, 8, longs, 0, 4, MASK8_4);
shiftLongs(tmp, 8, longs, 8, 0, MASK8_4);
}
private static void decode5(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 10);
+ in.readLongs(tmp, 0, 10);
shiftLongs(tmp, 10, longs, 0, 3, MASK8_5);
for (int iter = 0, tmpIdx = 0, longsIdx = 10; iter < 2; ++iter, tmpIdx += 5, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK8_3) << 2;
@@ -585,7 +582,7 @@ final class ForUtil {
}
private static void decode6(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 12);
+ in.readLongs(tmp, 0, 12);
shiftLongs(tmp, 12, longs, 0, 2, MASK8_6);
shiftLongs(tmp, 12, tmp, 0, 0, MASK8_2);
for (int iter = 0, tmpIdx = 0, longsIdx = 12; iter < 4; ++iter, tmpIdx += 3, longsIdx += 1) {
@@ -597,7 +594,7 @@ final class ForUtil {
}
private static void decode7(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 14);
+ in.readLongs(tmp, 0, 14);
shiftLongs(tmp, 14, longs, 0, 1, MASK8_7);
shiftLongs(tmp, 14, tmp, 0, 0, MASK8_1);
for (int iter = 0, tmpIdx = 0, longsIdx = 14; iter < 2; ++iter, tmpIdx += 7, longsIdx += 1) {
@@ -613,11 +610,11 @@ final class ForUtil {
}
private static void decode8(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(longs, 0, 16);
+ in.readLongs(longs, 0, 16);
}
private static void decode9(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 18);
+ in.readLongs(tmp, 0, 18);
shiftLongs(tmp, 18, longs, 0, 7, MASK16_9);
for (int iter = 0, tmpIdx = 0, longsIdx = 18; iter < 2; ++iter, tmpIdx += 9, longsIdx += 7) {
long l0 = (tmp[tmpIdx + 0] & MASK16_7) << 2;
@@ -646,7 +643,7 @@ final class ForUtil {
}
private static void decode10(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 20);
+ in.readLongs(tmp, 0, 20);
shiftLongs(tmp, 20, longs, 0, 6, MASK16_10);
for (int iter = 0, tmpIdx = 0, longsIdx = 20; iter < 4; ++iter, tmpIdx += 5, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK16_6) << 4;
@@ -663,7 +660,7 @@ final class ForUtil {
}
private static void decode11(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 22);
+ in.readLongs(tmp, 0, 22);
shiftLongs(tmp, 22, longs, 0, 5, MASK16_11);
for (int iter = 0, tmpIdx = 0, longsIdx = 22; iter < 2; ++iter, tmpIdx += 11, longsIdx += 5) {
long l0 = (tmp[tmpIdx + 0] & MASK16_5) << 6;
@@ -690,7 +687,7 @@ final class ForUtil {
}
private static void decode12(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 24);
+ in.readLongs(tmp, 0, 24);
shiftLongs(tmp, 24, longs, 0, 4, MASK16_12);
shiftLongs(tmp, 24, tmp, 0, 0, MASK16_4);
for (int iter = 0, tmpIdx = 0, longsIdx = 24; iter < 8; ++iter, tmpIdx += 3, longsIdx += 1) {
@@ -702,7 +699,7 @@ final class ForUtil {
}
private static void decode13(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 26);
+ in.readLongs(tmp, 0, 26);
shiftLongs(tmp, 26, longs, 0, 3, MASK16_13);
for (int iter = 0, tmpIdx = 0, longsIdx = 26; iter < 2; ++iter, tmpIdx += 13, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK16_3) << 10;
@@ -727,7 +724,7 @@ final class ForUtil {
}
private static void decode14(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 28);
+ in.readLongs(tmp, 0, 28);
shiftLongs(tmp, 28, longs, 0, 2, MASK16_14);
shiftLongs(tmp, 28, tmp, 0, 0, MASK16_2);
for (int iter = 0, tmpIdx = 0, longsIdx = 28; iter < 4; ++iter, tmpIdx += 7, longsIdx += 1) {
@@ -743,7 +740,7 @@ final class ForUtil {
}
private static void decode15(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 30);
+ in.readLongs(tmp, 0, 30);
shiftLongs(tmp, 30, longs, 0, 1, MASK16_15);
shiftLongs(tmp, 30, tmp, 0, 0, MASK16_1);
for (int iter = 0, tmpIdx = 0, longsIdx = 30; iter < 2; ++iter, tmpIdx += 15, longsIdx += 1) {
@@ -767,11 +764,11 @@ final class ForUtil {
}
private static void decode16(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(longs, 0, 32);
+ in.readLongs(longs, 0, 32);
}
private static void decode17(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 34);
+ in.readLongs(tmp, 0, 34);
shiftLongs(tmp, 34, longs, 0, 15, MASK32_17);
for (int iter = 0, tmpIdx = 0, longsIdx = 34; iter < 2; ++iter, tmpIdx += 17, longsIdx += 15) {
long l0 = (tmp[tmpIdx + 0] & MASK32_15) << 2;
@@ -824,7 +821,7 @@ final class ForUtil {
}
private static void decode18(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 36);
+ in.readLongs(tmp, 0, 36);
shiftLongs(tmp, 36, longs, 0, 14, MASK32_18);
for (int iter = 0, tmpIdx = 0, longsIdx = 36; iter < 4; ++iter, tmpIdx += 9, longsIdx += 7) {
long l0 = (tmp[tmpIdx + 0] & MASK32_14) << 4;
@@ -853,7 +850,7 @@ final class ForUtil {
}
private static void decode19(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 38);
+ in.readLongs(tmp, 0, 38);
shiftLongs(tmp, 38, longs, 0, 13, MASK32_19);
for (int iter = 0, tmpIdx = 0, longsIdx = 38; iter < 2; ++iter, tmpIdx += 19, longsIdx += 13) {
long l0 = (tmp[tmpIdx + 0] & MASK32_13) << 6;
@@ -904,7 +901,7 @@ final class ForUtil {
}
private static void decode20(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 40);
+ in.readLongs(tmp, 0, 40);
shiftLongs(tmp, 40, longs, 0, 12, MASK32_20);
for (int iter = 0, tmpIdx = 0, longsIdx = 40; iter < 8; ++iter, tmpIdx += 5, longsIdx += 3) {
long l0 = (tmp[tmpIdx + 0] & MASK32_12) << 8;
@@ -921,7 +918,7 @@ final class ForUtil {
}
private static void decode21(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 42);
+ in.readLongs(tmp, 0, 42);
shiftLongs(tmp, 42, longs, 0, 11, MASK32_21);
for (int iter = 0, tmpIdx = 0, longsIdx = 42; iter < 2; ++iter, tmpIdx += 21, longsIdx += 11) {
long l0 = (tmp[tmpIdx + 0] & MASK32_11) << 10;
@@ -970,7 +967,7 @@ final class ForUtil {
}
private static void decode22(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 44);
+ in.readLongs(tmp, 0, 44);
shiftLongs(tmp, 44, longs, 0, 10, MASK32_22);
for (int iter = 0, tmpIdx = 0, longsIdx = 44; iter < 4; ++iter, tmpIdx += 11, longsIdx += 5) {
long l0 = (tmp[tmpIdx + 0] & MASK32_10) << 12;
@@ -997,7 +994,7 @@ final class ForUtil {
}
private static void decode23(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 46);
+ in.readLongs(tmp, 0, 46);
shiftLongs(tmp, 46, longs, 0, 9, MASK32_23);
for (int iter = 0, tmpIdx = 0, longsIdx = 46; iter < 2; ++iter, tmpIdx += 23, longsIdx += 9) {
long l0 = (tmp[tmpIdx + 0] & MASK32_9) << 14;
@@ -1044,7 +1041,7 @@ final class ForUtil {
}
private static void decode24(DataInput in, long[] tmp, long[] longs) throws IOException {
- in.readLELongs(tmp, 0, 48);
+ in.readLongs(tmp, 0, 48);
shiftLongs(tmp, 48, longs, 0, 8, MASK32_24);
shiftLongs(tmp, 48, tmp, 0, 0, MASK32_8);
for (int iter = 0, tmpIdx = 0, longsIdx = 48; iter < 16; ++iter, tmpIdx += 3, longsIdx += 1) {
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundFormat.java
index d06802c8954..f37b669e0ea 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundFormat.java
@@ -123,9 +123,9 @@ public final class Lucene90CompoundFormat extends CompoundFormat {
// this is poached from CodecUtil.writeFooter, but we need to use our own checksum, not
// data.getChecksum(), but I think
// adding a public method to CodecUtil to do that is somewhat dangerous:
- data.writeInt(CodecUtil.FOOTER_MAGIC);
- data.writeInt(0);
- data.writeLong(checksum);
+ CodecUtil.writeBEInt(data, CodecUtil.FOOTER_MAGIC);
+ CodecUtil.writeBEInt(data, 0);
+ CodecUtil.writeBELong(data, checksum);
}
long endOffset = data.getFilePointer();
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorReader.java
index d630921ee57..b2776afe83e 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90HnswVectorReader.java
@@ -397,7 +397,7 @@ public final class Lucene90HnswVectorReader extends VectorReader {
@Override
public float[] vectorValue() throws IOException {
dataIn.seek((long) ord * byteSize);
- dataIn.readLEFloats(value, 0, value.length);
+ dataIn.readFloats(value, 0, value.length);
return value;
}
@@ -452,7 +452,7 @@ public final class Lucene90HnswVectorReader extends VectorReader {
@Override
public float[] vectorValue(int targetOrd) throws IOException {
dataIn.seek((long) targetOrd * byteSize);
- dataIn.readLEFloats(value, 0, value.length);
+ dataIn.readFloats(value, 0, value.length);
return value;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/StoredFieldsInts.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/StoredFieldsInts.java
index 60a4a48bf83..1ed28c22b13 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/StoredFieldsInts.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/compressing/StoredFieldsInts.java
@@ -72,7 +72,7 @@ class StoredFieldsInts {
| ((long) values[step + 80 + i] << 16)
| ((long) values[step + 96 + i] << 8)
| (long) values[step + 112 + i];
- out.writeLong(Long.reverseBytes(l));
+ out.writeLong(l);
}
}
for (; k < count; k++) {
@@ -91,7 +91,7 @@ class StoredFieldsInts {
| ((long) values[step + 32 + i] << 32)
| ((long) values[step + 64 + i] << 16)
| (long) values[step + 96 + i];
- out.writeLong(Long.reverseBytes(l));
+ out.writeLong(l);
}
}
for (; k < count; k++) {
@@ -106,7 +106,7 @@ class StoredFieldsInts {
int step = offset + k;
for (int i = 0; i < 64; ++i) {
long l = ((long) values[step + i] << 32) | (long) values[step + 64 + i];
- out.writeLong(Long.reverseBytes(l));
+ out.writeLong(l);
}
}
for (; k < count; k++) {
@@ -140,7 +140,7 @@ class StoredFieldsInts {
int k = 0;
for (; k < count - BLOCK_SIZE_MINUS_ONE; k += BLOCK_SIZE) {
final int step = offset + k;
- in.readLELongs(values, step, 16);
+ in.readLongs(values, step, 16);
for (int i = 0; i < 16; ++i) {
final long l = values[step + i];
values[step + i] = (l >>> 56) & 0xFFL;
@@ -163,7 +163,7 @@ class StoredFieldsInts {
int k = 0;
for (; k < count - BLOCK_SIZE_MINUS_ONE; k += BLOCK_SIZE) {
int step = offset + k;
- in.readLELongs(values, step, 32);
+ in.readLongs(values, step, 32);
for (int i = 0; i < 32; ++i) {
final long l = values[step + i];
values[step + i] = (l >>> 48) & 0xFFFFL;
@@ -182,7 +182,7 @@ class StoredFieldsInts {
int k = 0;
for (; k < count - BLOCK_SIZE_MINUS_ONE; k += BLOCK_SIZE) {
final int step = offset + k;
- in.readLELongs(values, step, 64);
+ in.readLongs(values, step, 64);
for (int i = 0; i < 64; ++i) {
final long l = values[step + i];
values[step + i] = l >>> 32;
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/gen_ForUtil.py b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/gen_ForUtil.py
index dd828c955d0..9f4b03ab39b 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/gen_ForUtil.py
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/gen_ForUtil.py
@@ -229,7 +229,7 @@ final class ForUtil {
for (int i = 0; i < numLongsPerShift; ++i) {
// Java longs are big endian and we want to read little endian longs, so we need to reverse
// bytes
- long l = Long.reverseBytes(tmp[i]);
+ long l = tmp[i];
out.writeLong(l);
}
}
@@ -242,7 +242,7 @@ final class ForUtil {
private static void decodeSlow(int bitsPerValue, DataInput in, long[] tmp, long[] longs)
throws IOException {
final int numLongs = bitsPerValue << 1;
- in.readLELongs(tmp, 0, numLongs);
+ in.readLongs(tmp, 0, numLongs);
final long mask = MASKS32[bitsPerValue];
int longsIdx = 0;
int shift = 32 - bitsPerValue;
@@ -346,9 +346,9 @@ def writeDecode(bpv, f):
f.write(' private static void decode%d(DataInput in, long[] tmp, long[] longs) throws IOException {\n' %bpv)
num_values_per_long = 64 / next_primitive
if bpv == next_primitive:
- f.write(' in.readLELongs(longs, 0, %d);\n' %(bpv*2))
+ f.write(' in.readLongs(longs, 0, %d);\n' %(bpv*2))
else:
- f.write(' in.readLELongs(tmp, 0, %d);\n' %(bpv*2))
+ f.write(' in.readLongs(tmp, 0, %d);\n' %(bpv*2))
shift = next_primitive - bpv
o = 0
while shift >= 0:
diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
index 7e7d7cb10c5..3933bd5a51a 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java
@@ -319,7 +319,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
try {
// NOTE: as long as we want to throw indexformattooold (vs corruptindexexception), we need
// to read the magic ourselves.
- int magic = input.readInt();
+ int magic = CodecUtil.readBEInt(input);
if (magic != CodecUtil.CODEC_MAGIC) {
throw new IndexFormatTooOldException(
input, magic, CodecUtil.CODEC_MAGIC, CodecUtil.CODEC_MAGIC);
@@ -377,14 +377,14 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
private static void parseSegmentInfos(
Directory directory, DataInput input, SegmentInfos infos, int format) throws IOException {
- infos.version = input.readLong();
+ infos.version = CodecUtil.readBELong(input);
// System.out.println("READ sis version=" + infos.version);
if (format > VERSION_70) {
infos.counter = input.readVLong();
} else {
- infos.counter = input.readInt();
+ infos.counter = CodecUtil.readBEInt(input);
}
- int numSegments = input.readInt();
+ int numSegments = CodecUtil.readBEInt(input);
if (numSegments < 0) {
throw new CorruptIndexException("invalid segment count: " + numSegments, input);
}
@@ -406,15 +406,15 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
codec.segmentInfoFormat().read(directory, segName, segmentID, IOContext.READ);
info.setCodec(codec);
totalDocs += info.maxDoc();
- long delGen = input.readLong();
- int delCount = input.readInt();
+ long delGen = CodecUtil.readBELong(input);
+ int delCount = CodecUtil.readBEInt(input);
if (delCount < 0 || delCount > info.maxDoc()) {
throw new CorruptIndexException(
"invalid deletion count: " + delCount + " vs maxDoc=" + info.maxDoc(), input);
}
- long fieldInfosGen = input.readLong();
- long dvGen = input.readLong();
- int softDelCount = format > VERSION_72 ? input.readInt() : 0;
+ long fieldInfosGen = CodecUtil.readBELong(input);
+ long dvGen = CodecUtil.readBELong(input);
+ int softDelCount = format > VERSION_72 ? CodecUtil.readBEInt(input) : 0;
if (softDelCount < 0 || softDelCount > info.maxDoc()) {
throw new CorruptIndexException(
"invalid deletion count: " + softDelCount + " vs maxDoc=" + info.maxDoc(), input);
@@ -446,13 +446,13 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
new SegmentCommitInfo(info, delCount, softDelCount, delGen, fieldInfosGen, dvGen, sciId);
siPerCommit.setFieldInfosFiles(input.readSetOfStrings());
final Map<Integer, Set<String>> dvUpdateFiles;
- final int numDVFields = input.readInt();
+ final int numDVFields = CodecUtil.readBEInt(input);
if (numDVFields == 0) {
dvUpdateFiles = Collections.emptyMap();
} else {
Map<Integer, Set<String>> map = new HashMap<>(numDVFields);
for (int i = 0; i < numDVFields; i++) {
- map.put(input.readInt(), input.readSetOfStrings());
+ map.put(CodecUtil.readBEInt(input), input.readSetOfStrings());
}
dvUpdateFiles = Collections.unmodifiableMap(map);
}
@@ -589,9 +589,9 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
out.writeVInt(indexCreatedVersionMajor);
- out.writeLong(version);
+ CodecUtil.writeBELong(out, version);
out.writeVLong(counter); // write counter
- out.writeInt(size());
+ CodecUtil.writeBEInt(out, size());
if (size() > 0) {
@@ -630,7 +630,8 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
}
out.writeBytes(segmentID, segmentID.length);
out.writeString(si.getCodec().getName());
- out.writeLong(siPerCommit.getDelGen());
+
+ CodecUtil.writeBELong(out, siPerCommit.getDelGen());
int delCount = siPerCommit.getDelCount();
if (delCount < 0 || delCount > si.maxDoc()) {
throw new IllegalStateException(
@@ -641,9 +642,9 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
+ " delCount="
+ delCount);
}
- out.writeInt(delCount);
- out.writeLong(siPerCommit.getFieldInfosGen());
- out.writeLong(siPerCommit.getDocValuesGen());
+ CodecUtil.writeBEInt(out, delCount);
+ CodecUtil.writeBELong(out, siPerCommit.getFieldInfosGen());
+ CodecUtil.writeBELong(out, siPerCommit.getDocValuesGen());
int softDelCount = siPerCommit.getSoftDelCount();
if (softDelCount < 0 || softDelCount > si.maxDoc()) {
throw new IllegalStateException(
@@ -654,7 +655,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
+ " softDelCount="
+ softDelCount);
}
- out.writeInt(softDelCount);
+ CodecUtil.writeBEInt(out, softDelCount);
// we ensure that there is a valid ID for this SCI just in case
// this is manually upgraded outside of IW
byte[] sciId = siPerCommit.getId();
@@ -669,9 +670,9 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfo
out.writeSetOfStrings(siPerCommit.getFieldInfosFiles());
final Map<Integer, Set<String>> dvUpdatesFiles = siPerCommit.getDocValuesUpdatesFiles();
- out.writeInt(dvUpdatesFiles.size());
+ CodecUtil.writeBEInt(out, dvUpdatesFiles.size());
for (Entry<Integer, Set<String>> e : dvUpdatesFiles.entrySet()) {
- out.writeInt(e.getKey());
+ CodecUtil.writeBEInt(out, e.getKey());
out.writeSetOfStrings(e.getValue());
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java
index 6b55152055b..974ad0c6874 100644
--- a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java
@@ -24,7 +24,9 @@ import java.nio.ByteOrder;
/** Base implementation class for buffered {@link IndexInput}. */
public abstract class BufferedIndexInput extends IndexInput implements RandomAccessInput {
- private static final ByteBuffer EMPTY_BYTEBUFFER = ByteBuffer.allocate(0);
+ private static final ByteBuffer EMPTY_BYTEBUFFER =
+ ByteBuffer.allocate(0).order(ByteOrder.LITTLE_ENDIAN);
+ ;
/** Default buffer size set to {@value #BUFFER_SIZE}. */
public static final int BUFFER_SIZE = 1024;
@@ -279,7 +281,8 @@ public abstract class BufferedIndexInput extends IndexInput implements RandomAcc
if (newLength <= 0) throw new EOFException("read past EOF: " + this);
if (buffer == EMPTY_BYTEBUFFER) {
- buffer = ByteBuffer.allocate(bufferSize); // allocate buffer lazily
+ buffer =
+ ByteBuffer.allocate(bufferSize).order(ByteOrder.LITTLE_ENDIAN); // allocate buffer lazily
seekInternal(bufferStart);
}
buffer.position(0);
@@ -287,7 +290,7 @@ public abstract class BufferedIndexInput extends IndexInput implements RandomAcc
bufferStart = start;
readInternal(buffer);
// Make sure sub classes don't mess up with the buffer.
- assert buffer.order() == ByteOrder.BIG_ENDIAN : buffer.order();
+ assert buffer.order() == ByteOrder.LITTLE_ENDIAN : buffer.order();
assert buffer.remaining() == 0 : "should have thrown EOFException";
assert buffer.position() == newLength;
buffer.flip();
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java
index c51c3989c4b..31c5e231fb4 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java
@@ -81,30 +81,38 @@ public final class ByteArrayDataInput extends DataInput {
@Override
public short readShort() {
- return (short) (((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF));
+ final byte b1 = bytes[pos++];
+ final byte b2 = bytes[pos++];
+ return (short) ((b2 & 0xFF) << 8 | (b1 & 0xFF));
}
@Override
public int readInt() {
- return ((bytes[pos++] & 0xFF) << 24)
- | ((bytes[pos++] & 0xFF) << 16)
- | ((bytes[pos++] & 0xFF) << 8)
- | (bytes[pos++] & 0xFF);
+ final byte b1 = bytes[pos++];
+ final byte b2 = bytes[pos++];
+ final byte b3 = bytes[pos++];
+ final byte b4 = bytes[pos++];
+ return (b4 & 0xFF) << 24 | (b3 & 0xFF) << 16 | (b2 & 0xFF) << 8 | (b1 & 0xFF);
}
@Override
public long readLong() {
- final int i1 =
- ((bytes[pos++] & 0xff) << 24)
- | ((bytes[pos++] & 0xff) << 16)
- | ((bytes[pos++] & 0xff) << 8)
- | (bytes[pos++] & 0xff);
- final int i2 =
- ((bytes[pos++] & 0xff) << 24)
- | ((bytes[pos++] & 0xff) << 16)
- | ((bytes[pos++] & 0xff) << 8)
- | (bytes[pos++] & 0xff);
- return (((long) i1) << 32) | (i2 & 0xFFFFFFFFL);
+ final byte b1 = bytes[pos++];
+ final byte b2 = bytes[pos++];
+ final byte b3 = bytes[pos++];
+ final byte b4 = bytes[pos++];
+ final byte b5 = bytes[pos++];
+ final byte b6 = bytes[pos++];
+ final byte b7 = bytes[pos++];
+ final byte b8 = bytes[pos++];
+ return (b8 & 0xFFL) << 56
+ | (b7 & 0xFFL) << 48
+ | (b6 & 0xFFL) << 40
+ | (b5 & 0xFFL) << 32
+ | (b4 & 0xFFL) << 24
+ | (b3 & 0xFFL) << 16
+ | (b2 & 0xFFL) << 8
+ | (b1 & 0xFFL);
}
@Override
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java
index 0afc57c9e98..cb7d5230ba4 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBufferIndexInput.java
@@ -137,7 +137,7 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
}
@Override
- public void readLELongs(long[] dst, int offset, int length) throws IOException {
+ public void readLongs(long[] dst, int offset, int length) throws IOException {
// ByteBuffer#getLong could work but it has some per-long overhead and there
// is no ByteBuffer#getLongs to read multiple longs at once. So we use the
// below trick in order to be able to leverage LongBuffer#get(long[]) to
@@ -168,7 +168,7 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
} catch (
@SuppressWarnings("unused")
BufferUnderflowException e) {
- super.readLELongs(dst, offset, length);
+ super.readLongs(dst, offset, length);
} catch (
@SuppressWarnings("unused")
NullPointerException npe) {
@@ -177,8 +177,8 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
}
@Override
- public final void readLEFloats(float[] floats, int offset, int len) throws IOException {
- // See notes about readELongs above
+ public final void readFloats(float[] floats, int offset, int len) throws IOException {
+ // See notes about readLongs above
if (curFloatBufferViews == null) {
curFloatBufferViews = new FloatBuffer[Float.BYTES];
for (int i = 0; i < Float.BYTES; ++i) {
@@ -202,7 +202,7 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
} catch (
@SuppressWarnings("unused")
BufferUnderflowException e) {
- super.readLEFloats(floats, offset, len);
+ super.readFloats(floats, offset, len);
} catch (
@SuppressWarnings("unused")
NullPointerException npe) {
@@ -445,7 +445,11 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
if (newBuffers.length == 1) {
newBuffers[0].position(offset);
return new SingleBufferImpl(
- newResourceDescription, newBuffers[0].slice(), length, chunkSizePower, this.guard);
+ newResourceDescription,
+ newBuffers[0].slice().order(ByteOrder.LITTLE_ENDIAN),
+ length,
+ chunkSizePower,
+ this.guard);
} else {
return new MultiBufferImpl(
newResourceDescription, newBuffers, offset, length, chunkSizePower, guard);
@@ -466,7 +470,7 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
final ByteBuffer slices[] = new ByteBuffer[endIndex - startIndex + 1];
for (int i = 0; i < slices.length; i++) {
- slices[i] = buffers[startIndex + i].duplicate();
+ slices[i] = buffers[startIndex + i].duplicate().order(ByteOrder.LITTLE_ENDIAN);
}
// set the last buffer's limit for the sliced view.
@@ -512,6 +516,7 @@ public abstract class ByteBufferIndexInput extends IndexInput implements RandomA
ByteBufferGuard guard) {
super(resourceDescription, new ByteBuffer[] {buffer}, length, chunkSizePower, guard);
this.curBufIndex = 0;
+ assert buffer.order() == ByteOrder.LITTLE_ENDIAN;
setCurBuf(buffer);
buffer.position(0);
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java
index b6572f6ee1b..63c5fd3d386 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataInput.java
@@ -53,7 +53,10 @@ public final class ByteBuffersDataInput extends DataInput
public ByteBuffersDataInput(List<ByteBuffer> buffers) {
ensureAssumptions(buffers);
- this.blocks = buffers.stream().map(buf -> buf.asReadOnlyBuffer()).toArray(ByteBuffer[]::new);
+ this.blocks =
+ buffers.stream()
+ .map(buf -> buf.asReadOnlyBuffer().order(ByteOrder.LITTLE_ENDIAN))
+ .toArray(ByteBuffer[]::new);
// pre-allocate this array and create the FloatBuffers lazily
this.floatBuffers = new FloatBuffer[blocks.length * Float.BYTES];
if (blocks.length == 1) {
@@ -173,7 +176,7 @@ public final class ByteBuffersDataInput extends DataInput
if (blockOffset + Short.BYTES <= blockMask) {
return blocks[blockIndex(absPos)].getShort(blockOffset);
} else {
- return (short) ((readByte(pos) & 0xFF) << 8 | (readByte(pos + 1) & 0xFF));
+ return (short) ((readByte(pos) & 0xFF) | (readByte(pos + 1) & 0xFF) << 8);
}
}
@@ -184,10 +187,10 @@ public final class ByteBuffersDataInput extends DataInput
if (blockOffset + Integer.BYTES <= blockMask) {
return blocks[blockIndex(absPos)].getInt(blockOffset);
} else {
- return ((readByte(pos)) << 24
- | (readByte(pos + 1) & 0xFF) << 16
- | (readByte(pos + 2) & 0xFF) << 8
- | (readByte(pos + 3) & 0xFF));
+ return ((readByte(pos) & 0xFF)
+ | (readByte(pos + 1) & 0xFF) << 8
+ | (readByte(pos + 2) & 0xFF) << 16
+ | (readByte(pos + 3) << 24));
}
}
@@ -198,12 +201,27 @@ public final class ByteBuffersDataInput extends DataInput
if (blockOffset + Long.BYTES <= blockMask) {
return blocks[blockIndex(absPos)].getLong(blockOffset);
} else {
- return (((long) readInt(pos)) << 32) | (readInt(pos + 4) & 0xFFFFFFFFL);
+ final byte b1 = readByte(pos);
+ final byte b2 = readByte(pos + 1);
+ final byte b3 = readByte(pos + 2);
+ final byte b4 = readByte(pos + 3);
+ final byte b5 = readByte(pos + 4);
+ final byte b6 = readByte(pos + 5);
+ final byte b7 = readByte(pos + 6);
+ final byte b8 = readByte(pos + 7);
+ return (b8 & 0xFFL) << 56
+ | (b7 & 0xFFL) << 48
+ | (b6 & 0xFFL) << 40
+ | (b5 & 0xFFL) << 32
+ | (b4 & 0xFFL) << 24
+ | (b3 & 0xFFL) << 16
+ | (b2 & 0xFFL) << 8
+ | (b1 & 0xFFL);
}
}
@Override
- public void readLEFloats(float[] arr, int off, int len) throws EOFException {
+ public void readFloats(float[] arr, int off, int len) throws EOFException {
try {
while (len > 0) {
FloatBuffer floatBuffer = getFloatBuffer(pos);
@@ -211,7 +229,7 @@ public final class ByteBuffersDataInput extends DataInput
int chunk = Math.min(len, floatBuffer.remaining());
if (chunk == 0) {
// read a single float spanning the boundary between two buffers
- arr[off] = Float.intBitsToFloat(Integer.reverseBytes(readInt(pos - offset)));
+ arr[off] = Float.intBitsToFloat(readInt(pos - offset));
off++;
len--;
pos += Float.BYTES;
@@ -354,7 +372,8 @@ public final class ByteBuffersDataInput extends DataInput
ensureAssumptions(buffers);
if (buffers.size() == 1) {
- ByteBuffer cloned = buffers.get(0).asReadOnlyBuffer();
+ ByteBuffer cloned = buffers.get(0).asReadOnlyBuffer().order(ByteOrder.LITTLE_ENDIAN);
+ ;
cloned.position(Math.toIntExact(cloned.position() + offset));
cloned.limit(Math.toIntExact(cloned.position() + length));
return Arrays.asList(cloned);
@@ -374,11 +393,11 @@ public final class ByteBuffersDataInput extends DataInput
Math.toIntExact(absStart / blockBytes),
Math.toIntExact(absEnd / blockBytes + (endOffset == 0 ? 0 : 1)))
.stream()
- .map(buf -> buf.asReadOnlyBuffer())
+ .map(buf -> buf.asReadOnlyBuffer().order(ByteOrder.LITTLE_ENDIAN))
.collect(Collectors.toCollection(ArrayList::new));
if (endOffset == 0) {
- cloned.add(ByteBuffer.allocate(0));
+ cloned.add(ByteBuffer.allocate(0).order(ByteOrder.LITTLE_ENDIAN));
}
cloned.get(0).position(Math.toIntExact(absStart & blockMask));
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java
index 4fd5a7f1ec8..c76c848a354 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDataOutput.java
@@ -19,6 +19,7 @@ package org.apache.lucene.store;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
@@ -37,7 +38,8 @@ import org.apache.lucene.util.UnicodeUtil;
/** A {@link DataOutput} storing data in a list of {@link ByteBuffer}s. */
public final class ByteBuffersDataOutput extends DataOutput implements Accountable {
- private static final ByteBuffer EMPTY = ByteBuffer.allocate(0);
+ private static final ByteBuffer EMPTY = ByteBuffer.allocate(0).order(ByteOrder.LITTLE_ENDIAN);
+ ;
private static final byte[] EMPTY_BYTE_ARRAY = {};
public static final IntFunction<ByteBuffer> ALLOCATE_BB_ON_HEAP = ByteBuffer::allocate;
@@ -193,7 +195,8 @@ public final class ByteBuffersDataOutput extends DataOutput implements Accountab
result.add(EMPTY);
} else {
for (ByteBuffer bb : blocks) {
- bb = bb.asReadOnlyBuffer().flip();
+ bb = bb.asReadOnlyBuffer().flip().order(ByteOrder.LITTLE_ENDIAN);
+ ;
result.add(bb);
}
}
@@ -433,7 +436,8 @@ public final class ByteBuffersDataOutput extends DataOutput implements Accountab
}
final int requiredBlockSize = 1 << blockBits;
- currentBlock = blockAllocate.apply(requiredBlockSize);
+ currentBlock = blockAllocate.apply(requiredBlockSize).order(ByteOrder.LITTLE_ENDIAN);
+ ;
assert currentBlock.capacity() == requiredBlockSize;
blocks.add(currentBlock);
ramBytesUsed += RamUsageEstimator.NUM_BYTES_OBJECT_REF + currentBlock.capacity();
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
index 8358c2979a9..1b65ffa43b7 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersDirectory.java
@@ -18,6 +18,7 @@ package org.apache.lucene.store;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.file.AccessDeniedException;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.NoSuchFileException;
@@ -65,7 +66,9 @@ public final class ByteBuffersDirectory extends BaseDirectory {
public static final BiFunction<String, ByteBuffersDataOutput, IndexInput> OUTPUT_AS_ONE_BUFFER =
(fileName, output) -> {
ByteBuffersDataInput dataInput =
- new ByteBuffersDataInput(Arrays.asList(ByteBuffer.wrap(output.toArrayCopy())));
+ new ByteBuffersDataInput(
+ Arrays.asList(
+ ByteBuffer.wrap(output.toArrayCopy()).order(ByteOrder.LITTLE_ENDIAN)));
String inputName =
String.format(
Locale.ROOT,
@@ -83,7 +86,7 @@ public final class ByteBuffersDirectory extends BaseDirectory {
OUTPUT_AS_MANY_BUFFERS_LUCENE =
(fileName, output) -> {
List<ByteBuffer> bufferList = output.toBufferList();
- bufferList.add(ByteBuffer.allocate(0));
+ bufferList.add(ByteBuffer.allocate(0).order(ByteOrder.LITTLE_ENDIAN));
int chunkSizePower;
int blockSize = ByteBuffersDataInput.determineBlockPage(bufferList);
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexInput.java
index 7a662110352..ad91fb4d0ea 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBuffersIndexInput.java
@@ -188,9 +188,9 @@ public final class ByteBuffersIndexInput extends IndexInput implements RandomAcc
}
@Override
- public void readLEFloats(float[] floats, int offset, int len) throws IOException {
+ public void readFloats(float[] floats, int offset, int len) throws IOException {
ensureOpen();
- in.readLEFloats(floats, offset, len);
+ in.readFloats(floats, offset, len);
}
@Override
diff --git a/lucene/core/src/java/org/apache/lucene/store/DataInput.java b/lucene/core/src/java/org/apache/lucene/store/DataInput.java
index b10b4c6aab3..6a65c085e98 100644
--- a/lucene/core/src/java/org/apache/lucene/store/DataInput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/DataInput.java
@@ -90,7 +90,9 @@ public abstract class DataInput implements Cloneable {
* @see DataOutput#writeByte(byte)
*/
public short readShort() throws IOException {
- return (short) (((readByte() & 0xFF) << 8) | (readByte() & 0xFF));
+ final byte b1 = readByte();
+ final byte b2 = readByte();
+ return (short) (((b2 & 0xFF) << 8) | (b1 & 0xFF));
}
/**
@@ -99,10 +101,11 @@ public abstract class DataInput implements Cloneable {
* @see DataOutput#writeInt(int)
*/
public int readInt() throws IOException {
- return ((readByte() & 0xFF) << 24)
- | ((readByte() & 0xFF) << 16)
- | ((readByte() & 0xFF) << 8)
- | (readByte() & 0xFF);
+ final byte b1 = readByte();
+ final byte b2 = readByte();
+ final byte b3 = readByte();
+ final byte b4 = readByte();
+ return ((b4 & 0xFF) << 24) | ((b3 & 0xFF) << 16) | ((b2 & 0xFF) << 8) | (b1 & 0xFF);
}
/**
@@ -160,29 +163,18 @@ public abstract class DataInput implements Cloneable {
* @see DataOutput#writeLong(long)
*/
public long readLong() throws IOException {
- return (((long) readInt()) << 32) | (readInt() & 0xFFFFFFFFL);
+ return (readInt() & 0xFFFFFFFFL) | (((long) readInt()) << 32);
}
/**
- * Read a specified number of longs with the little endian byte order.
- *
- * <p>This method can be used to read longs whose bytes have been {@link Long#reverseBytes
- * reversed} at write time:
- *
- * <pre class="prettyprint">
- * for (long l : longs) {
- * output.writeLong(Long.reverseBytes(l));
- * }
- * </pre>
+ * Read a specified number of longs.
*
* @lucene.experimental
*/
- // TODO: LUCENE-9047: Make the entire DataInput/DataOutput API little endian
- // Then this would just be `readLongs`?
- public void readLELongs(long[] dst, int offset, int length) throws IOException {
+ public void readLongs(long[] dst, int offset, int length) throws IOException {
Objects.checkFromIndexSize(offset, length, dst.length);
for (int i = 0; i < length; ++i) {
- dst[offset + i] = Long.reverseBytes(readLong());
+ dst[offset + i] = readLong();
}
}
@@ -193,10 +185,10 @@ public abstract class DataInput implements Cloneable {
* @param offset the offset in the array to start storing floats
* @param len the number of floats to read
*/
- public void readLEFloats(float[] floats, int offset, int len) throws IOException {
+ public void readFloats(float[] floats, int offset, int len) throws IOException {
Objects.checkFromIndexSize(offset, len, floats.length);
for (int i = 0; i < len; i++) {
- floats[offset + i] = Float.intBitsToFloat(Integer.reverseBytes(readInt()));
+ floats[offset + i] = Float.intBitsToFloat(readInt());
}
}
diff --git a/lucene/core/src/java/org/apache/lucene/store/DataOutput.java b/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
index 6ea722d2e98..d7a85a8c197 100644
--- a/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
@@ -70,10 +70,10 @@ public abstract class DataOutput {
* @see DataInput#readInt()
*/
public void writeInt(int i) throws IOException {
- writeByte((byte) (i >> 24));
- writeByte((byte) (i >> 16));
- writeByte((byte) (i >> 8));
writeByte((byte) i);
+ writeByte((byte) (i >> 8));
+ writeByte((byte) (i >> 16));
+ writeByte((byte) (i >> 24));
}
/**
@@ -82,8 +82,8 @@ public abstract class DataOutput {
* @see DataInput#readShort()
*/
public void writeShort(short i) throws IOException {
- writeByte((byte) (i >> 8));
writeByte((byte) i);
+ writeByte((byte) (i >> 8));
}
/**
@@ -188,6 +188,8 @@ public abstract class DataOutput {
*
* <p>This provides compression while still being efficient to decode.
*
+ * <p>This provides compression while still being efficient to decode.
+ *
* @param i Smaller values take fewer bytes. Negative numbers are supported, but should be
* avoided.
* @throws IOException If there is an I/O error writing to the underlying medium.
@@ -220,8 +222,8 @@ public abstract class DataOutput {
* @see DataInput#readLong()
*/
public void writeLong(long i) throws IOException {
- writeInt((int) (i >> 32));
writeInt((int) i);
+ writeInt((int) (i >> 32));
}
/**
diff --git a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
index 5a65ce8fc1b..acadeefdf9b 100644
--- a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.lang.invoke.MethodHandle;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.ClosedChannelException; // javadoc @link
import java.nio.channels.FileChannel;
@@ -263,6 +264,7 @@ public class MMapDirectory extends FSDirectory {
MappedByteBuffer buffer;
try {
buffer = fc.map(MapMode.READ_ONLY, offset + bufferStart, bufSize);
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
} catch (IOException ioe) {
throw convertMapFailedIOException(ioe, resourceDescription, bufSize);
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/fst/FST.java b/lucene/core/src/java/org/apache/lucene/util/fst/FST.java
index 6857f90e19b..2ccaa937286 100644
--- a/lucene/core/src/java/org/apache/lucene/util/fst/FST.java
+++ b/lucene/core/src/java/org/apache/lucene/util/fst/FST.java
@@ -115,7 +115,8 @@ public final class FST<T> implements Accountable {
// Increment version to change it
private static final String FILE_FORMAT_NAME = "FST";
private static final int VERSION_START = 6;
- private static final int VERSION_CURRENT = 7;
+ private static final int VERSION_LITTLE_ENDIAN = 8;
+ private static final int VERSION_CURRENT = VERSION_LITTLE_ENDIAN;
// Never serialized; just used to represent the virtual
// final node w/ no arcs:
@@ -146,6 +147,8 @@ public final class FST<T> implements Accountable {
public final Outputs<T> outputs;
+ private final int version;
+
/** Represents a single arc. */
public static final class Arc<T> {
@@ -420,6 +423,7 @@ public final class FST<T> implements Accountable {
// the stop state w/ no arcs
bytes.writeByte((byte) 0);
emptyOutput = null;
+ this.version = VERSION_CURRENT;
}
private static final int DEFAULT_MAX_BLOCK_BITS = Constants.JRE_IS_64BIT ? 30 : 28;
@@ -441,7 +445,7 @@ public final class FST<T> implements Accountable {
// NOTE: only reads formats VERSION_START up to VERSION_CURRENT; we don't have
// back-compat promise for FSTs (they are experimental), but we are sometimes able to offer it
- CodecUtil.checkHeader(metaIn, FILE_FORMAT_NAME, VERSION_START, VERSION_CURRENT);
+ this.version = CodecUtil.checkHeader(metaIn, FILE_FORMAT_NAME, VERSION_START, VERSION_CURRENT);
if (metaIn.readByte() == 1) {
// accepts empty string
// 1 KB blocks:
@@ -610,7 +614,11 @@ public final class FST<T> implements Accountable {
v = in.readByte() & 0xFF;
} else if (inputType == INPUT_TYPE.BYTE2) {
// Unsigned short:
- v = in.readShort() & 0xFFFF;
+ if (version < VERSION_LITTLE_ENDIAN) {
+ v = Short.reverseBytes(in.readShort()) & 0xFFFF;
+ } else {
+ v = in.readShort() & 0xFFFF;
+ }
} else {
v = in.readVInt();
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/DirectReader.java b/lucene/core/src/java/org/apache/lucene/util/packed/DirectReader.java
index 71469981ed5..15d87479796 100644
--- a/lucene/core/src/java/org/apache/lucene/util/packed/DirectReader.java
+++ b/lucene/core/src/java/org/apache/lucene/util/packed/DirectReader.java
@@ -97,7 +97,7 @@ public class DirectReader {
@Override
public long get(long index) {
try {
- int shift = 7 - (int) (index & 7);
+ int shift = (int) (index & 7);
return (in.readByte(offset + (index >>> 3)) >>> shift) & 0x1;
} catch (IOException e) {
throw new RuntimeException(e);
@@ -117,7 +117,7 @@ public class DirectReader {
@Override
public long get(long index) {
try {
- int shift = (3 - (int) (index & 3)) << 1;
+ int shift = ((int) (index & 3)) << 1;
return (in.readByte(offset + (index >>> 2)) >>> shift) & 0x3;
} catch (IOException e) {
throw new RuntimeException(e);
@@ -132,12 +132,13 @@ public class DirectReader {
DirectPackedReader4(RandomAccessInput in, long offset) {
this.in = in;
this.offset = offset;
+ ;
}
@Override
public long get(long index) {
try {
- int shift = (int) ((index + 1) & 1) << 2;
+ int shift = (int) (index & 1) << 2;
return (in.readByte(offset + (index >>> 1)) >>> shift) & 0xF;
} catch (IOException e) {
throw new RuntimeException(e);
@@ -177,7 +178,7 @@ public class DirectReader {
public long get(long index) {
try {
long offset = (index * 12) >>> 3;
- int shift = (int) ((index + 1) & 1) << 2;
+ int shift = (int) (index & 1) << 2;
return (in.readShort(this.offset + offset) >>> shift) & 0xFFF;
} catch (IOException e) {
throw new RuntimeException(e);
@@ -217,10 +218,8 @@ public class DirectReader {
public long get(long index) {
try {
long offset = (index * 20) >>> 3;
- // TODO: clean this up...
- int v = in.readInt(this.offset + offset) >>> 8;
- int shift = (int) ((index + 1) & 1) << 2;
- return (v >>> shift) & 0xFFFFF;
+ int shift = (int) (index & 1) << 2;
+ return (in.readInt(this.offset + offset) >>> shift) & 0xFFFFF;
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -230,6 +229,7 @@ public class DirectReader {
static final class DirectPackedReader24 extends LongValues {
final RandomAccessInput in;
final long offset;
+ ;
DirectPackedReader24(RandomAccessInput in, long offset) {
this.in = in;
@@ -239,7 +239,7 @@ public class DirectReader {
@Override
public long get(long index) {
try {
- return in.readInt(offset + index * 3) >>> 8;
+ return in.readInt(this.offset + index * 3) & 0xFFFFFF;
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -259,8 +259,8 @@ public class DirectReader {
public long get(long index) {
try {
long offset = (index * 28) >>> 3;
- int shift = (int) ((index + 1) & 1) << 2;
- return (in.readInt(this.offset + offset) >>> shift) & 0xFFFFFFFL;
+ int shift = (int) (index & 1) << 2;
+ return (in.readInt(this.offset + offset) >>> shift) & 0xFFFFFFF;
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -298,7 +298,7 @@ public class DirectReader {
@Override
public long get(long index) {
try {
- return in.readLong(this.offset + index * 5) >>> 24;
+ return in.readLong(this.offset + index * 5) & 0xFFFFFFFFFFL;
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -317,7 +317,7 @@ public class DirectReader {
@Override
public long get(long index) {
try {
- return in.readLong(this.offset + index * 6) >>> 16;
+ return in.readLong(this.offset + index * 6) & 0xFFFFFFFFFFFFL;
} catch (IOException e) {
throw new RuntimeException(e);
}
@@ -336,7 +336,7 @@ public class DirectReader {
@Override
public long get(long index) {
try {
- return in.readLong(this.offset + index * 7) >>> 8;
+ return in.readLong(this.offset + index * 7) & 0xFFFFFFFFFFFFFFL;
} catch (IOException e) {
throw new RuntimeException(e);
}
diff --git a/lucene/core/src/java/org/apache/lucene/util/packed/DirectWriter.java b/lucene/core/src/java/org/apache/lucene/util/packed/DirectWriter.java
index c35f9fe38d4..a2b499edf36 100644
--- a/lucene/core/src/java/org/apache/lucene/util/packed/DirectWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/util/packed/DirectWriter.java
@@ -55,12 +55,18 @@ public final class DirectWriter {
final long[] nextValues;
final BulkOperation encoder;
final int iterations;
+ final int byteOffset;
+ final int bitsUsedOffset;
+ final int byteValueCount;
DirectWriter(DataOutput output, long numValues, int bitsPerValue) {
this.output = output;
this.numValues = numValues;
this.bitsPerValue = bitsPerValue;
encoder = BulkOperation.of(PackedInts.Format.PACKED, bitsPerValue);
+ this.byteOffset = 8 - bitsPerValue;
+ this.bitsUsedOffset = bitsPerValue - 8;
+ this.byteValueCount = encoder.byteValueCount();
iterations =
encoder.computeIterations(
(int) Math.min(numValues, Integer.MAX_VALUE), PackedInts.DEFAULT_BUFFER_SIZE);
@@ -83,7 +89,7 @@ public final class DirectWriter {
}
private void flush() throws IOException {
- encoder.encode(nextValues, 0, nextBlocks, 0, iterations);
+ encode(nextValues, 0, nextBlocks, 0, iterations);
final int blockCount =
(int) PackedInts.Format.PACKED.byteCount(PackedInts.VERSION_CURRENT, off, bitsPerValue);
output.writeBytes(nextBlocks, blockCount);
@@ -91,6 +97,33 @@ public final class DirectWriter {
off = 0;
}
+ public void encode(
+ long[] values, int valuesOffset, byte[] blocks, int blocksOffset, int iterations) {
+ int nextBlock = 0;
+ int bitsUsed = 0;
+ for (int i = 0; i < byteValueCount * iterations; ++i) {
+ final long v = values[valuesOffset++];
+ assert PackedInts.unsignedBitsRequired(v) <= bitsPerValue;
+ if (bitsUsed < byteOffset) {
+ // just buffer
+ nextBlock |= v << bitsUsed;
+ bitsUsed += bitsPerValue;
+ } else {
+ // flush as many blocks as possible
+ blocks[blocksOffset++] = (byte) (nextBlock | (v << bitsUsed));
+ int bits = 8 - bitsUsed;
+ while (bits <= bitsUsedOffset) {
+ blocks[blocksOffset++] = (byte) (v >> bits);
+ bits += 8;
+ }
+ // then buffer
+ bitsUsed = bitsPerValue - bits;
+ nextBlock = (int) ((v >>> bits) & ((1L << bitsUsed) - 1));
+ }
+ }
+ assert bitsUsed == 0;
+ }
+
/** finishes writing */
public void finish() throws IOException {
if (count != numValues) {
diff --git a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
index 8e1a81314dd..3c8717aaa68 100644
--- a/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
+++ b/lucene/core/src/test/org/apache/lucene/codecs/TestCodecUtil.java
@@ -182,9 +182,9 @@ public class TestCodecUtil extends LuceneTestCase {
IndexOutput output = new ByteBuffersIndexOutput(out, "temp", "temp");
CodecUtil.writeHeader(output, "FooBar", 5);
output.writeString("this is the data");
- output.writeInt(CodecUtil.FOOTER_MAGIC);
- output.writeInt(0);
- output.writeLong(1234567); // write a bogus checksum
+ CodecUtil.writeBEInt(output, CodecUtil.FOOTER_MAGIC);
+ CodecUtil.writeBEInt(output, 0);
+ CodecUtil.writeBELong(output, 1234567); // write a bogus checksum
output.close();
ChecksumIndexInput input =
@@ -265,10 +265,10 @@ public class TestCodecUtil extends LuceneTestCase {
public void testReadBogusCRC() throws Exception {
ByteBuffersDataOutput out = new ByteBuffersDataOutput();
IndexOutput output = new ByteBuffersIndexOutput(out, "temp", "temp");
- output.writeLong(-1L); // bad
- output.writeLong(1L << 32); // bad
- output.writeLong(-(1L << 32)); // bad
- output.writeLong((1L << 32) - 1); // ok
+ CodecUtil.writeBELong(output, -1L); // bad
+ CodecUtil.writeBELong(output, 1L << 32); // bad
+ CodecUtil.writeBELong(output, -(1L << 32)); // bad);
+ CodecUtil.writeBELong(output, (1L << 32) - 1); // ok
output.close();
IndexInput input =
new BufferedChecksumIndexInput(new ByteBuffersIndexInput(out.toDataInput(), "temp"));
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
index ad2abc34275..1a1f0b3c679 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestAllFilesHaveCodecHeader.java
@@ -84,7 +84,7 @@ public class TestAllFilesHaveCodecHeader extends LuceneTestCase {
Directory dir, String file, Map<String, String> namesToExtensions, byte[] id)
throws IOException {
try (IndexInput in = dir.openInput(file, newIOContext(random()))) {
- int val = in.readInt();
+ int val = CodecUtil.readBEInt(in);
assertEquals(
file + " has no codec header, instead found: " + val, CodecUtil.CODEC_MAGIC, val);
String codecName = in.readString();
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
index 333c147dd1a..6599ba91fc7 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
@@ -426,15 +426,15 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
new MMapDirectory(createTempDir("testLittleEndianLongsCrossBoundary"), 16)) {
try (IndexOutput out = dir.createOutput("littleEndianLongs", newIOContext(random()))) {
out.writeByte((byte) 2);
- out.writeLong(Long.reverseBytes(3L));
- out.writeLong(Long.reverseBytes(Long.MAX_VALUE));
- out.writeLong(Long.reverseBytes(-3L));
+ out.writeLong(3L);
+ out.writeLong(Long.MAX_VALUE);
+ out.writeLong(-3L);
}
try (IndexInput input = dir.openInput("littleEndianLongs", newIOContext(random()))) {
assertEquals(25, input.length());
assertEquals(2, input.readByte());
long[] l = new long[4];
- input.readLELongs(l, 1, 3);
+ input.readLongs(l, 1, 3);
assertArrayEquals(new long[] {0L, 3L, Long.MAX_VALUE, -3L}, l);
assertEquals(25, input.getFilePointer());
}
@@ -445,15 +445,15 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
try (Directory dir = new MMapDirectory(createTempDir("testFloatsCrossBoundary"), 8)) {
try (IndexOutput out = dir.createOutput("Floats", newIOContext(random()))) {
out.writeByte((byte) 2);
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(3f)));
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(Float.MAX_VALUE)));
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(-3f)));
+ out.writeInt(Float.floatToIntBits(3f));
+ out.writeInt(Float.floatToIntBits(Float.MAX_VALUE));
+ out.writeInt(Float.floatToIntBits(-3f));
}
try (IndexInput input = dir.openInput("Floats", newIOContext(random()))) {
assertEquals(13, input.length());
assertEquals(2, input.readByte());
float[] ff = new float[4];
- input.readLEFloats(ff, 1, 3);
+ input.readFloats(ff, 1, 3);
assertArrayEquals(new float[] {0, 3f, Float.MAX_VALUE, -3f}, ff, 0);
assertEquals(13, input.getFilePointer());
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/TestBytesStore.java b/lucene/core/src/test/org/apache/lucene/util/fst/TestBytesStore.java
index 47bd0cd6a52..4fd823bbeb7 100644
--- a/lucene/core/src/test/org/apache/lucene/util/fst/TestBytesStore.java
+++ b/lucene/core/src/test/org/apache/lucene/util/fst/TestBytesStore.java
@@ -349,16 +349,16 @@ public class TestBytesStore extends LuceneTestCase {
int expectedInt = 0;
if (reversed) {
expectedPos -= skipBytes;
- expectedInt |= (expected[expectedPos--] & 0xFF) << 24;
- expectedInt |= (expected[expectedPos--] & 0xFF) << 16;
- expectedInt |= (expected[expectedPos--] & 0xFF) << 8;
expectedInt |= (expected[expectedPos--] & 0xFF);
+ expectedInt |= (expected[expectedPos--] & 0xFF) << 8;
+ expectedInt |= (expected[expectedPos--] & 0xFF) << 16;
+ expectedInt |= (expected[expectedPos--] & 0xFF) << 24;
} else {
expectedPos += skipBytes;
- expectedInt |= (expected[expectedPos++] & 0xFF) << 24;
- expectedInt |= (expected[expectedPos++] & 0xFF) << 16;
- expectedInt |= (expected[expectedPos++] & 0xFF) << 8;
expectedInt |= (expected[expectedPos++] & 0xFF);
+ expectedInt |= (expected[expectedPos++] & 0xFF) << 8;
+ expectedInt |= (expected[expectedPos++] & 0xFF) << 16;
+ expectedInt |= (expected[expectedPos++] & 0xFF) << 24;
}
if (VERBOSE) {
diff --git a/lucene/luke/src/java/org/apache/lucene/luke/models/util/IndexUtils.java b/lucene/luke/src/java/org/apache/lucene/luke/models/util/IndexUtils.java
index 11244ec78c4..099326f7602 100644
--- a/lucene/luke/src/java/org/apache/lucene/luke/models/util/IndexUtils.java
+++ b/lucene/luke/src/java/org/apache/lucene/luke/models/util/IndexUtils.java
@@ -311,7 +311,7 @@ public final class IndexUtils {
protected String doBody(String segmentFileName) throws IOException {
String format = "unknown";
try (IndexInput in = dir.openInput(segmentFileName, IOContext.READ)) {
- if (CodecUtil.CODEC_MAGIC == in.readInt()) {
+ if (CodecUtil.CODEC_MAGIC == CodecUtil.readBEInt(in)) {
int actualVersion =
CodecUtil.checkHeaderNoMagic(
in, "segments", SegmentInfos.VERSION_70, Integer.MAX_VALUE);
diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java
index 59335f12322..9cf9db3f854 100644
--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java
+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/fst/FSTCompletionLookup.java
@@ -183,7 +183,12 @@ public class FSTCompletionLookup extends Lookup {
}
output.reset(buffer);
- output.writeInt(encodeWeight(iterator.weight()));
+ final int encodedWeight = encodeWeight(iterator.weight());
+ // write bytes for comparing in lexicographically order
+ output.writeByte((byte) (encodedWeight >> 24));
+ output.writeByte((byte) (encodedWeight >> 16));
+ output.writeByte((byte) (encodedWeight >> 8));
+ output.writeByte((byte) encodedWeight);
output.writeBytes(spare.bytes, spare.offset, spare.length);
writer.write(buffer, 0, output.getPosition());
inputLineCount++;
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
index 95a936afda6..5545b6e9e7b 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseCompoundFormatTestCase.java
@@ -856,11 +856,10 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
}
// write footer w/ wrong checksum
- os.writeInt(CodecUtil.FOOTER_MAGIC);
- os.writeInt(0);
-
+ CodecUtil.writeBEInt(os, CodecUtil.FOOTER_MAGIC);
+ CodecUtil.writeBEInt(os, 0);
long checksum = os.getChecksum();
- os.writeLong(checksum + 1);
+ CodecUtil.writeBELong(os, checksum + 1);
}
si.setFiles(Collections.singletonList(subFile));
@@ -881,10 +880,10 @@ public abstract class BaseCompoundFormatTestCase extends BaseIndexFileFormatTest
for (int i = 0; i < 1024; i++) {
os.writeByte((byte) i);
}
- os.writeInt(CodecUtil.FOOTER_MAGIC);
- os.writeInt(0);
+ CodecUtil.writeBEInt(os, CodecUtil.FOOTER_MAGIC);
+ CodecUtil.writeBEInt(os, 0);
long checksum = os.getChecksum();
- os.writeLong(checksum);
+ CodecUtil.writeBELong(os, checksum);
}
si.setFiles(Collections.singletonList(subFile));
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
index 7cdc0246bd1..d6738f631ac 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/BaseDirectoryTestCase.java
@@ -185,14 +185,14 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
public void testAlignedLittleEndianLongs() throws Exception {
try (Directory dir = getDirectory(createTempDir("testAlignedLittleEndianLongs"))) {
try (IndexOutput out = dir.createOutput("littleEndianLongs", newIOContext(random()))) {
- out.writeLong(Long.reverseBytes(3L));
- out.writeLong(Long.reverseBytes(Long.MAX_VALUE));
- out.writeLong(Long.reverseBytes(-3L));
+ out.writeLong(3L);
+ out.writeLong(Long.MAX_VALUE);
+ out.writeLong(-3L);
}
try (IndexInput input = dir.openInput("littleEndianLongs", newIOContext(random()))) {
assertEquals(24, input.length());
long[] l = new long[4];
- input.readLELongs(l, 1, 3);
+ input.readLongs(l, 1, 3);
assertArrayEquals(new long[] {0L, 3L, Long.MAX_VALUE, -3L}, l);
assertEquals(24, input.getFilePointer());
}
@@ -203,15 +203,15 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
try (Directory dir = getDirectory(createTempDir("testUnalignedLittleEndianLongs"))) {
try (IndexOutput out = dir.createOutput("littleEndianLongs", newIOContext(random()))) {
out.writeByte((byte) 2);
- out.writeLong(Long.reverseBytes(3L));
- out.writeLong(Long.reverseBytes(Long.MAX_VALUE));
- out.writeLong(Long.reverseBytes(-3L));
+ out.writeLong(3L);
+ out.writeLong(Long.MAX_VALUE);
+ out.writeLong(-3L);
}
try (IndexInput input = dir.openInput("littleEndianLongs", newIOContext(random()))) {
assertEquals(25, input.length());
assertEquals(2, input.readByte());
long[] l = new long[4];
- input.readLELongs(l, 1, 3);
+ input.readLongs(l, 1, 3);
assertArrayEquals(new long[] {0L, 3L, Long.MAX_VALUE, -3L}, l);
assertEquals(25, input.getFilePointer());
}
@@ -230,7 +230,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
}
try (IndexInput input = dir.openInput("littleEndianLongs", newIOContext(random()))) {
input.seek(offset);
- expectThrows(EOFException.class, () -> input.readLELongs(new long[length], 0, length));
+ expectThrows(EOFException.class, () -> input.readLongs(new long[length], 0, length));
}
}
}
@@ -238,14 +238,14 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
public void testAlignedFloats() throws Exception {
try (Directory dir = getDirectory(createTempDir("testAlignedFloats"))) {
try (IndexOutput out = dir.createOutput("Floats", newIOContext(random()))) {
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(3f)));
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(Float.MAX_VALUE)));
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(-3f)));
+ out.writeInt(Float.floatToIntBits(3f));
+ out.writeInt(Float.floatToIntBits(Float.MAX_VALUE));
+ out.writeInt(Float.floatToIntBits(-3f));
}
try (IndexInput input = dir.openInput("Floats", newIOContext(random()))) {
assertEquals(12, input.length());
float[] ff = new float[4];
- input.readLEFloats(ff, 1, 3);
+ input.readFloats(ff, 1, 3);
assertArrayEquals(new float[] {0, 3f, Float.MAX_VALUE, -3f}, ff, 0);
assertEquals(12, input.getFilePointer());
}
@@ -259,9 +259,9 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
for (int i = 0; i < padding; i++) {
out.writeByte((byte) 2);
}
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(3f)));
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(Float.MAX_VALUE)));
- out.writeInt(Integer.reverseBytes(Float.floatToIntBits(-3f)));
+ out.writeInt(Float.floatToIntBits(3f));
+ out.writeInt(Float.floatToIntBits(Float.MAX_VALUE));
+ out.writeInt(Float.floatToIntBits(-3f));
}
try (IndexInput input = dir.openInput("Floats", newIOContext(random()))) {
assertEquals(12 + padding, input.length());
@@ -269,7 +269,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
assertEquals(2, input.readByte());
}
float[] ff = new float[4];
- input.readLEFloats(ff, 1, 3);
+ input.readFloats(ff, 1, 3);
assertArrayEquals(new float[] {0, 3f, Float.MAX_VALUE, -3f}, ff, 0);
assertEquals(12 + padding, input.getFilePointer());
}
@@ -288,7 +288,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
}
try (IndexInput input = dir.openInput("Floats", newIOContext(random()))) {
input.seek(offset);
- expectThrows(EOFException.class, () -> input.readLEFloats(new float[length], 0, length));
+ expectThrows(EOFException.class, () -> input.readFloats(new float[length], 0, length));
}
}
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
index fea8096923c..fa9043e6571 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockIndexInputWrapper.java
@@ -155,9 +155,9 @@ public class MockIndexInputWrapper extends IndexInput {
}
@Override
- public void readLEFloats(float[] floats, int offset, int len) throws IOException {
+ public void readFloats(float[] floats, int offset, int len) throws IOException {
ensureOpen();
- delegate.readLEFloats(floats, offset, len);
+ delegate.readFloats(floats, offset, len);
}
@Override