我在我的函数的一部分中有一个switch case,我需要重新排序一些案例以便更好地读取代码.
所以现在的代码看起来像这样:
switch(parameter) {
case "foo" : {DoSomething; DoSomething; DoSomething; DoSomething; break }
case "bar" : {DoSomething; DoSomething; DoSomething; DoSomething; break }
....
case "alpha" : {DoSomething; DoSomething; DoSomething; DoSomething; break }
case "beta" : {DoSomething; DoSomething; DoSomething; DoSomething; break }
}
Run Code Online (Sandbox Code Playgroud)
所以我在这个switch语句中有一些案例,我需要重新排序它们中的大多数.并且在重新排序时,例如,如果我想将案例foo和案例栏放在案例alpha和beta之下.一个简单的Ctrl+c,Ctrl+v给我一个像这样的输出:
switch(parameter) {
case "alpha" : {DoSomething; DoSomething; DoSomething; DoSomething; break }
case "beta" : {DoSomething; DoSomething; DoSomething; DoSomething; break }
......
case "foo" : {DoSomething;
DoSomething;
DoSomething;
DoSomething;
break }
case "bar" …Run Code Online (Sandbox Code Playgroud) 我正在开发一个客户端GUI,它接受自签名服务器证书,并将它们添加到信任存储区,就像任何浏览器一样.问题是我的客户端应用程序每次启动时都要求提供证书,换句话说,它不记得证书已经在信任库中.我该如何实现?这就是我编写信任库文件的方式:
public void WriteTrustStore(String alias, X509Certificate c){
char[] password = "changeit".toCharArray();
char SEP = File.separatorChar;
keystoreFile = new File(System.getProperty("java.home")
+ SEP + "lib" + SEP + "security" + SEP + "cacerts");
try {
setTrustStore(trustStore);
FileInputStream in = new FileInputStream(keystoreFile);
trustStore.load(in, password);
in.close();
trustStore.setCertificateEntry(alias, c);
FileOutputStream out = new FileOutputStream(keystoreFile);
trustStore.store(out, password);
out.close();
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有另一种方法,我正在初始化我的SSL上下文,并通过执行以下操作创建动态别名:
string alias = getHostname() + "-" + getPortname();
Run Code Online (Sandbox Code Playgroud)
最后我有一个别名,如:
"myhost-5001"
Run Code Online (Sandbox Code Playgroud)
然后我调用WriteTrustStore(别名,证书)方法.
但是在程序的下一次执行运行中,如果我试图找到具有此别名的证书,我总是会得到一个空指针异常.
我知道信任库文件有一个属性,如: …