영상관리파일싱크 추가
This commit is contained in:
@@ -2,7 +2,6 @@ package com.kamco.cd.kamcoback.common.utils;
|
||||
|
||||
import static java.lang.String.CASE_INSENSITIVE_ORDER;
|
||||
|
||||
import com.kamco.cd.kamcoback.scheduler.dto.FileDto;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
@@ -162,7 +161,7 @@ public class FIleChecker {
|
||||
// 윈도우용
|
||||
|
||||
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
|
||||
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
|
||||
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
|
||||
command.add("gdalinfo");
|
||||
command.add(filePath);
|
||||
command.add("|");
|
||||
@@ -207,7 +206,6 @@ public class FIleChecker {
|
||||
return hasDriver;
|
||||
}
|
||||
|
||||
|
||||
@Schema(name = "File Basic", description = "파일 기본 정보")
|
||||
@Getter
|
||||
public static class Basic {
|
||||
@@ -221,13 +219,13 @@ public class FIleChecker {
|
||||
private final String lastModified;
|
||||
|
||||
public Basic(
|
||||
String fileNm,
|
||||
String parentFolderNm,
|
||||
String parentPath,
|
||||
String fullPath,
|
||||
String extension,
|
||||
long fileSize,
|
||||
String lastModified) {
|
||||
String fileNm,
|
||||
String parentFolderNm,
|
||||
String parentPath,
|
||||
String fullPath,
|
||||
String extension,
|
||||
long fileSize,
|
||||
String lastModified) {
|
||||
this.fileNm = fileNm;
|
||||
this.parentFolderNm = parentFolderNm;
|
||||
this.parentPath = parentPath;
|
||||
@@ -238,9 +236,14 @@ public class FIleChecker {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static List<Basic> getFilesFromAllDepth(String dir, String targetFileNm, String extension, int maxDepth, String sortType, int startPos, int limit) {
|
||||
public static List<Basic> getFilesFromAllDepth(
|
||||
String dir,
|
||||
String targetFileNm,
|
||||
String extension,
|
||||
int maxDepth,
|
||||
String sortType,
|
||||
int startPos,
|
||||
int limit) {
|
||||
|
||||
Path startPath = Paths.get(dir);
|
||||
String dirPath = dir;
|
||||
@@ -256,39 +259,36 @@ public class FIleChecker {
|
||||
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
|
||||
|
||||
fileList =
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(
|
||||
p ->
|
||||
extension == null
|
||||
|| extension.equals("")
|
||||
|| extension.equals("*")
|
||||
|| targetExtensions.contains(extractExtension(p)))
|
||||
.sorted(getFileComparator(sortType))
|
||||
.filter(
|
||||
p -> p.getFileName().toString().contains(targetFileNm)
|
||||
)
|
||||
.skip(startPos)
|
||||
.limit(limit)
|
||||
.map(
|
||||
path -> {
|
||||
//int depth = path.getNameCount();
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(
|
||||
p ->
|
||||
extension == null
|
||||
|| extension.equals("")
|
||||
|| extension.equals("*")
|
||||
|| targetExtensions.contains(extractExtension(p)))
|
||||
.sorted(getFileComparator(sortType))
|
||||
.filter(p -> p.getFileName().toString().contains(targetFileNm))
|
||||
.skip(startPos)
|
||||
.limit(limit)
|
||||
.map(
|
||||
path -> {
|
||||
// int depth = path.getNameCount();
|
||||
|
||||
String fileNm = path.getFileName().toString();
|
||||
String ext = FilenameUtils.getExtension(fileNm);
|
||||
String parentFolderNm = path.getParent().getFileName().toString();
|
||||
String parentPath = path.getParent().toString();
|
||||
String fullPath = path.toAbsolutePath().toString();
|
||||
String fileNm = path.getFileName().toString();
|
||||
String ext = FilenameUtils.getExtension(fileNm);
|
||||
String parentFolderNm = path.getParent().getFileName().toString();
|
||||
String parentPath = path.getParent().toString();
|
||||
String fullPath = path.toAbsolutePath().toString();
|
||||
|
||||
File file = new File(fullPath);
|
||||
long fileSize = file.length();
|
||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
||||
|
||||
return new Basic(
|
||||
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
File file = new File(fullPath);
|
||||
long fileSize = file.length();
|
||||
String lastModified = dttmFormat.format(new Date(file.lastModified()));
|
||||
|
||||
return new Basic(
|
||||
fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
|
||||
@@ -297,7 +297,6 @@ public class FIleChecker {
|
||||
return fileList;
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> createExtensionSet(String extensionString) {
|
||||
if (extensionString == null || extensionString.isBlank()) {
|
||||
return Set.of();
|
||||
@@ -305,10 +304,10 @@ public class FIleChecker {
|
||||
|
||||
// "java, class" -> ["java", " class"] -> [".java", ".class"]
|
||||
return Arrays.stream(extensionString.split(","))
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static String extractExtension(Path path) {
|
||||
@@ -328,17 +327,17 @@ public class FIleChecker {
|
||||
|
||||
// 파일 이름 비교 기본 Comparator (대소문자 무시)
|
||||
Comparator<Path> nameComparator =
|
||||
Comparator.comparing(path -> path.getFileName().toString(), CASE_INSENSITIVE_ORDER);
|
||||
Comparator.comparing(path -> path.getFileName().toString(), CASE_INSENSITIVE_ORDER);
|
||||
|
||||
Comparator<Path> dateComparator =
|
||||
Comparator.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
});
|
||||
Comparator.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
});
|
||||
|
||||
if ("name desc".equalsIgnoreCase(sortType)) {
|
||||
return nameComparator.reversed();
|
||||
@@ -350,5 +349,4 @@ public class FIleChecker {
|
||||
return nameComparator;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user