Search in sources :

Example 76 with IndexInput

use of org.apache.lucene.store.IndexInput in project jackrabbit-oak by apache.

the class OakDirectoryTest method testOverflow.

//OAK-2388
@Test
public void testOverflow() throws Exception {
    Directory dir = createDir(builder, false, "/foo");
    NodeBuilder file = builder.child(INDEX_DATA_CHILD_NAME).child("test.txt");
    int blobSize = 32768;
    int dataSize = 90844;
    file.setProperty(OakDirectory.PROP_BLOB_SIZE, blobSize);
    List<? super Blob> blobs = new ArrayList<Blob>(dataSize);
    for (int i = 0; i < dataSize; i++) {
        blobs.add(new ArrayBasedBlob(new byte[0]));
    }
    file.setProperty(PropertyStates.createProperty("jcr:data", blobs, Type.BINARIES));
    IndexInput input = dir.openInput("test.txt", IOContext.DEFAULT);
    assertEquals((long) blobSize * (dataSize - 1), input.length());
}
Also used : ArrayBasedBlob(org.apache.jackrabbit.oak.plugins.memory.ArrayBasedBlob) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) IndexInput(org.apache.lucene.store.IndexInput) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Example 77 with IndexInput

use of org.apache.lucene.store.IndexInput in project elasticsearch by elastic.

the class Checkpoint method read.

public static Checkpoint read(Path path) throws IOException {
    try (Directory dir = new SimpleFSDirectory(path.getParent())) {
        try (IndexInput indexInput = dir.openInput(path.getFileName().toString(), IOContext.DEFAULT)) {
            // We checksum the entire file before we even go and parse it. If it's corrupted we barf right here.
            CodecUtil.checksumEntireFile(indexInput);
            final int fileVersion = CodecUtil.checkHeader(indexInput, CHECKPOINT_CODEC, INITIAL_VERSION, CURRENT_VERSION);
            if (fileVersion == INITIAL_VERSION) {
                assert indexInput.length() == V1_FILE_SIZE : indexInput.length();
                return Checkpoint.readCheckpointV5_0_0(indexInput);
            } else {
                assert fileVersion == CURRENT_VERSION : fileVersion;
                assert indexInput.length() == FILE_SIZE : indexInput.length();
                return Checkpoint.readCheckpointV6_0_0(indexInput);
            }
        }
    }
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) SimpleFSDirectory(org.apache.lucene.store.SimpleFSDirectory) Directory(org.apache.lucene.store.Directory)

Example 78 with IndexInput

use of org.apache.lucene.store.IndexInput in project elasticsearch by elastic.

the class InputStreamIndexInputTests method testReadMultiTwoBytesLimit1.

public void testReadMultiTwoBytesLimit1() throws IOException {
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("test", IOContext.DEFAULT);
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 1);
    }
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 2);
    }
    output.close();
    IndexInput input = dir.openInput("test", IOContext.DEFAULT);
    byte[] read = new byte[2];
    assertThat(input.getFilePointer(), lessThan(input.length()));
    InputStreamIndexInput is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 1));
    assertThat(read[1], equalTo((byte) 1));
    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 1));
    assertThat(read[1], equalTo((byte) 2));
    assertThat(input.getFilePointer(), lessThan(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(2L));
    assertThat(is.read(read), equalTo(2));
    assertThat(read[0], equalTo((byte) 2));
    assertThat(read[1], equalTo((byte) 2));
    assertThat(input.getFilePointer(), equalTo(input.length()));
    is = new InputStreamIndexInput(input, 2);
    assertThat(is.actualSizeToRead(), equalTo(0L));
    assertThat(is.read(read), equalTo(-1));
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) IndexOutput(org.apache.lucene.store.IndexOutput) RAMDirectory(org.apache.lucene.store.RAMDirectory)

Example 79 with IndexInput

use of org.apache.lucene.store.IndexInput in project elasticsearch by elastic.

the class ByteArrayIndexInputTests method randomReadAndSlice.

private byte[] randomReadAndSlice(IndexInput indexInput, int length) throws IOException {
    int readPos = (int) indexInput.getFilePointer();
    byte[] output = new byte[length];
    while (readPos < length) {
        switch(randomIntBetween(0, 3)) {
            case 0:
                // Read by one byte at a time
                output[readPos++] = indexInput.readByte();
                break;
            case 1:
                // Read several bytes into target
                int len = randomIntBetween(1, length - readPos);
                indexInput.readBytes(output, readPos, len);
                readPos += len;
                break;
            case 2:
                // Read several bytes into 0-offset target
                len = randomIntBetween(1, length - readPos);
                byte[] temp = new byte[len];
                indexInput.readBytes(temp, 0, len);
                System.arraycopy(temp, 0, output, readPos, len);
                readPos += len;
                break;
            case 3:
                // Read using slice
                len = randomIntBetween(1, length - readPos);
                IndexInput slice = indexInput.slice("slice (" + readPos + ", " + len + ") of " + indexInput.toString(), readPos, len);
                temp = randomReadAndSlice(slice, len);
                // assert that position in the original input didn't change
                assertEquals(readPos, indexInput.getFilePointer());
                System.arraycopy(temp, 0, output, readPos, len);
                readPos += len;
                indexInput.seek(readPos);
                assertEquals(readPos, indexInput.getFilePointer());
                break;
            default:
                fail();
        }
        assertEquals(readPos, indexInput.getFilePointer());
    }
    return output;
}
Also used : IndexInput(org.apache.lucene.store.IndexInput)

Example 80 with IndexInput

use of org.apache.lucene.store.IndexInput in project elasticsearch by elastic.

the class InputStreamIndexInputTests method testReadMultiSingleByteLimit1.

public void testReadMultiSingleByteLimit1() throws IOException {
    RAMDirectory dir = new RAMDirectory();
    IndexOutput output = dir.createOutput("test", IOContext.DEFAULT);
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 1);
    }
    for (int i = 0; i < 3; i++) {
        output.writeByte((byte) 2);
    }
    output.close();
    IndexInput input = dir.openInput("test", IOContext.DEFAULT);
    byte[] read = new byte[2];
    for (int i = 0; i < 3; i++) {
        assertThat(input.getFilePointer(), lessThan(input.length()));
        InputStreamIndexInput is = new InputStreamIndexInput(input, 1);
        assertThat(is.actualSizeToRead(), equalTo(1L));
        assertThat(is.read(read), equalTo(1));
        assertThat(read[0], equalTo((byte) 1));
    }
    for (int i = 0; i < 3; i++) {
        assertThat(input.getFilePointer(), lessThan(input.length()));
        InputStreamIndexInput is = new InputStreamIndexInput(input, 1);
        assertThat(is.actualSizeToRead(), equalTo(1L));
        assertThat(is.read(read), equalTo(1));
        assertThat(read[0], equalTo((byte) 2));
    }
    assertThat(input.getFilePointer(), equalTo(input.length()));
    InputStreamIndexInput is = new InputStreamIndexInput(input, 1);
    assertThat(is.actualSizeToRead(), equalTo(0L));
    assertThat(is.read(read), equalTo(-1));
}
Also used : IndexInput(org.apache.lucene.store.IndexInput) IndexOutput(org.apache.lucene.store.IndexOutput) RAMDirectory(org.apache.lucene.store.RAMDirectory)

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