文件解压专题:支持Gzip、Rar5、rar、7z、tar.gz、zip
POM依赖
<dependency>
<groupId>net.sf.sevenzipjbinding</groupId>
<artifactId>sevenzipjbinding</artifactId>
<version>16.02-2.01</version>
</dependency>
<dependency>
<groupId>net.sf.sevenzipjbinding</groupId>
<artifactId>sevenzipjbinding-all-platforms</artifactId>
<version>16.02-2.01</version>
</dependency>
工具类
public class ProjectUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectUtils.class);
private static Set<String> suffixSet;
private long maxUncompressedSize = 5120;
static {
suffixSet = Arrays.stream("zip,rar,gz,7z".split(",")).collect(Collectors.toSet());
}
public boolean compareToMaxUnSize(long fileSize) {
return fileSize > getSizeByte(maxUncompressedSize);
}
public long getSizeByte(long size) {
return (long) (size * Constants.TRANSLATING_SIZE);
}
public boolean isNotNormFileSuffix(String fileName) {
if (StringUtils.isBlank(fileName)) {
return true;
}
String suffix = fileName.substring(fileName.lastIndexOf(Constants.DOT) + 1);
return !suffixSet.contains(suffix.toLowerCase(Locale.US));
}
public long getTimestamp() {
return System.currentTimeMillis();
}
public void deleteTemFile(File taskFiles) {
if (!taskFiles.exists()) {
return;
}
try {
FileUtils.forceDelete(taskFiles);
} catch (IOException e) {
LOGGER.info("Delete temp file false. msg: {}", e.getMessage());
}
}
}
解压接口定义
public interface UploadService {
String ENCODING_GBK = "GBK";
String TAR_GZ = "tar.gz";
String GZ = ".gz";
boolean isOwn(FileType fileType);