파일체크 수정

This commit is contained in:
Harry M. You
2025-12-09 09:35:41 +09:00
parent c3245ab79c
commit ed45018877
2 changed files with 53 additions and 50 deletions

View File

@@ -13,6 +13,8 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.geotools.coverage.grid.GridCoverage2D; import org.geotools.coverage.grid.GridCoverage2D;
import org.geotools.gce.geotiff.GeoTiffReader; import org.geotools.gce.geotiff.GeoTiffReader;
@@ -45,8 +47,9 @@ public class FIleChecker {
return true; return true;
} }
public static boolean verifyFileIntegrity(Path path, String expectedHash) public static boolean verifyFileIntegrity(Path path, String expectedHash)
throws IOException, NoSuchAlgorithmException { throws IOException, NoSuchAlgorithmException {
// 1. 알고리즘 선택 (SHA-256 권장, MD5는 보안상 비추천) // 1. 알고리즘 선택 (SHA-256 권장, MD5는 보안상 비추천)
MessageDigest digest = MessageDigest.getInstance("SHA-256"); MessageDigest digest = MessageDigest.getInstance("SHA-256");
@@ -69,6 +72,7 @@ public class FIleChecker {
return actualHash.equalsIgnoreCase(expectedHash); return actualHash.equalsIgnoreCase(expectedHash);
} }
public static boolean checkTfw(String filePath) { public static boolean checkTfw(String filePath) {
File file = new File(filePath); File file = new File(filePath);
@@ -86,13 +90,13 @@ public class FIleChecker {
lines.add(Double.parseDouble(line.trim())); lines.add(Double.parseDouble(line.trim()));
} }
} }
} catch (IOException ignored) { }catch (IOException ignored) {
return false; return false;
} }
// 2. 6줄이 맞는지 확인 // 2. 6줄이 맞는지 확인
if (lines.size() < 6) { if (lines.size() < 6) {
// System.out.println("유효하지 않은 TFW 파일입니다. (데이터 부족)"); //System.out.println("유효하지 않은 TFW 파일입니다. (데이터 부족)");
return false; return false;
} }
@@ -119,9 +123,9 @@ public class FIleChecker {
if (coverage == null) return false; if (coverage == null) return false;
// 3. GIS 필수 정보(좌표계)가 있는지 확인 // 3. GIS 필수 정보(좌표계)가 있는지 확인
// if (coverage.getCoordinateReferenceSystem() == null) { //if (coverage.getCoordinateReferenceSystem() == null) {
// GeoTIFF가 아니라 일반 TIFF일 수도 있음(이미지는 정상이지만, 좌표계(CRS) 정보가 없습니다.) // GeoTIFF가 아니라 일반 TIFF일 수도 있음(이미지는 정상이지만, 좌표계(CRS) 정보가 없습니다.)
// } //}
return true; return true;
@@ -145,57 +149,59 @@ public class FIleChecker {
String resStr = ""; String resStr = "";
boolean hasDriver = false; boolean hasDriver = false;
// 리눅스/맥용 // 리눅스/맥용
// 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<>(); List<String> command = new ArrayList<>();
// 윈도우용
command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
// command.add("C:\\Program Files\\QGIS 3.44.4\\bin\\gdalinfo");
command.add("gdalinfo");
command.add(filePath);
command.add("|");
command.add("findstr");
command.add("/i");
command.add("Geo");
//윈도우용
/* /*
command.add("sh"); // 윈도우 명령 프롬프트 실행 command.add("cmd.exe"); // 윈도우 명령 프롬프트 실행
command.add("-c"); // 명령어를 수행하고 종료한다는 옵션 command.add("/c"); // 명령어를 수행하고 종료한다는 옵션
command.add("gdalinfo"); command.add("gdalinfo");
command.add(filePath); command.add(filePath);
command.add("|"); command.add("|");
command.add("grep"); command.add("findstr");
command.add("-i"); command.add("/i");
command.add("Geo"); command.add("Geo");
*/ */
ProcessBuilder processBuilder = new ProcessBuilder(command); command.add("sh"); // 리눅스,맥 명령 프롬프트 실행
processBuilder.redirectErrorStream(true); command.add("-c"); // 명령어를 수행하고 종료한다는 옵션
command.add("gdalinfo");
command.add(filePath);
command.add("|");
command.add("grep");
command.add("-i");
command.add("Geo");
try {
Process process = processBuilder.start();
// 인코딩은 윈도우 한글 환경에 맞게 MS949로 지정 ProcessBuilder processBuilder = new ProcessBuilder(command);
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); processBuilder.redirectErrorStream(true);
String line; try {
while ((line = reader.readLine()) != null) { Process process = processBuilder.start();
// System.out.println(line);
if (line.contains("Driver: GTiff/GeoTIFF")) { // 인코딩은 윈도우 한글 환경에 맞게 MS949로 지정
hasDriver = true; BufferedReader reader = new BufferedReader(
break; 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();
} }
int exitCode = process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
return hasDriver; return hasDriver;
} }
} }

View File

@@ -41,7 +41,6 @@ public class MapSheetMngFileCheckerService {
public FoldersDto getFolderAll(SrchFoldersDto srchDto) { public FoldersDto getFolderAll(SrchFoldersDto srchDto) {
System.out.println("getFolderAll === ");
Path startPath = Paths.get(srchDto.getDirPath()); Path startPath = Paths.get(srchDto.getDirPath());
String dirPath = srchDto.getDirPath(); String dirPath = srchDto.getDirPath();
@@ -120,8 +119,6 @@ public class MapSheetMngFileCheckerService {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
// FoldersDto foldersDto = new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt,
// folderDtoList);
return new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList); return new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList);
} }