Search in sources :

Example 1 with ByteArrayIndexInput

use of org.elasticsearch.common.lucene.store.ByteArrayIndexInput in project elasticsearch by elastic.

the class ChecksumBlobStoreFormat method readBlob.

/**
     * Reads blob with specified name without resolving the blobName using using {@link #blobName} method.
     *
     * @param blobContainer blob container
     * @param blobName blob name
     */
public T readBlob(BlobContainer blobContainer, String blobName) throws IOException {
    try (InputStream inputStream = blobContainer.readBlob(blobName)) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Streams.copy(inputStream, out);
        final byte[] bytes = out.toByteArray();
        final String resourceDesc = "ChecksumBlobStoreFormat.readBlob(blob=\"" + blobName + "\")";
        try (ByteArrayIndexInput indexInput = new ByteArrayIndexInput(resourceDesc, bytes)) {
            CodecUtil.checksumEntireFile(indexInput);
            CodecUtil.checkHeader(indexInput, codec, VERSION, VERSION);
            long filePointer = indexInput.getFilePointer();
            long contentSize = indexInput.length() - CodecUtil.footerLength() - filePointer;
            BytesReference bytesReference = new BytesArray(bytes, (int) filePointer, (int) contentSize);
            return read(bytesReference);
        } catch (CorruptIndexException | IndexFormatTooOldException | IndexFormatTooNewException ex) {
            // we trick this into a dedicated exception with the original stacktrace
            throw new CorruptStateException(ex);
        }
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) BytesArray(org.elasticsearch.common.bytes.BytesArray) InputStream(java.io.InputStream) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayIndexInput(org.elasticsearch.common.lucene.store.ByteArrayIndexInput) IndexFormatTooOldException(org.apache.lucene.index.IndexFormatTooOldException) CorruptStateException(org.elasticsearch.gateway.CorruptStateException) IndexFormatTooNewException(org.apache.lucene.index.IndexFormatTooNewException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)1 IndexFormatTooNewException (org.apache.lucene.index.IndexFormatTooNewException)1 IndexFormatTooOldException (org.apache.lucene.index.IndexFormatTooOldException)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 ByteArrayIndexInput (org.elasticsearch.common.lucene.store.ByteArrayIndexInput)1 CorruptStateException (org.elasticsearch.gateway.CorruptStateException)1