Search in sources :

Example 51 with IndexInput

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));
}
Also used : IndexInput(org.apache.lucene.store.IndexInput)

Example 52 with IndexInput

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();
}
Also used : IndexInput(org.apache.lucene.store.IndexInput)

Example 53 with IndexInput

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();
}
Also used : RAMFile(org.apache.lucene.store.RAMFile) RAMInputStream(org.apache.lucene.store.RAMInputStream) RAMOutputStream(org.apache.lucene.store.RAMOutputStream) IndexInput(org.apache.lucene.store.IndexInput) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) BufferedChecksumIndexInput(org.apache.lucene.store.BufferedChecksumIndexInput) IndexOutput(org.apache.lucene.store.IndexOutput)

Example 54 with IndexInput

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);
    }
}
Also used : BitSetIterator(org.apache.lucene.util.BitSetIterator) FixedBitSet(org.apache.lucene.util.FixedBitSet) IndexInput(org.apache.lucene.store.IndexInput) IndexOutput(org.apache.lucene.store.IndexOutput) Directory(org.apache.lucene.store.Directory)

Example 55 with IndexInput

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();
}
Also used : RAMFile(org.apache.lucene.store.RAMFile) RAMInputStream(org.apache.lucene.store.RAMInputStream) RAMOutputStream(org.apache.lucene.store.RAMOutputStream) IndexInput(org.apache.lucene.store.IndexInput) ChecksumIndexInput(org.apache.lucene.store.ChecksumIndexInput) BufferedChecksumIndexInput(org.apache.lucene.store.BufferedChecksumIndexInput) IndexOutput(org.apache.lucene.store.IndexOutput)

Aggregations

IndexInput (org.apache.lucene.store.IndexInput)150 IndexOutput (org.apache.lucene.store.IndexOutput)69 Directory (org.apache.lucene.store.Directory)62 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)41 IOException (java.io.IOException)21 RAMDirectory (org.apache.lucene.store.RAMDirectory)21 FilterDirectory (org.apache.lucene.store.FilterDirectory)19 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)17 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)14 ArrayList (java.util.ArrayList)13 BytesRef (org.apache.lucene.util.BytesRef)13 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)13 CorruptingIndexOutput (org.apache.lucene.store.CorruptingIndexOutput)10 IOContext (org.apache.lucene.store.IOContext)10 NRTCachingDirectory (org.apache.lucene.store.NRTCachingDirectory)10 IntersectVisitor (org.apache.lucene.index.PointValues.IntersectVisitor)9 Relation (org.apache.lucene.index.PointValues.Relation)9 Test (org.junit.Test)8 FileNotFoundException (java.io.FileNotFoundException)7 BaseDirectoryWrapper (org.apache.lucene.store.BaseDirectoryWrapper)7