From f77710844f66d90169ca4fa57dec29b97c2fcc7a Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Fri, 12 Apr 2024 15:13:55 +0900 Subject: [PATCH] =?UTF-8?q?=EC=86=8C=EB=82=98=ED=81=90=EB=B8=8C=20?= =?UTF-8?q?=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/file/etc/OutsourcingFileWriter.java | 4 +- .../cokr/xit/base/file/hwp/HWPWriter.java | 6 +-- .../java/cokr/xit/fims/cmmn/CmmnUtil.java | 54 ++++++++++--------- .../java/cokr/xit/fims/cmmn/ftp/FTPUtil.java | 23 ++++---- 4 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java b/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java index b8e35cb4..cfd0aa90 100644 --- a/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java +++ b/src/main/java/cokr/xit/base/file/etc/OutsourcingFileWriter.java @@ -107,7 +107,9 @@ public class OutsourcingFileWriter { File file = new File(metaFilePath); if (!file.exists()) { - file.createNewFile(); + if(!file.createNewFile()) { + throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); + }; } FileWriter fw = new FileWriter(file); BufferedWriter writer = new BufferedWriter(fw); diff --git a/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java b/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java index 49ac314f..1ea1431b 100644 --- a/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java +++ b/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java @@ -107,7 +107,9 @@ public class HWPWriter { kr.dogfoot.hwplib.writer.HWPWriter.toFile(baseFile, basePath); for(int i=2; i <= partFileList.size();i++) { - (new File(partFileList.get(i-1))).delete(); + if(!(new File(partFileList.get(i-1))).delete()) { + throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다."); + } } } @@ -118,9 +120,7 @@ public class HWPWriter { result.put("file", new File(filePath)); } catch (Exception e) { - e.printStackTrace(); throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다."); - } return result; diff --git a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java index d0b34177..adb42a00 100644 --- a/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/CmmnUtil.java @@ -26,6 +26,7 @@ import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.imageio.ImageIO; @@ -203,36 +204,39 @@ public class CmmnUtil { * @return 삭제된 폴더수 */ public static void removeDuplicateFileName(String root) { - try { - - List fileList = Files.walk(Paths.get(root)).filter(Files::isRegularFile).toList(); - - Map> byFileName = fileList.stream().collect(Collectors.groupingBy(item -> item.toFile().getName())); - - Iterator keys = byFileName.keySet().iterator(); - - while( keys.hasNext() ){ - String key = keys.next(); - List sameNameFileList = byFileName.get(key); - if(sameNameFileList.size() < 2) { - continue; - } - - Path latest = sameNameFileList.stream() - .max(Comparator.comparing(item -> item.toFile().lastModified())) - .orElseThrow(); - - for(Path sameNameFile : sameNameFileList) { - if(!sameNameFile.equals(latest)) { - sameNameFile.toFile().delete(); - } - } - } + List fileList = null; + try (Stream pathStream = Files.walk(Paths.get(root))){ + fileList = pathStream.filter(Files::isRegularFile).toList(); } catch (IOException e) { e.printStackTrace(); } + if(fileList != null && !fileList.isEmpty()) { + Map> byFileName = fileList.stream().collect(Collectors.groupingBy(item -> item.toFile().getName())); + + Iterator keys = byFileName.keySet().iterator(); + + while( keys.hasNext() ){ + String key = keys.next(); + List sameNameFileList = byFileName.get(key); + if(sameNameFileList.size() < 2) { + continue; + } + + Path latest = sameNameFileList.stream() + .max(Comparator.comparing(item -> item.toFile().lastModified())) + .orElseThrow(); + + for(Path sameNameFile : sameNameFileList) { + if(!sameNameFile.equals(latest)) { + if(!sameNameFile.toFile().delete()) { + throw new RuntimeException("[F]파일 삭제 오류"); + } + } + } + } + } } /** diff --git a/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java b/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java index 85977c41..e4cb1321 100644 --- a/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/ftp/FTPUtil.java @@ -102,19 +102,20 @@ public class FTPUtil { } + if(client.isConnected()) { + client.disconnect(); + } } catch (Exception e) { - e.printStackTrace(); + if(client.isConnected()) { + try { + client.disconnect(); + } catch (IOException e1) { + throw new RuntimeException("오류 발생"); + } + } + throw new RuntimeException("오류 발생"); - } finally { - // ftp 커넥션이 연결되어 있으면 종료한다. - try { - if (client.isConnected()) { - client.disconnect(); - } - } catch (Throwable e) { - throw new RuntimeException("오류 발생"); - } - } + } return true; }