package com.eagle.file.client;
import com.eagle.file.common.CmdMap;
import com.eagle.file.common.Constants;
import com.eagle.file.common.HandlerMap;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.stream.ChunkedWriteHandler;
/**
* Created by zhangwenhui on 16/12/20.
*/
public class ClientCmdHandler extends ChannelHandlerAdapter {
private String cmd;
private String path;
public ClientCmdHandler(String cmd,String path){
this.cmd = cmd;
this.path = path;
}
public void channelActive(ChannelHandlerContext ctx) throws Exception {
if(cmd.equals(CmdMap.LS.getCode())){
ctx.pipeline().addLast(HandlerMap.LS.getCode(),new ClientLsHandler(path));
ctx.writeAndFlush(CmdMap.LS.getCode()+Constants.CHAR_SPLIT_CMD+path);
ctx.pipeline().remove(HandlerMap.CMD.getCode());
}else if(cmd.equals(CmdMap.UPLOAD.getCode())){
ctx.pipeline().addLast(HandlerMap.CHUNKEDWRITE.getCode(),new ChunkedWriteHandler());
ctx.pipeline().addLast(HandlerMap.HTTPOBJECTAGGREGATOR.getCode(),new HttpObjectAggregator(64*1024));
ctx.pipeline().addLast(HandlerMap.UPLOAD.getCode(),new ClientUploadHandler(path));
ctx.fireChannelActive();
ctx.writeAndFlush(CmdMap.UPLOAD.getCode()+Constants.CHAR_SPLIT_CMD+path);
}else if(cmd.equals(CmdMap.DOWNLOAD.getCode())){
ctx.pipeline().addLast(HandlerMap.CHUNKEDWRITE.getCode(),new ChunkedWriteHandler());
ctx.pipeline().addLast(HandlerMap.HTTPOBJECTAGGREGATOR.getCode(),new HttpObjectAggregator(64*1024));
ctx.pipeline().addLast(HandlerMap.DOWNLOAD.getCode(),new ClientDownloadHandler(path));
ctx.fireChannelActive();
ctx.writeAndFlush(CmdMap.DOWNLOAD.getCode()+Constants.CHAR_SPLIT_CMD+path);
ctx.pipeline().remove(HandlerMap.STRINGDECODER.getCode());
ctx.pipeline().remove(HandlerMap.STRINGENCODER.getCode());
ctx.pipeline().remove(HandlerMap.CMD.getCode());
}
}
public void channelRead(ChannelHandlerContext ctx,Object msg) throws Exception {
if(cmd.equals(CmdMap.UPLOAD.getCode())){
ctx.pipeline().remove(HandlerMap.STRINGDECODER.getCode());
ctx.pipeline().remove(HandlerMap.STRINGENCODER.getCode());
ctx.pipeline().remove(HandlerMap.CMD.getCode());
ctx.fireChannelRead(msg);
}
}
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
ctx.close();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
NettyFileServer.rar (47个子文件)
NettyFileServer
src
test
java
main
resources
java
com
eagle
file
common
CmdMap.java 776B
Constants.java 442B
HandlerMap.java 1KB
client
ClientLsHandler.java 808B
ClientCmdHandler.java 3KB
FileClient.java 1KB
ClientUploadHandler.java 1KB
ClientDownloadHandler.java 2KB
ClientChildChannelHandler.java 2KB
ClientBootStart.java 452B
server
ServerBootStart.java 380B
ServerUploadHandler.java 2KB
ServerDownloadHandler.java 1KB
ServerLsHandler.java 2KB
ServerCmdHandler.java 2KB
FileServer.java 1KB
ServerChildChannelHandler.java 2KB
lib
netty-all-5.0.0.Alpha1.jar 1.5MB
target
generated-sources
annotations
classes
com
eagle
file
common
HandlerMap.class 2KB
CmdMap.class 2KB
Constants.class 740B
client
ClientBootStart.class 991B
ClientDownloadHandler.class 3KB
ClientUploadHandler.class 2KB
ClientLsHandler.class 1KB
ClientCmdHandler.class 3KB
ClientChildChannelHandler.class 2KB
FileClient.class 2KB
ClientUploadHandler$1.class 2KB
ClientUploadHandler$1$1.class 1KB
server
ServerDownloadHandler$1$1.class 1KB
FileServer.class 2KB
ServerChildChannelHandler.class 3KB
ServerLsHandler.class 3KB
ServerBootStart.class 843B
ServerCmdHandler.class 3KB
ServerUploadHandler.class 3KB
ServerDownloadHandler.class 2KB
ServerDownloadHandler$1.class 2KB
.idea
libraries
Maven__org_json_json_20090211.xml 473B
misc.xml 1KB
compiler.xml 1KB
workspace.xml 51KB
modules.xml 270B
copyright
profiles_settings.xml 76B
pom.xml 1KB
NettyFileServer.iml 1KB
共 47 条
- 1
资源评论
happyzwh
- 粉丝: 72
- 资源: 126
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功