2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.impl.tls;
10 import com.google.common.base.Preconditions;
12 import java.io.FileInputStream;
13 import java.io.FileNotFoundException;
14 import java.io.InputStream;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.config.rev230112.pcep.session.tls.PathType;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public final class SslKeyStore {
20 private static final Logger LOG = LoggerFactory.getLogger(SslKeyStore.class);
22 private SslKeyStore() {
27 * InputStream instance of key - key location is on classpath or specific path.
32 * keystore location type - "classpath" or "path"
34 * @return key as InputStream
36 public static InputStream asInputStream(final String filename, final PathType pathType) {
40 in = SslKeyStore.class.getResourceAsStream(filename);
41 Preconditions.checkArgument(in != null, "KeyStore file not found: %s", filename);
44 LOG.debug("Current dir using System: {}", System.getProperty("user.dir"));
45 final File keystorefile = new File(filename);
47 in = new FileInputStream(keystorefile);
48 } catch (final FileNotFoundException e) {
49 throw new IllegalStateException("KeyStore file not found: " + filename,e);
53 throw new IllegalArgumentException("Unknown path type: " + pathType);