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>
|
<version>4.8.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>1.18.30</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
|
@ -107,40 +101,30 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<!-- 使用maven-jar-plugin和maven-dependency-plugin插件打包 -->
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.10.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<release>17</release>
|
||||||
<manifest>
|
<encoding>utf-8</encoding>
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>lib/</classpathPrefix>
|
|
||||||
<mainClass>com.zhangmeng.minio.MiniToolsApplication</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.openjfx</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>javafx-maven-plugin</artifactId>
|
||||||
<version>3.1.1</version>
|
<version>0.0.8</version>
|
||||||
<executions>
|
<configuration>
|
||||||
<execution>
|
<stripDebug>true</stripDebug>
|
||||||
<id>copy-dependencies</id>
|
<compress>2</compress>
|
||||||
<phase>package</phase>
|
<noHeaderFiles>true</noHeaderFiles>
|
||||||
<goals>
|
<noManPages>true</noManPages>
|
||||||
<goal>copy-dependencies</goal>
|
<launcher>minio manager</launcher>
|
||||||
</goals>
|
<jlinkImageName>minio manager</jlinkImageName>
|
||||||
<configuration>
|
<jlinkZipName>minio-managerZip</jlinkZipName>
|
||||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
<mainClass>com.zhangmeng.minio.MiniToolsApplication</mainClass>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<repositories>
|
<repositories>
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,12 @@
|
||||||
package com.zhangmeng.minio.model;
|
package com.zhangmeng.minio.model;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangmeng
|
* @author zhangmeng
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @date 2024-03-07 16:31
|
* @date 2024-03-07 16:31
|
||||||
*/
|
*/
|
||||||
@Data
|
|
||||||
public class BucketFile {
|
public class BucketFile {
|
||||||
|
|
||||||
private String bucketName;
|
private String bucketName;
|
||||||
|
|
@ -16,4 +14,55 @@ public class BucketFile {
|
||||||
private boolean isDir;
|
private boolean isDir;
|
||||||
private Long size;
|
private Long size;
|
||||||
private String url;
|
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 com.zhangmeng.minio.model.BucketFile;
|
||||||
import io.minio.*;
|
import io.minio.*;
|
||||||
|
import io.minio.errors.*;
|
||||||
import io.minio.http.Method;
|
import io.minio.http.Method;
|
||||||
import io.minio.messages.Bucket;
|
import io.minio.messages.Bucket;
|
||||||
import io.minio.messages.Item;
|
import io.minio.messages.Item;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
import lombok.SneakyThrows;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.tika.Tika;
|
import org.apache.tika.Tika;
|
||||||
import org.apache.tika.exception.TikaException;
|
import org.apache.tika.exception.TikaException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
import java.security.InvalidKeyException;
|
||||||
import java.io.IOException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -77,9 +76,29 @@ public class MinioUtils {
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SneakyThrows(Exception.class)
|
|
||||||
public static List<Bucket> getAllBuckets() {
|
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
|
* @param bucketName
|
||||||
*/
|
*/
|
||||||
@SneakyThrows(Exception.class)
|
|
||||||
public static void createBucket(String bucketName) {
|
public static void createBucket(String bucketName) {
|
||||||
if (!bucketExists(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 {
|
}else {
|
||||||
Platform.runLater(()->{
|
Platform.runLater(()->{
|
||||||
AlertUtils.alert_warning("bucket_name : "+ bucketName + "已存在");
|
AlertUtils.alert_warning("bucket_name : "+ bucketName + "已存在");
|
||||||
|
|
@ -105,9 +143,29 @@ public class MinioUtils {
|
||||||
* @param bucketName
|
* @param bucketName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SneakyThrows(Exception.class)
|
public static Boolean bucketExists(String bucketName) {
|
||||||
public static boolean bucketExists(String bucketName) {
|
try {
|
||||||
return getDefault().bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
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){
|
public String DateFormatString(ZonedDateTime zonedDateTime){
|
||||||
|
|
@ -125,7 +183,6 @@ public class MinioUtils {
|
||||||
* @param recursive 是否使用递归查询
|
* @param recursive 是否使用递归查询
|
||||||
* @return MinioItem 列表
|
* @return MinioItem 列表
|
||||||
*/
|
*/
|
||||||
@SneakyThrows(Exception.class)
|
|
||||||
public static List<Item> getAllObjectsByPrefix(String bucketName,
|
public static List<Item> getAllObjectsByPrefix(String bucketName,
|
||||||
String prefix,
|
String prefix,
|
||||||
boolean recursive) {
|
boolean recursive) {
|
||||||
|
|
@ -134,7 +191,28 @@ public class MinioUtils {
|
||||||
ListObjectsArgs.builder().bucket(bucketName).prefix(prefix).recursive(recursive).build());
|
ListObjectsArgs.builder().bucket(bucketName).prefix(prefix).recursive(recursive).build());
|
||||||
if (objectsIterator != null) {
|
if (objectsIterator != null) {
|
||||||
for (Result<Item> o : objectsIterator) {
|
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);
|
list.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -148,16 +226,35 @@ public class MinioUtils {
|
||||||
* @param objectName
|
* @param objectName
|
||||||
* @return url
|
* @return url
|
||||||
*/
|
*/
|
||||||
@SneakyThrows(Exception.class)
|
|
||||||
public static String getPresignedObjectUrl(String bucketName, String objectName) {
|
public static String getPresignedObjectUrl(String bucketName, String objectName) {
|
||||||
GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder()
|
GetPresignedObjectUrlArgs args = GetPresignedObjectUrlArgs.builder()
|
||||||
.bucket(bucketName)
|
.bucket(bucketName)
|
||||||
.object(objectName)
|
.object(objectName)
|
||||||
.method(Method.GET).build();
|
.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){
|
public static List<BucketFile> getFileList(String bucketName){
|
||||||
List<Item> itemList = getAllObjectsByPrefix(bucketName, null, true);
|
List<Item> itemList = getAllObjectsByPrefix(bucketName, null, true);
|
||||||
List<BucketFile> list = new ArrayList<>();
|
List<BucketFile> list = new ArrayList<>();
|
||||||
|
|
@ -199,16 +296,45 @@ public class MinioUtils {
|
||||||
* @param contentType 类型
|
* @param contentType 类型
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SneakyThrows(Exception.class)
|
|
||||||
public static ObjectWriteResponse uploadFile(String bucketName, File file, String objectName, String contentType) {
|
public static ObjectWriteResponse uploadFile(String bucketName, File file, String objectName, String contentType) {
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
FileInputStream inputStream = null;
|
||||||
return minioClient.putObject(
|
try {
|
||||||
PutObjectArgs.builder()
|
inputStream = new FileInputStream(file);
|
||||||
.bucket(bucketName)
|
return minioClient.putObject(
|
||||||
.object(objectName)
|
PutObjectArgs.builder()
|
||||||
.contentType(contentType)
|
.bucket(bucketName)
|
||||||
.stream(inputStream,inputStream.available(), -1)
|
.object(objectName)
|
||||||
.build());
|
.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.controls;
|
||||||
requires javafx.base;
|
requires javafx.base;
|
||||||
requires minio;
|
requires minio;
|
||||||
requires lombok;
|
|
||||||
requires com.fasterxml.jackson.core;
|
requires com.fasterxml.jackson.core;
|
||||||
requires tika.core;
|
requires tika.core;
|
||||||
requires org.apache.commons.lang3;
|
requires org.apache.commons.lang3;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue