作者:多米音乐_35794462 | 来源:互联网 | 2023-07-30 15:09
如何使用:FIeViewer.getListFiles在java获取文件夹下的所有文和大小publicstaticvoidmain(String[]args){Str
如何使用:FIeViewer.getListFiles在java获取文件夹下的所有文和大小
public static void main(String[] args) {String ip &#61;"162.245.236.170";String accKey &#61;"HSCBKASDKLKL";String serKey &#61; "ASNXCJNASJnjksancascjnkjasc";MinioUtil minioUtil &#61; new MinioUtil(ip,accKey,serKey);String m3u8RootPath &#61;"C:\\Users\\NING MEI\\Desktop\\FFmpeg切片测试";String filmId &#61; "hawhauha";List<String> listFiles &#61; FileViewer.getListFiles(m3u8RootPath, "", true);System.out.println(GsonUtils.toJson(listFiles));startPoll(listFiles,minioUtil,filmId);}
package com.TKW.Minio;import io.minio.MinioClient;
import io.minio.errors.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParserException;import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;public class MinioUtil {private static Logger log &#61; LoggerFactory.getLogger(MinioUtil.class);private static MinioClient minioclient;public MinioUtil(String END_POINT,String ACCESS_KEY, String SECRET_KEY) {String ip &#61; "http://"&#43; END_POINT&#43;":9000";try {minioclient &#61; new MinioClient(ip,ACCESS_KEY,SECRET_KEY);} catch (InvalidEndpointException e) {e.printStackTrace();} catch (InvalidPortException e) {e.printStackTrace();}}public void push(String packageName, String fileName, String suffix, String fileUrl) throws IOException, InvalidKeyException, NoSuchAlgorithmException, InsufficientDataException, InvalidArgumentException, InternalException, NoResponseException, InvalidBucketNameException, XmlPullParserException, ErrorResponseException {try {boolean isExist &#61;minioclient.bucketExists(packageName);if (isExist){log.info(packageName&#43;"已经存在了");}else {minioclient.makeBucket(packageName);}}catch (Exception e){log.error(e.getMessage());}minioclient.putObject(packageName,fileName&#43;"."&#43;suffix,fileUrl);log.info(fileUrl&#43;fileName&#43;"."&#43;suffix&#43;"插入成功");}public static void startPoll(List<String> list, MinioUtil minioUtil, String filmId){int length &#61; list.size();int num &#61; 5; if(num > length){num &#61; length;}int baseNum &#61; length / num;int remainderNum &#61; length % num;int end &#61; 0;for (int i &#61; 0; i < num; i&#43;&#43;) {int start &#61; end ;end &#61; start &#43; baseNum;if(i &#61;&#61; (num-1)){end &#61; length;}else if( i < remainderNum){end &#61; end &#43; 1;}HandleThread thread &#61; new HandleThread("线程[" &#43; (i &#43; 1) &#43; "] ", list, start , end,minioUtil,filmId);thread.start();}}public static class HandleThread extends Thread {private String threadName;private List<String> list;private int startIndex;private int endIndex;private MinioUtil minioUtil;private String filmId;public HandleThread(String threadName, List<String> list, int startIndex, int endIndex,MinioUtil minioUtil,String filmId) {this.threadName &#61; threadName;this.list &#61; list;this.startIndex &#61; startIndex;this.endIndex &#61; endIndex;this.minioUtil &#61;minioUtil;this.filmId &#61;filmId;}public void run() {long startTime &#61; System.currentTimeMillis(); List<String> subList &#61; list.subList(startIndex, endIndex);for (int i &#61; startIndex; i < endIndex; i&#43;&#43;) {try {minioUpload(list.get(i),minioUtil,filmId);} catch (Exception e) {e.printStackTrace();}}System.out.println(threadName&#43;"处理了"&#43;subList.size()&#43;"条&#xff01;startIndex:"&#43;startIndex&#43;"|endIndex:"&#43;endIndex);long endTime &#61; System.currentTimeMillis(); System.out.println("程序运行时间&#xff1a;" &#43; (endTime - startTime) &#43; "ms"); }}public static void minioUpload(String file,MinioUtil minioUtil,String filmId) throws IOException, XmlPullParserException, NoSuchAlgorithmException, InvalidKeyException, InvalidArgumentException, ErrorResponseException, NoResponseException, InvalidBucketNameException, InsufficientDataException, InternalException {String spit &#61;"";if (file.contains("/")){spit &#61;"/";}else if (file.contains("\\")){spit &#61; "\\";}String nameSuffix &#61; file.substring(file.lastIndexOf(spit) &#43; 1);String name &#61; nameSuffix.substring(0, nameSuffix.lastIndexOf("."));String suffix &#61; nameSuffix.substring(nameSuffix.lastIndexOf(".") &#43; 1);System.out.println("开始上传&#43;" &#43; name);minioUtil.push("film", filmId &#43; "/" &#43; name, suffix, file);}}