最后
学习视频:
大厂面试真题:
WebCompressUtil 工具类代码
======================
import io.minio.MinioClient;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.springframework.web.multipart.MultipartFile;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
- web 压缩解压工具
*/
public class WebCompressUtil {
private static final int BUFFER_SIZE = 2048;
public static List unTar(InputStream in,MinioClient minioClient,String bucketName,String parentDir) {
List fileNames = new ArrayList();
try {
TarArchiveInputStream tarIn = new TarArchiveInputStream(in, BUFFER_SIZE);
while (tarIn.getNextTarEntry() != null) {
TarArchiveEntry entry = tarIn.getNextTarEntry();
if (entry.isFile()) {
minioClient.putObject(bucketName, parentDir+entry.getName(), tarIn, entry.getSize(), null, null, null);
fileNames.add(parentDir+entry.getName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return fileNames;
}
public static List unZip(InputStream in,MinioClient minioClient,String bucketName,String parentDir) {
List fileNames = new ArrayList();
try {
// 创建客户端
ZipArchiveInputStream is = new ZipArchiveInputStream(new BufferedInputStream(in, BUFFER_SIZE));
ZipArchiveEntry entry = null;
while ((entry = is.getNextZipEntry()) != null) {
if (!entry.isDirectory()) {
try {
// 使用putObject上传一个文件到存储桶中。
minioClient.putObject(bucketName,parentDir+entry.getName() , is, entry.getSize(), null, null, null);
} catch (Exception e) {
e.printStackTrace();
}
fileNames.add(parentDir+entry.getName());
}
}
} catch (Exception e) {
e.printStackTrace();
}
return fileNames;
}
/**
-
解压方法
-
@param file 解压文件
-
@return
-
@throws Exception
*/
public static List unCompress(MultipartFile file,MinioClient minioClient,String bucketName,String parentDir){
List ret = new ArrayList();
try {
String fileName=file.getOriginalFilename();
String upperName = fileName.toUpperCase();
if (upperName.endsWith(“.ZIP”)) {
ret = unZip(file.getInputStream(),minioClient,bucketName, parentDir);
最后总结
搞定算法,面试字节再不怕,有需要文章中分享的这些二叉树、链表、字符串、栈和队列等等各大面试高频知识点及解析
最后再分享一份终极手撕架构的大礼包(学习笔记):分布式+微服务+开源框架+性能优化
NG开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)收录**