@Test public void asInputStream() throws Exception { Assert.assertNotNull(SslContextFactory.asInputStream("keystore", PathType.CLASSPATH)); final File file = new File("tst_file"); if (file.createNewFile()) { Assert.assertNotNull(SslContextFactory.asInputStream("tst_file", PathType.PATH)); file.delete(); } try { Assert.assertNotNull(SslContextFactory.asInputStream("", PathType.PATH)); Assert.fail("Should fail on as file does not exist"); } catch (Exception e) { } try { Assert.assertNotNull(SslContextFactory.asInputStream("keystore", null)); Assert.fail("Should fail on as path is not specified"); } catch (Exception e) { } }
public static InputStream asInputStream(final String filename, final PathType pathType) { InputStream in; switch (pathType) { case CLASSPATH: in = SslContextFactory.class.getClassLoader().getResourceAsStream(filename); Preconditions.checkArgument(in != null, "File not found: %s", filename); break; case PATH: LOG.debug("Current dir using System: {}", System.getProperty("user.dir")); final File keystorefile = new File(filename); try { in = new FileInputStream(keystorefile); } catch (final FileNotFoundException e) { throw new IllegalStateException("File not found: " + filename, e); } break; default: throw new IllegalArgumentException("Unknown path type: " + pathType); } return in; }
SslContextFactory { public static InputStream asInputStream(final String filename, final PathType pathType) { InputStream in; switch (pathType) { case CLASSPATH: in = SslContextFactory.class.getClassLoader().getResourceAsStream(filename); Preconditions.checkArgument(in != null, "File not found: %s", filename); break; case PATH: LOG.debug("Current dir using System: {}", System.getProperty("user.dir")); final File keystorefile = new File(filename); try { in = new FileInputStream(keystorefile); } catch (final FileNotFoundException e) { throw new IllegalStateException("File not found: " + filename, e); } break; default: throw new IllegalArgumentException("Unknown path type: " + pathType); } return in; } }
SslContextFactory { public static InputStream asInputStream(final String filename, final PathType pathType) { InputStream in; switch (pathType) { case CLASSPATH: in = SslContextFactory.class.getClassLoader().getResourceAsStream(filename); Preconditions.checkArgument(in != null, "File not found: %s", filename); break; case PATH: LOG.debug("Current dir using System: {}", System.getProperty("user.dir")); final File keystorefile = new File(filename); try { in = new FileInputStream(keystorefile); } catch (final FileNotFoundException e) { throw new IllegalStateException("File not found: " + filename, e); } break; default: throw new IllegalArgumentException("Unknown path type: " + pathType); } return in; } SslContextFactory(final Tls tlsConfig); }
SslContextFactory { public static InputStream asInputStream(final String filename, final PathType pathType) { InputStream in; switch (pathType) { case CLASSPATH: in = SslContextFactory.class.getClassLoader().getResourceAsStream(filename); Preconditions.checkArgument(in != null, "File not found: %s", filename); break; case PATH: LOG.debug("Current dir using System: {}", System.getProperty("user.dir")); final File keystorefile = new File(filename); try { in = new FileInputStream(keystorefile); } catch (final FileNotFoundException e) { throw new IllegalStateException("File not found: " + filename, e); } break; default: throw new IllegalArgumentException("Unknown path type: " + pathType); } return in; } SslContextFactory(final Tls tlsConfig); static InputStream asInputStream(final String filename, final PathType pathType); Optional<SslContext> getClientContext(); Optional<SslContext> getServerContext(); }
SslContextFactory { public static InputStream asInputStream(final String filename, final PathType pathType) { InputStream in; switch (pathType) { case CLASSPATH: in = SslContextFactory.class.getClassLoader().getResourceAsStream(filename); Preconditions.checkArgument(in != null, "File not found: %s", filename); break; case PATH: LOG.debug("Current dir using System: {}", System.getProperty("user.dir")); final File keystorefile = new File(filename); try { in = new FileInputStream(keystorefile); } catch (final FileNotFoundException e) { throw new IllegalStateException("File not found: " + filename, e); } break; default: throw new IllegalArgumentException("Unknown path type: " + pathType); } return in; } SslContextFactory(final Tls tlsConfig); static InputStream asInputStream(final String filename, final PathType pathType); Optional<SslContext> getClientContext(); Optional<SslContext> getServerContext();  }