Example usage for org.apache.lucene.store SimpleFSDirectory openInput

List of usage examples for org.apache.lucene.store SimpleFSDirectory openInput

Introduction

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

Prototype

@Override
public IndexInput openInput(String name, IOContext context) throws IOException 

Source Link

Document

Creates an IndexInput for the file with the given name.

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 w w . ja v  a 2 s  . c  o 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);
    }
}