Example usage for org.apache.lucene.store BufferedChecksumIndexInput BufferedChecksumIndexInput

List of usage examples for org.apache.lucene.store BufferedChecksumIndexInput BufferedChecksumIndexInput

Introduction

In this page you can find the example usage for org.apache.lucene.store BufferedChecksumIndexInput BufferedChecksumIndexInput.

Prototype

public BufferedChecksumIndexInput(IndexInput main) 

Source Link

Document

Creates a new BufferedChecksumIndexInput

Usage

From source file:org.elasticsearch.common.settings.KeyStoreWrapper.java

License:Apache License

/**
 * Loads information about the Elasticsearch keystore from the provided config directory.
 *
 * {@link #decrypt(char[])} must be called before reading or writing any entries.
 * Returns {@code null} if no keystore exists.
 *///from  w  ww . j a va  2  s  .  co m
public static KeyStoreWrapper load(Path configDir) throws IOException {
    Path keystoreFile = keystorePath(configDir);
    if (Files.exists(keystoreFile) == false) {
        return null;
    }

    SimpleFSDirectory directory = new SimpleFSDirectory(configDir);
    try (IndexInput indexInput = directory.openInput(KEYSTORE_FILENAME, IOContext.READONCE)) {
        ChecksumIndexInput input = new BufferedChecksumIndexInput(indexInput);
        CodecUtil.checkHeader(input, KEYSTORE_FILENAME, FORMAT_VERSION, FORMAT_VERSION);
        byte hasPasswordByte = input.readByte();
        boolean hasPassword = hasPasswordByte == 1;
        if (hasPassword == false && hasPasswordByte != 0) {
            throw new IllegalStateException(
                    "hasPassword boolean is corrupt: " + String.format(Locale.ROOT, "%02x", hasPasswordByte));
        }
        String type = input.readString();
        String secretKeyAlgo = input.readString();
        byte[] keystoreBytes = new byte[input.readInt()];
        input.readBytes(keystoreBytes, 0, keystoreBytes.length);
        CodecUtil.checkFooter(input);
        return new KeyStoreWrapper(hasPassword, type, secretKeyAlgo, keystoreBytes);
    }
}