파일 체크 수정 및 패키지 분리

This commit is contained in:
Harry M. You
2025-12-05 16:13:18 +09:00
parent 786b2f8cc8
commit fba9a14035
13 changed files with 680 additions and 241 deletions

View File

@@ -73,7 +73,10 @@ public class FIleChecker {
}
public static boolean checkTfw(File file) {
public static boolean checkTfw(String filePath) {
File file = new File(filePath);
if (!file.exists()) {
return false;
}
@@ -100,7 +103,14 @@ public class FIleChecker {
return true;
}
public static boolean checkGeoTiff(File file) {
public static boolean checkGeoTiff(String filePath) {
File file = new File(filePath);
if (!file.exists()) {
return false;
}
GeoTiffReader reader = null;
try {
// 1. 파일 포맷 및 헤더 확인
@@ -130,27 +140,65 @@ public class FIleChecker {
public static Boolean cmmndGdalInfo(String filePath) {
File file = new File(filePath);
if (!file.exists()) {
return false;
}
String resStr = "";
boolean hasDriver = false;
try {
// 리눅스/맥용
ProcessBuilder pb = new ProcessBuilder("sh", "-c", "gdalinfo "+filePath+" | grep -i 'Geo'");
//ProcessBuilder pb = new ProcessBuilder("sh", "-c", "gdalinfo "+filePath+" | grep -i 'Geo'");
List<String> command = new ArrayList<>();
//윈도우용
//ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "gdalinfo " + filePath + " | findstr /i \"Geo\"");
Process process = pb.start();
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
command.add("C:\\Program Files\\QGIS 3.44.4\\bin\\gdalinfo");
command.add(filePath);
command.add("|");
command.add("findstr");
command.add("/i");
command.add("Geo");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
/*
command.add("sh"); // 윈도우 명령 프롬프트 실행
command.add("-c"); // 명령어를 수행하고 종료한다는 옵션
command.add("gdalinfo");
command.add(filePath);
command.add("|");
command.add("grep");
command.add("-i");
command.add("Geo");
*/
while ((line = reader.readLine()) != null) {
if (line.contains("Driver: GTiff")) hasDriver = true;
//if (line.contains("Size is")) hasSize = true;
//if (line.contains("FAILURE:")) hasFailure = true;
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true);
try {
Process process = processBuilder.start();
// 인코딩은 윈도우 한글 환경에 맞게 MS949로 지정
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
//System.out.println(line);
if( line.contains("Driver: GTiff/GeoTIFF")) {
hasDriver = true;
break;
}
}
int exitCode = process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return hasDriver;
}