我有几个清单:
A = ["a0", "a1"] // the number of lists varies
B = ["b0", "b1", "b2"] // such as the number of elements in a list.
C = ["c1"]
D = ["d0", "d1"]
Run Code Online (Sandbox Code Playgroud)
我将此结构转换为树:
_____ROOT______
/ \
___a0____ ____a1____
/ | \ / | \
b0 b1 b2 b0 b1 b2
| | | | | |
c1 c1 c1 c1 c1 c1
/ | / | / | / | / | / |
d0 d1 d0 d1 d0 …Run Code Online (Sandbox Code Playgroud) 我有一个服务器 - 客户端架构,客户端将XML发送到读取它的服务器并从中生成PDF并将其发送回客户端.
在客户端:
JAXBElement<Xml> xml = ...
Socket sock = ...
Marshaller marshaller = ...
marshaller.marshal(xml, sock.getOutputStream());
sock.shutdownOuput();
Run Code Online (Sandbox Code Playgroud)
同时在服务器端:
ServerSocket server = ...
Socket client = server.accept();
Unmarshaller unmarshaller = ...
// client.isClosed() -> false
JAXBElement<Xml> xml =
(JAXBElement<Xml>)) unmarshaller.unmarshall(client.getInputStream());
// client.isClosed() -> true
Pdf pdf = new Pdf(xml);
client.getOutputStream().write(pdf.toBytes());
// "socket is closed" IOException is thrown
Run Code Online (Sandbox Code Playgroud)
如果我不解组客户端InputStream(在服务器端)并只发送一个虚拟PDF,那么一切都顺利进行.所以,我必须假设Unmarshaller关闭了InputStream它,因此暗中关闭客户Socket毁了我的一天......
解决这个问题的任何想法?
到目前为止,我一直在我的Linux机器上使用vim/gVim,我也有一台Windows机器.在这台Windows机器中,我主要是记事本++.
我想在Dropbox中存储我的所有.vimrc设置和.vim文件夹,并在Linux中创建指向它们的符号链接,并且它们在我的Windows机器中执行相同的操作.
~在我的配置中,我有很多"主页快捷符号"(如果这是正确的名称),并且想知道是否写下来例如$ HOME而不是〜它会起作用:这样,我可以创建Windows中的一些符号链接也指向这些文件(我使用的是Windows 7,因此我的主页是c:\ Users\username).
使用Dropbox创建vimrc交叉平台时还有其他任何陷阱或建议吗?
前几天我偶然发现了一些不便,java.util.ServiceLoader并在我身上形成了一些问题.
假设我有一个通用服务:
public interface Service<T> { ... }
Run Code Online (Sandbox Code Playgroud)
我无法明确告诉只ServiceLoader加载具有特定泛型类型的实现.
ServiceLoader<Service<String>> services =
ServiceLoader.load(Service.class); // Fail.
Run Code Online (Sandbox Code Playgroud)
我的问题是:什么是合理的方法ServiceLoader来安全地加载通用服务的实现?
在询问了上述问题之后,在Paŭlo的回答之前,我已经设法找到了解决方案.
public interface Service<T> { ...
// true if an implementation can handle the given `t' type; false otherwise.
public boolean canHandle(Class<?> t) { ...
public final class StringService implements Service<String> { ...
@Override public boolean canHandle(Class<?> t) {
if (String.class.isAssignableFrom(type))
return true;
return false;
}
public final class DoubleService implements Service<Double> { ...
// ...
public …Run Code Online (Sandbox Code Playgroud) 在对文件@ParametersAreNonnullByDefault说,认为:
此注释可以应用于包,类或方法,以指示默认情况下该元素中的方法参数是非空的,除非...
我不认为方法的返回类型/值是它的参数.它只是它的签名的一部分,所以这对我来说有点模棱两可.
正如Joachim Sauer在他的回答的评论部分中为我指出的那样,名称@ParametersAreNonnullByDefault(参数)应该清楚地表明这个注释不适用于方法的返回类型/值.我是盲人!:)谢谢Joachim!
鉴于此,我只能说@EverythingIsNonnullByDefault应该存在于某个地方.:)
我想做以下事情
var obj = {
animal: "${animal}"
};
var res = magic(obj, {animal: "cat"});
// res => {animal: "cat"}
Run Code Online (Sandbox Code Playgroud)
magic是一些做脏工作的功能.显然obj,使用多个键,嵌套数组等可能会更复杂.模板变量可以在这样的数组中
var obj = {
animals: ["cat", "dog", "${animal}", "cow"]
};
Run Code Online (Sandbox Code Playgroud)
它可以在阵列中的任何地方,所以简单地做obj.animals[2] = "bat";是不可行的.
我找到了可以实现我想要的下划线tpl库,但我想知道是否有其他解决方案供将来参考,因为我很难找到下划线tpl.
我实际使用的情况是我有一个config.json文件,我有几个声明,如下所示
{
"task1": {
"command": "command-line-program",
"args": [
"--input", "{{input}}",
"--flag1",
"--output", "{{output}}",
"--flag2",
],
"options": {
"cwd": "path-to-working-dir"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我用这个解析consig.json JSON.parse(...)我打电话require("child_process").spawn用command,args并options在文件中声明的参数,但是args改变了不少,标志添加,重新排序和东西,所以只做config.task1.args[1] = "<input value>"; …
javascript json string-interpolation underscore.js-templating
使用来自cargo-maven2-plugin的run mojo,我想知道关闭容器的更好方法.
控制台输出显示Ctrl + C停止,但似乎什么也没做.
如果我终止,它会留下一个孤儿java.exe进程,我必须自杀.
难道我做错了什么?这有点麻烦.
编辑:我在独立配置中使用Tomcat.如果我使用嵌入式Jetty,自然终止工作,但我们需要Tomcat.
我想知道Java EE 7的核心接口是否扩展AutoCloseable.(通过核心接口我的主要意思EntityManager和喜欢,但我不确定是否有其他接口或类可能会自动关闭.)
我认为他们应该而且这里是我假设的基础.
Java 6Connection甚至没有扩展Closeable,但Java 7的Connection扩展AutoCloseable(就像java.sql包中的其他几个接口一样).
在Java 7的声明中,接口是否可以EntityManager扩展AutoCloseable以便为我们提供良好的服务?或者自动神奇地关闭太复杂了?try-with-resourcesEntityManager
这个特殊功能是否被认为是JSR-342的一部分?
我想在tpl里面的javascript里面使用smarty变量
{literal}
<script language="javascript">
google.load('visualization','1',{'packages': ['geomap']});
google.setOnLoadCallback(drawMap);
function drawMap() {
var data = new google.visualization.DataTable();
data.addRows(4);
data.addColumn('string', 'Location');
data.addColumn('number', 'Number of links');
{/literal}{foreach from=$last5 item=link name=links key=index}
data.setValue({$index},0,'{$link.location|replace:'\'':'\\\''}');
data.setValue({$index},1,{$link.location_count});
{/foreach}{literal}
var options = {};
options['dataMode'] = 'regions';
options['region'] = 'world';
var container = document.getElementById('map');
var geomap = new google.visualization.GeoMap(container);
geomap.draw(data, options);
};
</script>
{/literal}
Run Code Online (Sandbox Code Playgroud)
你能告诉我一个解决方案吗?
我正在开发一个使用Dropbox API的Jersey服务.
我需要将一个通用文件发布到我的服务中(该服务可以管理各种文件,也可以使用Dropbox API).
客户端
所以,我实现了一个简单的客户端:
FileInputStream并使用字节缓冲区在连接的输出流上写入文件.这是客户端测试代码.
public class Client {
public static void main(String args[]) throws IOException, InterruptedException {
String target = "http://localhost:8080/DCService/REST/professor/upload";
URL putUrl = new URL(target);
HttpURLConnection connection = (HttpURLConnection) putUrl.openConnection();
connection.setDoOutput(true);
connection.setInstanceFollowRedirects(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("content-Type", "application/pdf");
OutputStream os = connection.getOutputStream();
InputStream is = new FileInputStream("welcome.pdf");
byte buf[] = new byte[1024];
int len;
int lung = 0;
while ((len = is.read(buf)) > 0) {
System.out.print(len);
lung += len;
is.read(buf);
os.write(buf, 0, len); …Run Code Online (Sandbox Code Playgroud) 从以下输入
[
[{group=a, value=cat}, {group=b, value=dog}],
[{group=a, value=cow}, {group=b, value=bat}]
]
Run Code Online (Sandbox Code Playgroud)
我如何获得以下输出
{
a=[{value=cat}, {value=cow}],
b=[{value=dog}, {value=bat}]
}
Run Code Online (Sandbox Code Playgroud)
使用Java 8流?
我有以下标准解决方案
Map<String, String > map1 = new LinkedHashMap<>();
map1.put("group", "a");
map1.put("value", "cat");
Map<String, String > map2 = new LinkedHashMap<>();
map2.put("group", "b");
map2.put("value", "dog");
Map<String, String > map3 = new LinkedHashMap<>();
map3.put("group", "a");
map3.put("value", "cow");
Map<String, String > map4 = new LinkedHashMap<>();
map4.put("group", "b");
map4.put("value", "bat");
List<Map<String, String>> list1 = Arrays.asList(map1, map2);
List<Map<String, String>> list2 = Arrays.asList(map3, map4);
List<List<Map<String, …Run Code Online (Sandbox Code Playgroud) java ×7
javascript ×2
algorithm ×1
annotations ×1
bit ×1
c ×1
cargo ×1
collections ×1
dropbox ×1
eclipse ×1
java-6 ×1
java-8 ×1
java-ee ×1
java-ee-7 ×1
java-stream ×1
jaxb ×1
jaxb2 ×1
jersey ×1
json ×1
jsr305 ×1
linux ×1
m2e ×1
maven ×1
random ×1
rest ×1
smarty ×1
sockets ×1
tree ×1
vim ×1
windows ×1