我想异步和非阻止上传文件并阅读本文:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/HTML5andServlet31/HTML5andServlet%203.1.html。
除了我的java-ee书之外,建议的解决方案是这样的:
public class Stack {
private List<String> stack = new ArrayList<String>();
...
public int count() {
return stack.size();
}
}
我的问题是,
public class FotoReadListener implements ReadListener {
private AsyncContext ac;
private ServletInputStream is;
private StringBuilder input;
public FotoReadListener(final AsyncContext ac, final ServletInputStream is) {
this.ac = ac;
this.is = is;
this.input = new StringBuilder();
}
@Override
public void onDataAvailable() throws IOException {
byte[] b = new byte[1024];
int len = 0;
StringBuilder sb = new StringBuilder();;
while (is.isReady() && (len = is.read(b)) != -1) {
String data = new String(b, 0, len);
sb.append(data);
}
input.append(sb);
}
@Override
public void onAllDataRead() throws IOException {
FileWriter fw = new FileWriter(new File("C:\\temp\\onAllDataRead.txt"));
fw.write(input.toString());
fw.close();
ac.getResponse().getOutputStream().print("true");
ac.complete();
}
}
确实不仅仅包含文件:
ServletInputStream
如何解析此输入?我是否必须为此编写自己的解析器 - 我真的很想知道,如果没有更好的方法可以做到这一点。