use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.
the class BufferedOakDirectoryTest method assertFile.
private void assertFile(Directory dir, String file, byte[] expected) throws IOException {
assertTrue(dir.fileExists(file));
assertEquals(expected.length, dir.fileLength(file));
IndexInput in = dir.openInput(file, IOContext.DEFAULT);
byte[] data = new byte[expected.length];
in.readBytes(data, 0, data.length);
in.close();
assertTrue(Arrays.equals(expected, data));
}
use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.
the class IndexCopierTest method readAndAssert.
private static void readAndAssert(Directory wrapped, String fileName, byte[] expectedData) throws IOException {
IndexInput i = wrapped.openInput(fileName, IOContext.DEFAULT);
byte[] result = new byte[(int) wrapped.fileLength(fileName)];
i.readBytes(result, 0, result.length);
assertTrue(Arrays.equals(expectedData, result));
i.close();
}
use of org.apache.lucene.store.IndexInput in project lucene-solr by apache.
the class TestCodecUtil method testSegmentHeaderLength.
public void testSegmentHeaderLength() throws Exception {
RAMFile file = new RAMFile();
IndexOutput output = new RAMOutputStream(file, true);
CodecUtil.writeIndexHeader(output, "FooBar", 5, StringHelper.randomId(), "xyz");
output.writeString("this is the data");
output.close();
IndexInput input = new RAMInputStream("file", file);
input.seek(CodecUtil.indexHeaderLength("FooBar", "xyz"));
assertEquals("this is the data", input.readString());
input.close();
}
use of org.apache.lucene.store.IndexInput in project lucene-solr by apache.
the class TestIndexedDISI method testSparseDenseBoundary.
public void testSparseDenseBoundary() throws IOException {
try (Directory dir = newDirectory()) {
FixedBitSet set = new FixedBitSet(200000);
int start = 65536 + random().nextInt(100);
// 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)) {
IndexedDISI.writeBitSet(new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH), out);
length = out.getFilePointer();
}
try (IndexInput in = dir.openInput("sparse", IOContext.DEFAULT)) {
IndexedDISI disi = new IndexedDISI(in, 0L, length, IndexedDISI.MAX_ARRAY_LENGTH);
assertEquals(start, disi.nextDoc());
assertEquals(IndexedDISI.Method.SPARSE, disi.method);
}
doTest(set, dir);
// 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)) {
IndexedDISI.writeBitSet(new BitSetIterator(set, IndexedDISI.MAX_ARRAY_LENGTH + 1), out);
length = out.getFilePointer();
}
try (IndexInput in = dir.openInput("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);
}
doTest(set, dir);
}
}
use of org.apache.lucene.store.IndexInput in project lucene-solr by apache.
the class TestCodecUtil method testWriteVeryLongSuffix.
public void testWriteVeryLongSuffix() throws Exception {
StringBuilder justLongEnough = new StringBuilder();
for (int i = 0; i < 255; i++) {
justLongEnough.append('a');
}
RAMFile file = new RAMFile();
IndexOutput output = new RAMOutputStream(file, true);
byte[] id = StringHelper.randomId();
CodecUtil.writeIndexHeader(output, "foobar", 5, id, justLongEnough.toString());
output.close();
IndexInput input = new RAMInputStream("file", file);
CodecUtil.checkIndexHeader(input, "foobar", 5, 5, id, justLongEnough.toString());
assertEquals(input.getFilePointer(), input.length());
assertEquals(input.getFilePointer(), CodecUtil.indexHeaderLength("foobar", justLongEnough.toString()));
input.close();
}
Aggregations