- 浏览: 429446 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
sunwang810812:
万分感谢中!!!!!这么多年终于看到一个可运行可解决的方案!! ...
POI 后台生成Excel,在前台显示进度 -
zzb7728317:
LZ正解
Spring Jackson AjaxFileUpload 没有执行回调函数的解决办法 -
sleeper_qp:
lz是在源码上修改的么? 源码的话你重新编译一遍了么? 可 ...
由nutch readseg -dump 中文编码乱码想到的…… -
shenjian430:
请问你改好的程序在写在哪了?
由nutch readseg -dump 中文编码乱码想到的…… -
yinxusen:
It seems to be the bug occur in ...
Mahout Local模式 执行example的注意点
利用Netty中提供的HttpChunk简单实现文件传输
服务端基本和Netty官方文档中的example:http--file一样。
客户端:
HttpClient:
public class HttpClient { private ClientBootstrap bootstrap; private String host="localhost"; private Channel channel; private boolean futureSuccess; private int port=8080; public HttpClient() { } public ChannelFuture connect() { bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors .newCachedThreadPool())); HttpResponseHandler clientHandler = new HttpResponseHandler(); bootstrap.setPipelineFactory(new HttpClientPipelineFactory(clientHandler)); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); return bootstrap.connect(new InetSocketAddress(host,port)); } public boolean checkFutureState(ChannelFuture channelFuture) { // Wait until the connection attempt succeeds or fails. channel = channelFuture.awaitUninterruptibly().getChannel(); channelFuture.addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture connectFuture) throws Exception { if (!connectFuture.isSuccess()) { connectFuture.getCause().printStackTrace(); // connectFuture.getChannel().close(); // bootstrap.releaseExternalResources(); futureSuccess = false; } else { futureSuccess = true; } } }); return futureSuccess; } public ChannelFuture write(HttpRequest request) { return channel.write(request); } public void Close() { // Close the connection. Make sure the close operation ends because // all I/O operations are asynchronous in Netty. channel.close().awaitUninterruptibly(); // Shut down all thread pools to exit. bootstrap.releaseExternalResources(); } }
HttpClientPipelineFactory:
public class HttpClientPipelineFactory implements ChannelPipelineFactory { private final HttpResponseHandler handler; public HttpClientPipelineFactory(HttpResponseHandler handler) { this.handler = handler; } public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = pipeline(); pipeline.addLast("decoder", new HttpResponseDecoder()); //pipeline.addLast("aggregator", new HttpChunkAggregator(6048576)); pipeline.addLast("encoder", new HttpRequestEncoder()); pipeline.addLast("chunkedWriter", new ChunkedWriteHandler()); pipeline.addLast("handler", handler); return pipeline; } }
HttpResponseHandler:
@ChannelPipelineCoverage("one") public class HttpResponseHandler extends SimpleChannelUpstreamHandler { private volatile boolean readingChunks; private File downloadFile; private FileOutputStream fOutputStream = null; @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof HttpResponse) { DefaultHttpResponse httpResponse = (DefaultHttpResponse) e.getMessage(); String fileName = httpResponse.getHeader("Content-Disposition").substring(20); downloadFile = new File(System.getProperty("user.dir") + File.separator + "download" + fileName); readingChunks = httpResponse.isChunked(); } else { HttpChunk httpChunk = (HttpChunk) e.getMessage(); if (!httpChunk.isLast()) { ChannelBuffer buffer = httpChunk.getContent(); if (fOutputStream == null) { fOutputStream = new FileOutputStream(downloadFile); } while (buffer.readable()) { byte[] dst = new byte[buffer.readableBytes()]; buffer.readBytes(dst); fOutputStream.write(dst); } } else { readingChunks = false; } fOutputStream.flush(); } if (!readingChunks) { fOutputStream.close(); } } @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { System.out.println(e.getCause()); } }
main:
public class ClientMain { public static void main(String[] args) { HttpClient httpClient=new HttpClient(); ChannelFuture connectFuture=httpClient.connect(); if (httpClient.checkFutureState(connectFuture)) { System.out.println("connect ok"); HttpRequest request=new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "thunder.zip"); // HttpRequest request=new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "thunder.java"); ChannelFuture writeFuture= httpClient.write(request); if (httpClient.checkFutureState(writeFuture)) { System.out.println("write ok"); } } } }
改天看看零拷贝方式
发表评论
-
hibernate的Criteria Query(转)
2014-06-29 21:22 681当查询数据时,人们往往需要设置查询条件。在SQL或HQL语句 ... -
【转】hibernate 中 Criteria 的使用介绍
2014-06-29 21:21 929转自:http://www.blogjava.net/jjs ... -
【转】Hibernate中Criteria的完整用法
2014-06-29 21:20 686转自:http://www.cnblogs.com/maba ... -
Java读写Oracle中的BLOB和CLOB
2013-10-16 18:00 1963转:http://www.iteye.com/topic/6 ... -
Spring的事务管理入门:编程式事务管理(TransactionTemplate)
2013-10-15 16:20 979可有效应用于Oracle 临时表的insert和select ... -
jdbcTemplate 调用存储过程和回到函数
2013-10-15 09:09 3716转:http://blog.csdn.net/dancelo ... -
Spring3核心技术之JdbcTemplate
2013-10-15 09:03 1264转:http://zhou137520.iteye.com/ ... -
验证码在WebLogic下报错java.io.IOException: response already committed
2013-05-06 14:16 2524我的登录验证码代码,一个jsp,在Tomcat下没有问题,但 ... -
Struts2在eclipse的console中总是出现WARN OgnlValueStack:45 - Could not find property
2013-04-17 18:00 1674struts2 在发开时,控制台如输出大量警告信息,太烦人 ... -
【转】Eclipse自动关闭解决方法及eclipse.ini设置
2013-03-29 15:21 3777转自:http://liujun5563.blog.163. ... -
[转]批量将Java源代码文件的编码从GBK转为UTF-8
2012-11-12 13:43 1464转自:http://my.oschina.net/binny/ ... -
对代理模式与Java动态代理类的理解
2012-09-25 01:51 01. 代理模式 代理模式的作用是:为其他对象提供一种 ... -
【转】 java中yield(),sleep()以及wait()的区别
2012-09-13 22:49 808从操作系统的角度讲,os会维护一个ready queue(就绪 ... -
java 继承类 变量、静态变量、构造函数执行顺序
2012-09-10 16:07 1005包含普通变量、静态变量、构造函数、继承类的执行顺序为: 1、父 ... -
京东2012春笔试编程题
2012-09-10 12:58 01、求给定数组中最大的K个数function array[] ... -
Java实现Stack、Queue、BinaryTree
2012-09-11 10:28 14341、用数组实现Stack: public class MySt ... -
Java中a++和++a的分析
2012-09-18 08:34 2829本人从编译后的代码来看a++和++a的区别: 先看代码1: ... -
华为2012校园上机编程题
2012-09-09 16:04 0/** * 1. 手机号码合法 ... -
2011年9月7日,华为上机题Java实现
2012-09-08 15:58 0第二题: /** * 输入字符串长度len,字符串str, ... -
Java对于Cookie的操作详解
2012-09-18 08:34 7881.设置Cookie Cookie cookie = n ...
相关推荐
通用的netty传输协议 通过该协议进行文件传输 文件传输客户端与服务端 可以根据文件的最后更新时间来增量传输文件 源码开放,通过eclipse或者idea导入代码即可运行 协议开放,协议是自定义的协议,大家可以根据需求...
简单但是内容不浅的netty传输文件的例子,实现客户端和服务器端。全面,5积分绝对值得。本人通过很久测试才完成该简单通俗易懂的例子。 netty版本:4.0.23
通过netty获取文件进度,上传文件的时时数据大小,剩余时间.websocket和HTML结合,并不javascript的轮询获取上传进度,而是通过NIO的推送.
封装NETTY来实现一个分布式文件传输服务,目标是提供定时的可靠安全文件传输。同时提供一种简便的方式,只需将数据配置好
Netty+H5实现实时进度条文件上传,支持断点续传。 1、WebSocketServer:服务启动类 2、服务启动后,浏览器访问http://localhost:9999 3、FileWebSocketFrameHandler类SERVER_SAVE_PATH常量为文件上传保存路经
赠送Maven依赖信息文件:netty-codec-http-4.1.27.Final.pom; 包含翻译后的API文档:netty-codec-http-4.1.27.Final-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.netty:netty-codec-...
赠送Maven依赖信息文件:netty-codec-http-4.1.11.Final.pom; 包含翻译后的API文档:netty-codec-http-4.1.11.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-codec-http:4.1.11.Final; ...
赠送Maven依赖信息文件:netty-codec-http2-4.1.74.Final.pom; 包含翻译后的API文档:netty-codec-http2-4.1.74.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-codec-http2:4.1.74.Final; ...
支持多文件、大文件上传,客户端长连接,只要客户端有文件就通知服务器要发送文件。
赠送Maven依赖信息文件:netty-codec-http-4.1.73.Final.pom; 包含翻译后的API文档:netty-codec-http-4.1.73.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-codec-http:4.1.73.Final; ...
赠送Maven依赖信息文件:reactor-netty-http-1.0.11.pom; 包含翻译后的API文档:reactor-netty-http-1.0.11-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.projectreactor.netty:reactor-netty-http:1.0.11; ...
这个小程序使用netty5进行udp网络通讯,客户端有两种,1:用netty5类库发送DatagramPacket和接收 2:直接使用DatagramSocket发送接收DatagramPacket 先运行netty_server的QuoteOfTheMomentServer, 在运行netty_...
赠送Maven依赖信息文件:netty-codec-http2-4.1.73.Final.pom; 包含翻译后的API文档:netty-codec-http2-4.1.73.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-codec-http2:4.1.73.Final; ...
赠送Maven依赖信息文件:netty-codec-http-4.1.74.Final.pom; 包含翻译后的API文档:netty-codec-http-4.1.74.Final-javadoc-API文档-中文(简体)版.zip; Maven坐标:io.netty:netty-codec-http:4.1.74.Final; ...
赠送Maven依赖信息文件:netty-codec-http-4.1.11.Final.pom; 包含翻译后的API文档:netty-codec-http-4.1.11.Final-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.netty:netty-codec-...
描述文档请看我的个人博客:www.mesoftware.cn
netty file server 文件服务 实现 列表 上传 下载
netty学习文件,实现http,websocket,protobuf方式,实现服务器与客户端通信。
包括netty的文件传输的实例,以及一些netty的简单的实例,里面包含有相对应的jar包,比起那些要5分,然后下下来P都没有的要实惠多了。自己也是新研究的,希望能和大家一起讨论分享
赠送Maven依赖信息文件:netty-codec-http2-4.1.73.Final.pom; 包含翻译后的API文档:netty-codec-http2-4.1.73.Final-javadoc-API文档-中文(简体)-英语-对照版.zip; Maven坐标:io.netty:netty-codec-...