From 1d97a816fda0cf2f78be101ad315c10325dd0210 Mon Sep 17 00:00:00 2001
From: zm <1334717033@qq.com>
Date: Sun, 10 Mar 2024 18:30:33 +0800
Subject: [PATCH] =?UTF-8?q?2024=E5=B9=B43=E6=9C=8810=E6=97=A518:30:23?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 50 ++---
.../com/zhangmeng/minio/model/BucketFile.java | 55 +++++-
.../com/zhangmeng/minio/utils/MinioUtils.java | 178 +++++++++++++++---
src/main/java/module-info.java | 1 -
4 files changed, 221 insertions(+), 63 deletions(-)
diff --git a/pom.xml b/pom.xml
index 9ec2759..bf13f3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,12 +27,6 @@
4.8.1
-
- org.projectlombok
- lombok
- 1.18.30
-
-
org.apache.commons
commons-lang3
@@ -107,40 +101,30 @@
-
-
org.apache.maven.plugins
- maven-jar-plugin
- 3.1.0
+ maven-compiler-plugin
+ 3.10.0
-
-
- true
- lib/
- com.zhangmeng.minio.MiniToolsApplication
-
-
+ 17
+ utf-8
- org.apache.maven.plugins
- maven-dependency-plugin
- 3.1.1
-
-
- copy-dependencies
- package
-
- copy-dependencies
-
-
- ${project.build.directory}/lib
-
-
-
+ org.openjfx
+ javafx-maven-plugin
+ 0.0.8
+
+ true
+ 2
+ true
+ true
+ minio manager
+ minio manager
+ minio-managerZip
+ com.zhangmeng.minio.MiniToolsApplication
+
-
diff --git a/src/main/java/com/zhangmeng/minio/model/BucketFile.java b/src/main/java/com/zhangmeng/minio/model/BucketFile.java
index ee5ce33..7e51441 100644
--- a/src/main/java/com/zhangmeng/minio/model/BucketFile.java
+++ b/src/main/java/com/zhangmeng/minio/model/BucketFile.java
@@ -1,14 +1,12 @@
package com.zhangmeng.minio.model;
-import lombok.AllArgsConstructor;
-import lombok.Data;
/**
* @author zhangmeng
* @version 1.0
* @date 2024-03-07 16:31
*/
-@Data
+
public class BucketFile {
private String bucketName;
@@ -16,4 +14,55 @@ public class BucketFile {
private boolean isDir;
private Long size;
private String url;
+
+ public BucketFile() {
+ }
+
+ public BucketFile(String bucketName, String fileName, boolean isDir, Long size, String url) {
+ this.bucketName = bucketName;
+ this.fileName = fileName;
+ this.isDir = isDir;
+ this.size = size;
+ this.url = url;
+ }
+
+ public String getBucketName() {
+ return bucketName;
+ }
+
+ public void setBucketName(String bucketName) {
+ this.bucketName = bucketName;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public boolean isDir() {
+ return isDir;
+ }
+
+ public void setDir(boolean dir) {
+ isDir = dir;
+ }
+
+ public Long getSize() {
+ return size;
+ }
+
+ public void setSize(Long size) {
+ this.size = size;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
}
diff --git a/src/main/java/com/zhangmeng/minio/utils/MinioUtils.java b/src/main/java/com/zhangmeng/minio/utils/MinioUtils.java
index daf42b1..bd37bfb 100644
--- a/src/main/java/com/zhangmeng/minio/utils/MinioUtils.java
+++ b/src/main/java/com/zhangmeng/minio/utils/MinioUtils.java
@@ -2,20 +2,19 @@ package com.zhangmeng.minio.utils;
import com.zhangmeng.minio.model.BucketFile;
import io.minio.*;
+import io.minio.errors.*;
import io.minio.http.Method;
import io.minio.messages.Bucket;
import io.minio.messages.Item;
import javafx.application.Platform;
import javafx.scene.control.TextField;
-import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.tika.Tika;
import org.apache.tika.exception.TikaException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -77,9 +76,29 @@ public class MinioUtils {
*
* @return
*/
- @SneakyThrows(Exception.class)
public static List getAllBuckets() {
- return getDefault().listBuckets();
+ try {
+ return getDefault().listBuckets();
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ }
+ return null;
}
/**
@@ -88,10 +107,29 @@ public class MinioUtils {
*
* @param bucketName
*/
- @SneakyThrows(Exception.class)
public static void createBucket(String bucketName) {
if (!bucketExists(bucketName)) {
- getDefault().makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+ try {
+ getDefault().makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ }
}else {
Platform.runLater(()->{
AlertUtils.alert_warning("bucket_name : "+ bucketName + "已存在");
@@ -105,9 +143,29 @@ public class MinioUtils {
* @param bucketName
* @return
*/
- @SneakyThrows(Exception.class)
- public static boolean bucketExists(String bucketName) {
- return getDefault().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+ public static Boolean bucketExists(String bucketName) {
+ try {
+ return getDefault().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ }
+ return null;
}
public String DateFormatString(ZonedDateTime zonedDateTime){
@@ -125,7 +183,6 @@ public class MinioUtils {
* @param recursive 是否使用递归查询
* @return MinioItem 列表
*/
- @SneakyThrows(Exception.class)
public static List- getAllObjectsByPrefix(String bucketName,
String prefix,
boolean recursive) {
@@ -134,7 +191,28 @@ public class MinioUtils {
ListObjectsArgs.builder().bucket(bucketName).prefix(prefix).recursive(recursive).build());
if (objectsIterator != null) {
for (Result
- o : objectsIterator) {
- Item item = o.get();
+ Item item = null;
+ try {
+ item = o.get();
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ }
list.add(item);
}
}
@@ -148,16 +226,35 @@ public class MinioUtils {
* @param objectName
* @return url
*/
- @SneakyThrows(Exception.class)
public static String getPresignedObjectUrl(String bucketName, String objectName) {
GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder()
.bucket(bucketName)
.object(objectName)
.method(Method.GET).build();
- return getDefault() .getPresignedObjectUrl(args);
+ try {
+ return getDefault() .getPresignedObjectUrl(args);
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ }
+ return null;
}
- @SneakyThrows(Exception.class)
public static List getFileList(String bucketName){
List
- itemList = getAllObjectsByPrefix(bucketName, null, true);
List list = new ArrayList<>();
@@ -199,16 +296,45 @@ public class MinioUtils {
* @param contentType 类型
* @return
*/
- @SneakyThrows(Exception.class)
public static ObjectWriteResponse uploadFile(String bucketName, File file, String objectName, String contentType) {
- FileInputStream inputStream = new FileInputStream(file);
- return minioClient.putObject(
- PutObjectArgs.builder()
- .bucket(bucketName)
- .object(objectName)
- .contentType(contentType)
- .stream(inputStream,inputStream.available(), -1)
- .build());
+ FileInputStream inputStream = null;
+ try {
+ inputStream = new FileInputStream(file);
+ return minioClient.putObject(
+ PutObjectArgs.builder()
+ .bucket(bucketName)
+ .object(objectName)
+ .contentType(contentType)
+ .stream(inputStream,inputStream.available(), -1)
+ .build());
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (ServerException e) {
+ e.printStackTrace();
+ } catch (InsufficientDataException e) {
+ e.printStackTrace();
+ } catch (ErrorResponseException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (InvalidResponseException e) {
+ e.printStackTrace();
+ } catch (XmlParserException e) {
+ e.printStackTrace();
+ } catch (InternalException e) {
+ e.printStackTrace();
+ } finally {
+ if (inputStream != null){
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return null;
}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 20ba2bc..b6003eb 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -8,7 +8,6 @@ open module javafx.tools.minio {
requires javafx.controls;
requires javafx.base;
requires minio;
- requires lombok;
requires com.fasterxml.jackson.core;
requires tika.core;
requires org.apache.commons.lang3;