我有一个库,它返回一些二进制数据作为二进制数组列表。这些 byte[] 需要合并到一个 InputStream 中。
这是我当前的实现:
public static InputStream foo(List<byte[]> binary) {
byte[] streamArray = null;
binary.forEach(bin -> {
org.apache.commons.lang.ArrayUtils.addAll(streamArray, bin);
});
return new ByteArrayInputStream(streamArray);
}
Run Code Online (Sandbox Code Playgroud)
但这对CPU来说是相当密集的。有没有更好的办法?
感谢所有的答案。我做了一个性能测试。这些是我的结果:
我不确定“Saka1029_2”是否测量正确......
这是执行函数:
private static double execute(Callable<InputStream> funct, int times) throws Exception {
List<Long> executions = new …
Run Code Online (Sandbox Code Playgroud) 我正在将 Hibernate 与 JpaRepositories 一起使用。
实体类的相关部分是:
@Entity
public class Person {
//.. id and other attributes
@Column(name = "function")
@ElementCollection
private Set<String> functions;
// .. getter setter
}
Run Code Online (Sandbox Code Playgroud)
我需要将我的实体类从只有一个函数更改为能够处理多个函数。我的一个 DAO 中有一个搜索函数,可以将所有现有函数与一个字符串进行比较,希望能找到已定义的函数。
最初的 JPA 查询是:
select DISTINCT(p.function) from Person p where UPPER(p.function) like UPPER(:term) order by p.function
Run Code Online (Sandbox Code Playgroud)
如何使用新的@ElementCollection 存档相同的结果?