我需要使用SSL设置Apache 2服务器.
我有我的*.key文件,但我的证书颁发者提供了一个*.cer文件.
在网络的所有文档中,它们都是*.crt证书.
请告诉我,*.cer与*.crt相同.
如果没有,我如何将CER转换为CRT格式?
请考虑以下事项:
public Class<List<String>> getObjectType() {
// what can I return here?
}
Run Code Online (Sandbox Code Playgroud)
我可以从这个满足泛型和编译的方法返回什么类文字表达式?List.class不会编译,也不会编译List.<String>class.
如果你想知道"为什么",我正在写一个Spring的实现FactoryBean<List<String>>,这需要我实现Class<List<String>> getObjectType().但是,这不是一个Spring问题.
编辑: SpringSource的权力听到了我的哀悼,因此Spring 3.0.1将返回类型getObjectType()改为Class<?>,这样可以很好地避免问题.
我正在玩Java 8的流,无法理解我得到的性能结果.我有2个核心CPU(Intel i73520M),Windows 8 x64和64位Java 8更新5.我正在做简单的字符串流/并行流Strings,发现并行版本有点慢.
Function<Stream<String>, Long> timeOperation = (Stream<String> stream) -> {
long time1 = System.nanoTime();
final List<String> list =
stream
.map(String::toLowerCase)
.collect(Collectors.toList());
long time2 = System.nanoTime();
return time2 - time1;
};
Consumer<Stream<String>> printTime = stream ->
System.out.println(timeOperation.apply(stream) / 1000000f);
String[] array = new String[1000000];
Arrays.fill(array, "AbabagalamagA");
printTime.accept(Arrays.stream(array)); // prints around 600
printTime.accept(Arrays.stream(array).parallel()); // prints around 900
Run Code Online (Sandbox Code Playgroud)
考虑到我有2个CPU内核的事实,并行版本不应该更快吗?有人能给我一个暗示为什么并行版本更慢?
我正在尝试使用JBoss焊接编写一个java SE swing应用程序.Weld使用jar中的以下log4j.xml文件使用log4j配置日志记录:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
JBoss, Home of Professional Open Source
Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
contributors by the @authors tag. See the copyright.txt in the
distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law …Run Code Online (Sandbox Code Playgroud) 我有如下地图
Map<String, String> values = new HashMap<String, String>();
values.put("aa", "20");
values.put("bb", "30");
values.put("cc", "20");
values.put("dd", "45");
values.put("ee", "35");
values.put("ff", "35");
values.put("gg", "20");
Run Code Online (Sandbox Code Playgroud)
我想以格式创建新地图 Map<String,List<String>> ,示例输出将为
"20" -> ["aa","cc","gg"]
"30" -> ["bb"]
"35" -> ["ee","ff"]
"45" -> ["dd"]
Run Code Online (Sandbox Code Playgroud)
我可以通过迭代实体来做
Map<String, List<String>> output = new HashMap<String,List<String>>();
for(Map.Entry<String, String> entry : values.entrySet()) {
if(output.containsKey(entry.getValue())){
output.get(entry.getValue()).add(entry.getKey());
}else{
List<String> list = new ArrayList<String>();
list.add(entry.getKey());
output.put(entry.getValue(),list);
}
}
Run Code Online (Sandbox Code Playgroud)
使用流可以做得更好吗?
无限流:
val ones: Stream[Int] = Stream.cons(1, ones)
如何在自己的声明中使用值?看来这应该会产生编译错误,但它确实有效.
functional-programming scala lazy-evaluation delayed-execution
我正在尝试通过完成入门教程来学习Vagrant.但是,只有教程中的几个步骤已经无法正常工作,如教程中所述.具体来说,看起来Vagrant不知道如何下载本教程中使用的框.这是我到目前为止所做的:
看看是否安装了vagrant:
$ which vagrant
Run Code Online (Sandbox Code Playgroud)
安装Vagrant:
$ sudo aptitude install vagrant
The following NEW packages will be installed:
bsdtar{a} libruby1.9.1{a} libyaml-0-2{a} ruby{a} ruby-childprocess{a} ruby-erubis{a} ruby-ffi{a} ruby-i18n{a} ruby-log4r{a} ruby-net-scp{a} ruby-net-ssh{a} ruby1.9.1{a} vagrant
0 packages upgraded, 13 newly installed, 0 to remove and 5 not upgraded.
Need to get 0 B/3,451 kB of archives. After unpacking 17.9 MB will be used.
Do you want to continue? [Y/n/?] y
Selecting previously unselected package libyaml-0-2:amd64.
(Reading database ... 171235 files and directories currently installed.) …Run Code Online (Sandbox Code Playgroud) 问题概述
在看似随机的时间我们得到一个例外"postgresql重复密钥违反了唯一约束".我确实认为我知道我们的问题是什么,但我不想在没有可重复的测试用例的情况下对代码进行更改.但由于我们无法在生产中随机以外的任何环境中重现它,我正在寻求SO的帮助.
在这个项目中,我们有多个postgres数据库,以及为每个数据库中的每个表配置的主键序列.这些序列是这样创建的:
create sequence PERSONS_SEQ;
create sequence VISITS_SEQ;
etc...
Run Code Online (Sandbox Code Playgroud)
我们使用这些序列为实体生成主键,如下所示:
@Entity
@Table(name = "visits")
public class Visit {
@Id
@Column(name = "id")
@SequenceGenerator(name = "seq", sequenceName = "visits_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
private int id;
...
}
@Entity
@Table(name = "person")
public class Person {
@Id
@Column(name = "id")
@SequenceGenerator(name = "seq", sequenceName = "persons_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
private int id;
...
}
Run Code Online (Sandbox Code Playgroud)
分析
我想我认识到这个配置有两个问题:
1)@SequenceGenerators都指定相同的名称属性,即使它们应该映射到不同的数据库序列.
2)@SequenceGenerator allocationSize属性默认为50(我们使用hibernate作为JPA提供者)所以我认为创建序列语法应该指定序列应该增加多少,特别是50以匹配allocationSize.
根据这个猜测,我认为代码应该被修改为这样的东西:
create sequence PERSONS_SEQ increment by …Run Code Online (Sandbox Code Playgroud) gradle scala插件将compileScala任务添加到项目中.但有时scala编译器可能会报告如下内容:
$ gradle compileScala
:compileJava UP-TO-DATE
:compileScala
[ant:scalac] warning: there were 3 feature warning(s); re-run with -feature for details
[ant:scalac] one warning found
BUILD SUCCESSFUL
Total time: 21.796 secs
Run Code Online (Sandbox Code Playgroud)
我尝试使用-feature重新运行,但gradle构建抱怨如下:
$ gradle compileScala -feature
FAILURE: Build failed with an exception.
* What went wrong:
Problem configuring task :compileScala from command line.
> Unknown command-line option '-f'.
* Try:
Run gradle help --task :compileScala to get task usage details. Run with --stacktrace option to get the stack trace. …Run Code Online (Sandbox Code Playgroud) 在此示例中,maven中央存储库正在使用以下依赖项:
<!-- provides HAPI library -->
<dependency>
<groupId>ca.uhn.hapi</groupId>
<artifactId>hapi-base</artifactId>
<version>2.2</version>
</dependency>
<!-- provides HAPI library message version -->
<dependency>
<groupId>ca.uhn.hapi</groupId>
<artifactId>hapi-structures-v22</artifactId>
<version>2.2</version>
</dependency>
<!-- provides ByteString -->
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.3.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是我用scala编写的解析代码示例:
import akka.util.ByteString
import ca.uhn.hl7v2.model.Message
import ca.uhn.hl7v2.model.v22.datatype.{CM_PAT_ID, ST, TN, TSComponentOne}
import ca.uhn.hl7v2.model.v22.segment.{EVN, MRG, PID}
import ca.uhn.hl7v2.parser.CanonicalModelClassFactory
import ca.uhn.hl7v2.{DefaultHapiContext, ErrorCode, HL7Exception}
lazy val parser = {
val context = new DefaultHapiContext()
context.setModelClassFactory(new CanonicalModelClassFactory("2.2"))
context.getGenericParser
}
def parseHL7Message(message: ByteString) = Try[Message] {
val msg: String = message.utf8String.trim
parser.parse(msg)
}
Run Code Online (Sandbox Code Playgroud)
此代码可以成功解析以下HL7消息. …
java ×5
java-stream ×2
scala ×2
apache ×1
build ×1
generics ×1
gradle ×1
hapi ×1
hibernate ×1
hl7 ×1
java-8 ×1
jls ×1
jpa ×1
log4j ×1
performance ×1
postgresql ×1
scalac ×1
ssl ×1
vagrant ×1
validation ×1