use of com.generallycloud.baseio.container.FileReceiveUtil in project baseio by generallycloud.
the class TestDownload method main.
public static void main(String[] args) throws Exception {
String serviceName = "TestDownloadServlet";
String fileName = "upload-flashmail-2.4.exe";
JSONObject j = new JSONObject();
j.put(FileReceiveUtil.FILE_NAME, fileName);
LoggerFactory.configure();
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
FixedSession session = new FixedSession(connector.connect());
final FileReceiveUtil fileReceiveUtil = new FileReceiveUtil("download-");
session.listen(serviceName, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
try {
fileReceiveUtil.accept(session, (ParamedProtobaseFuture) future, false);
} catch (Exception e) {
DebugUtil.debug(e);
}
}
});
long old = System.currentTimeMillis();
session.write(serviceName, j.toJSONString());
System.out.println("Time:" + (System.currentTimeMillis() - old));
ThreadUtil.sleep(5000);
CloseUtil.close(connector);
}
Aggregations