2024年3月10日18:30:23
parent
46d1bd7e63
commit
1d97a816fd
50
pom.xml
50
pom.xml
|
|
@ -27,12 +27,6 @@
|
|||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.30</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
|
@ -107,40 +101,30 @@
|
|||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<!-- 使用maven-jar-plugin和maven-dependency-plugin插件打包 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.10.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<addClasspath>true</addClasspath>
|
||||
<classpathPrefix>lib/</classpathPrefix>
|
||||
<mainClass>com.zhangmeng.minio.MiniToolsApplication</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<release>17</release>
|
||||
<encoding>utf-8</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.8</version>
|
||||
<configuration>
|
||||
<stripDebug>true</stripDebug>
|
||||
<compress>2</compress>
|
||||
<noHeaderFiles>true</noHeaderFiles>
|
||||
<noManPages>true</noManPages>
|
||||
<launcher>minio manager</launcher>
|
||||
<jlinkImageName>minio manager</jlinkImageName>
|
||||
<jlinkZipName>minio-managerZip</jlinkZipName>
|
||||
<mainClass>com.zhangmeng.minio.MiniToolsApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Bucket> 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<Item> 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<Item> 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<BucketFile> getFileList(String bucketName){
|
||||
List<Item> itemList = getAllObjectsByPrefix(bucketName, null, true);
|
||||
List<BucketFile> 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue