📄 informationprocessing.java
字号:
/**
*
*/
package com.sincere.utils.timer;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.Socket;
import java.util.Date;
import java.util.UUID;
import com.sincere.utils.ZipTool;
/**
* @author Administrator
* 信息处理线程
*/
public class InformationProcessing extends Thread {
Socket mySocket;
String strSavePath = "";//解压文件保存路径
/**
* 信息处理线程
* @param mySocket 要处理的Socket
* @param strSavePath 解压文件保存路径
*/
public InformationProcessing(Socket mySocket, String strSavePath){
super();
this.mySocket = mySocket;
this.strSavePath = strSavePath;
System.out.println(">>启动信息处理线程."+new Date().toString());
}
/* (non-Javadoc)
* @see java.lang.Thread#run()
*/
@Override
public void run() {
long bTime = System.currentTimeMillis();
try{
BufferedInputStream bis = new java.io.BufferedInputStream(mySocket.getInputStream());//输入流
//BufferedOutputStream bos = new java.io.BufferedOutputStream(mySocket.getOutputStream());//输出流
String strZipFilePath = strSavePath+File.separator+"zip"+File.separator;
File zipDirectory = new File(strZipFilePath);//压缩包文件保存目录
if(!zipDirectory.exists()){
zipDirectory.mkdirs();
}
String strZipFileName = "ZIP_"+UUID.randomUUID().toString()+".zip";
File zipFile = new File(strZipFilePath + strZipFileName);
if(!zipFile.exists()){
zipFile.createNewFile();
}
BufferedOutputStream zipFileBOS = new java.io.BufferedOutputStream(new FileOutputStream(zipFile));//输出流
//接收文件
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
zipFileBOS.write(buff, 0, bytesRead);
}
zipFileBOS.close();
bis.close();
//bos.close();
mySocket.close();
//从zip文件压缩包里面解压文件,保存到指定目录
ZipTool zipTool = new ZipTool();
zipTool.decompressFile(zipFile.getPath(), strSavePath);
//删除压缩文件
zipFile.delete();
}catch(Exception e){
System.out.println(">>信息处理线程发生异常:"+new Date().toString());
e.printStackTrace();
}finally{
System.out.println("<<服务结束:"+new Date().toString());
System.out.println("<<用时:"+(System.currentTimeMillis()-bTime));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -