本文整理汇总了Java中nxt.util.CountingInputStream类的典型用法代码示例。如果您正苦于以下问题:Java CountingInputStream类的具体用法?Java CountingInputStream怎么用?Java CountingInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CountingInputStream类属于nxt.util包,在下文中一共展示了CountingInputStream类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: doPost
import nxt.util.CountingInputStream; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PeerImpl peer = null;
JSONStreamAware response;
try {
peer = Peers.addPeer(req.getRemoteAddr(), null);
if (peer == null) {
return;
}
if (peer.isBlacklisted()) {
return;
}
JSONObject request;
CountingInputStream cis = new CountingInputStream(req.getInputStream());
try (Reader reader = new BufferedReader(new InputStreamReader(cis, "UTF-8"))) {
request = (JSONObject) JSONValue.parse(reader);
}
if (request == null) {
return;
}
if (peer.getState() == Peer.State.DISCONNECTED) {
peer.setState(Peer.State.CONNECTED);
}
peer.updateDownloadedVolume(cis.getCount());
if (! peer.analyzeHallmark(peer.getPeerAddress(), (String)request.get("hallmark"))) {
peer.blacklist();
return;
}
if (request.get("protocol") != null && ((Number)request.get("protocol")).intValue() == 1) {
PeerRequestHandler peerRequestHandler = peerRequestHandlers.get(request.get("requestType"));
if (peerRequestHandler != null) {
response = peerRequestHandler.processRequest(request, peer);
} else {
response = UNSUPPORTED_REQUEST_TYPE;
}
} else {
Logger.logDebugMessage("Unsupported protocol " + request.get("protocol"));
response = UNSUPPORTED_PROTOCOL;
}
} catch (RuntimeException e) {
Logger.logDebugMessage("Error processing POST request", e);
JSONObject json = new JSONObject();
json.put("error", e.toString());
response = json;
}
resp.setContentType("text/plain; charset=UTF-8");
CountingOutputStream cos = new CountingOutputStream(resp.getOutputStream());
try (Writer writer = new BufferedWriter(new OutputStreamWriter(cos, "UTF-8"))) {
response.writeJSONString(writer);
}
if (peer != null) {
peer.updateUploadedVolume(cos.getCount());
}
}
开发者ID:aspnmy,项目名称:NasCoin,代码行数:63,代码来源:PeerServlet.java
注:本文中的nxt.util.CountingInputStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论