Search in sources :

Example 1 with ByteBuffersDataInput

use of org.apache.lucene.store.ByteBuffersDataInput in project OpenSearch by opensearch-project.

the class ChecksumBlobStoreFormat method deserialize.

public T deserialize(String blobName, NamedXContentRegistry namedXContentRegistry, BytesReference bytes) throws IOException {
    final String resourceDesc = "ChecksumBlobStoreFormat.readBlob(blob=\"" + blobName + "\")";
    try {
        final IndexInput indexInput = bytes.length() > 0 ? new ByteBuffersIndexInput(new ByteBuffersDataInput(Arrays.asList(BytesReference.toByteBuffers(bytes))), resourceDesc) : new ByteArrayIndexInput(resourceDesc, BytesRef.EMPTY_BYTES);
        CodecUtil.checksumEntireFile(indexInput);
        CodecUtil.checkHeader(indexInput, codec, VERSION, VERSION);
        long filePointer = indexInput.getFilePointer();
        long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
        try (XContentParser parser = XContentHelper.createParser(namedXContentRegistry, LoggingDeprecationHandler.INSTANCE, bytes.slice((int) filePointer, (int) contentSize), XContentType.SMILE)) {
            return reader.apply(parser);
        }
    } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
        // we trick this into a dedicated exception with the original stacktrace
        throw new CorruptStateException(ex);
    }
}
Also used : IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) CorruptStateException(org.opensearch.gateway.CorruptStateException) ByteBuffersDataInput(org.apache.lucene.store.ByteBuffersDataInput) ByteBuffersIndexInput(org.apache.lucene.store.ByteBuffersIndexInput) ByteBuffersIndexInput(org.apache.lucene.store.ByteBuffersIndexInput) IndexInput(org.apache.lucene.store.IndexInput) ByteArrayIndexInput(org.opensearch.common.lucene.store.ByteArrayIndexInput) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ByteArrayIndexInput(org.opensearch.common.lucene.store.ByteArrayIndexInput) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException) XContentParser(org.opensearch.common.xcontent.XContentParser)

Aggregations

CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 ByteBuffersDataInput (org.apache.lucene.store.ByteBuffersDataInput)1 ByteBuffersIndexInput (org.apache.lucene.store.ByteBuffersIndexInput)1 IndexInput (org.apache.lucene.store.IndexInput)1 ByteArrayIndexInput (org.opensearch.common.lucene.store.ByteArrayIndexInput)1 XContentParser (org.opensearch.common.xcontent.XContentParser)1 CorruptStateException (org.opensearch.gateway.CorruptStateException)1