同步操作将从 Rainy/DocSys 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package com.DocSystem.commonService;import java.io.IOException;import java.io.InputStream;import java.net.ServerSocket;import java.net.Socket;import java.util.Date;import java.util.List;import java.util.concurrent.ConcurrentHashMap;import org.springframework.beans.factory.annotation.Autowired;import com.DocSystem.entity.DocShare;import com.DocSystem.service.impl.ReposServiceImpl;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONObject;public class ProxyThread extends Thread {@Autowiredprotected ReposServiceImpl reposService;boolean stopProxyThread = false;protected static ConcurrentHashMap<String, Socket> proxiedServer = new ConcurrentHashMap<String, Socket>();public void run(){//打印线程信息String name = Thread.currentThread().getName();String inf=Thread.currentThread().toString();long idnum = Thread.currentThread().getId();System.out.println("ProxyThread: thread name=="+ name +",threadid=="+ idnum+",thread inf=="+inf);//开始监听指定端口上的socket连接int port = 55533;ServerSocket server;try {server = new ServerSocket(port);while(!stopProxyThread){System.out.println("server将一直等待连接的到来");Socket socket = server.accept();if(verifyShareRequest(socket) == true){//push socket to HashMapString shareServerIP = getShareServerIpFromSocket(socket);if(shareServerIP != null){if(proxiedServer.get(shareServerIP) == null){proxiedServer.put(shareServerIP, socket);}}else{socket.close();}}}server.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}private boolean verifyShareRequest(Socket socket) {InputStream inputStream;try {inputStream = socket.getInputStream();byte[] bytes = new byte[1024];int len;StringBuilder sb = new StringBuilder();while ((len = inputStream.read(bytes)) != -1){sb.append(new String(bytes, 0, len,"UTF-8"));}System.out.println("get message from client: " + sb);inputStream.close();//check the requestJSONObject jobj = JSON.parseObject(sb.toString());Integer shareId = (Integer) jobj.get("shareId");if(shareId == null){return false;}DocShare docShare = getDocShare(shareId);if(isDocShareValid(docShare) == false){return false;}return true;} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}return false;}private boolean isDocShareValid(DocShare docShare) {if(docShare == null){System.out.println("verifyDocShare() docShare is null");return false;}if(docShare.getVid() == null){System.out.println("verifyDocShare() docShare.vid is null");return false;}if(docShare.getDocId() == null){System.out.println("verifyDocShare() docShare.docId is null");return false;}if(docShare.getPath() == null){System.out.println("verifyDocShare() docShare.path is null");return false;}if(docShare.getName() == null){System.out.println("verifyDocShare() docShare.name is null");return false;}if(docShare.getSharedBy() == null){System.out.println("verifyDocShare() docShare.sharedBy is null");return false;}Long expireTime = docShare.getExpireTime();if(expireTime != null){long curTime = new Date().getTime();if(curTime > expireTime) //{System.out.println("verifyDocShare() docShare is expired");return false;}}return true;}protected DocShare getDocShare(Integer shareId) {DocShare qDocShare = new DocShare();qDocShare.setShareId(shareId);List<DocShare> results = reposService.getDocShareList(qDocShare);if(results == null || results.size() < 1){return null;}return results.get(0);}private String getShareServerIpFromSocket(Socket socket) {//System.out.println(socket.getLocalSocketAddress().toString());String clientIP = socket.getInetAddress().toString();System.out.println(socket.getInetAddress().toString()); //客户端IP//System.out.println(socket.getLocalAddress().toString());//System.out.println(socket.getRemoteSocketAddress().toString());//System.out.println(socket.getLocalSocketAddress().toString());return clientIP;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。