删除多余类,引入rar包

This commit is contained in:
马超 2020-08-06 13:46:19 +08:00
parent de2550b892
commit ca2b6b2d2b
3 changed files with 93 additions and 79 deletions

View File

@ -14,7 +14,11 @@
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.github.junrar</groupId>
<artifactId>junrar</artifactId>
<version>7.3.0</version>
</dependency>
<!-- spring boot依赖包-->
<dependency>

View File

@ -1,64 +0,0 @@
package com.qiwenshare.common.domain;
import javax.persistence.*;
/**
* 代理实体类
*/
public class ProxyBean {
private long proxyid;
private String proxyip;
private int proxyport;
private int testresult;
private String testtime;
public ProxyBean(){
}
public ProxyBean(String proxyip, int proxyport) {
this.proxyip = proxyip;
this.proxyport = proxyport;
}
public String getProxyip() {
return proxyip;
}
public void setProxyip(String proxyip) {
this.proxyip = proxyip;
}
public long getProxyid() {
return proxyid;
}
public void setProxyid(long proxyid) {
this.proxyid = proxyid;
}
public int getProxyport() {
return proxyport;
}
public void setProxyport(int proxyport) {
this.proxyport = proxyport;
}
public int getTestresult() {
return testresult;
}
public void setTestresult(int testresult) {
this.testresult = testresult;
}
public String getTesttime() {
return testtime;
}
public void setTesttime(String testtime) {
this.testtime = testtime;
}
}

View File

@ -1,5 +1,7 @@
package com.qiwenshare.common.operation;
import com.github.junrar.Archive;
import com.github.junrar.rarfile.FileHeader;
import com.qiwenshare.common.util.FileUtil;
import com.qiwenshare.common.util.PathUtil;
import org.slf4j.Logger;
@ -16,6 +18,7 @@ import java.util.zip.ZipFile;
*/
public class FileOperation {
private static Logger logger = LoggerFactory.getLogger(FileOperation.class);
/**
* 创建文件
*
@ -29,6 +32,7 @@ public class FileOperation {
/**
* 删除文件
*
* @param file 文件
* @return 是否删除成功
*/
@ -42,10 +46,10 @@ public class FileOperation {
}
if (file.isFile()){
if (file.isFile()) {
return file.delete();
} else {
for (File newfile: file.listFiles()){
for (File newfile : file.listFiles()) {
deleteFile(newfile);
}
}
@ -54,6 +58,7 @@ public class FileOperation {
/**
* 删除文件
*
* @param fileUrl 文件路径
* @return 删除是否成功
*/
@ -70,7 +75,7 @@ public class FileOperation {
*/
public static long getFileSize(String fileUrl) {
File file = newFile(fileUrl);
if (file.exists()){
if (file.exists()) {
return file.length();
}
return 0;
@ -91,6 +96,7 @@ public class FileOperation {
/**
* 创建目录
*
* @param file 文件
* @return 是否创建成功
*/
@ -108,6 +114,7 @@ public class FileOperation {
/**
* 创建目录
*
* @param fileUrl 文件路径
* @return 是否创建成功
*/
@ -125,7 +132,8 @@ public class FileOperation {
/**
* 拷贝文件
* @param fileInputStream 文件输入流
*
* @param fileInputStream 文件输入流
* @param fileOutputStream 文件输出流
* @throws IOException io异常
*/
@ -166,7 +174,8 @@ public class FileOperation {
/**
* 拷贝文件
* @param src 源文件
*
* @param src 源文件
* @param dest 目的文件
* @throws IOException io异常
*/
@ -181,7 +190,8 @@ public class FileOperation {
/**
* 拷贝文件
* @param srcUrl 源路径
*
* @param srcUrl 源路径
* @param destUrl 目的路径
* @throws IOException io异常
*/
@ -196,26 +206,27 @@ public class FileOperation {
/**
* 文件解压缩
* @param file 需要解压的文件
*
* @param sourceFile 需要解压的文件
* @param destDirPath 目的路径
* @return 解压目录列表
*/
public static List<String> unzip(File file, String destDirPath) {
public static List<String> unzip(File sourceFile, String destDirPath) {
ZipFile zipFile = null;
Set<String> set = new HashSet<String>();
// set.add("/");
List<String> fileEntryNameList = new ArrayList<>();
try {
zipFile = new ZipFile(file);
zipFile = new ZipFile(sourceFile);
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
String[] nameStrArr = entry.getName().split("/");
String nameStr = "/";
for (int i = 0; i < nameStrArr.length; i++){
if (!"".equals(nameStrArr[i])){
nameStr =nameStr + "/" + nameStrArr[i];
for (int i = 0; i < nameStrArr.length; i++) {
if (!"".equals(nameStrArr[i])) {
nameStr = nameStr + "/" + nameStrArr[i];
set.add(nameStr);
}
@ -263,10 +274,73 @@ public class FileOperation {
}
}
List<String> res = new ArrayList<>(set);
return res ;
return res;
}
public static long deleteFileFromDisk(String fileurl){
/**
* 解压rar
*
* @param sourceFile 需要解压的文件
* @param destDirPath 目的路径
* @throws Exception
*/
public static void unrar(File sourceFile, String destDirPath) throws Exception {
File destDir = new File(destDirPath);
Archive archive = null;
FileOutputStream fos = null;
System.out.println("Starting 开始解压...");
try {
archive = new Archive(sourceFile);
FileHeader fh = archive.nextFileHeader();
int count = 0;
File destFileName = null;
while (fh != null) {
System.out.println((++count) + ") " + fh.getFileName());
String compressFileName = fh.getFileName().trim();
destFileName = new File(destDir.getAbsolutePath() + "/" + compressFileName);
if (fh.isDirectory()) {
if (!destFileName.exists()) {
destFileName.mkdirs();
}
fh = archive.nextFileHeader();
continue;
}
if (!destFileName.getParentFile().exists()) {
destFileName.getParentFile().mkdirs();
}
fos = new FileOutputStream(destFileName);
archive.extractFile(fh, fos);
fos.close();
fos = null;
fh = archive.nextFileHeader();
}
archive.close();
archive = null;
System.out.println("Finished 解压完成!");
} catch (Exception e) {
throw e;
} finally {
if (fos != null) {
try {
fos.close();
fos = null;
} catch (Exception e) {
}
}
if (archive != null) {
try {
archive.close();
archive = null;
} catch (Exception e) {
}
}
}
}
public static long deleteFileFromDisk(String fileurl) {
String fileUrl = PathUtil.getStaticPath() + fileurl;
String extendName = FileUtil.getFileType(fileUrl);
String minFileUrl = fileUrl.replace("." + extendName, "_min." + extendName);