From 13f4a6b1e919db23ffb9b28c2515a445bab234f5 Mon Sep 17 00:00:00 2001 From: kimjaeyeol Date: Mon, 8 Nov 2021 17:57:35 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20=ED=96=89=EC=95=88?= =?UTF-8?q?=EB=B6=80=20=ED=94=84=EB=A6=AC=EC=85=8B=20=EB=B3=B4=EC=95=88=20?= =?UTF-8?q?=EC=A0=90=EA=B2=80=201=EC=B0=A8=20=EC=A0=90=EA=B2=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/menu/MenuService.java | 4 +-- .../portalservice/utils/FileStorageUtils.java | 25 ++++++++++--------- .../portalservice/utils/FtpStorageUtils.java | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/service/menu/MenuService.java b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/service/menu/MenuService.java index fd0de08..025f79c 100644 --- a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/service/menu/MenuService.java +++ b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/service/menu/MenuService.java @@ -103,7 +103,7 @@ public class MenuService extends AbstractService { * @return */ @Transactional - public MenuTreeResponseDto updateName(Long menuId, String name) { + public MenuTreeResponseDto updateName(Long menuId, String name) throws EntityNotFoundException { Menu menu = menuRepository.findById(menuId) .orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("menu")}) + " ID= " + menuId)); @@ -122,7 +122,7 @@ public class MenuService extends AbstractService { * @return */ @Transactional - public MenuResponseDto update(Long menuId, MenuUpdateRequestDto updateRequestDto) { + public MenuResponseDto update(Long menuId, MenuUpdateRequestDto updateRequestDto) throws EntityNotFoundException, BusinessMessageException { Menu menu = menuRepository.findById(menuId) .orElseThrow(() -> new EntityNotFoundException(getMessage("valid.notexists.format", new Object[]{getMessage("menu")}) + " ID= " + menuId)); diff --git a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FileStorageUtils.java b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FileStorageUtils.java index 3f9e7e1..92b6a56 100644 --- a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FileStorageUtils.java +++ b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FileStorageUtils.java @@ -104,7 +104,7 @@ public class FileStorageUtils implements StorageUtils { try { mimeType = Files.probeContentType(filePath); } catch (IOException ex) { - //ignore + log.error("Files.probeContentType", ex); } return mimeType == null ? URLConnection.guessContentTypeFromName(filePath.toString()) : mimeType; @@ -279,24 +279,25 @@ public class FileStorageUtils implements StorageUtils { * image 태그에서 호출 시 byte 배열로 return * * @param imagename - * @return + * @return public String getContentType(String filename) { * @throws IOException */ public AttachmentImageResponseDto loadImage(String imagename) { try { Path imagePath = this.fileStorageLocation.resolve(imagename).normalize(); try (InputStream is = new FileInputStream(imagePath.toFile())) { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - int read; - byte[] data = new byte[(int) imagePath.toFile().length()]; - while ((read = is.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, read); - } + try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { + int read; + byte[] data = new byte[(int) imagePath.toFile().length()]; + while ((read = is.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, read); + } - return AttachmentImageResponseDto.builder() - .mimeType(getContentType(imagename)) - .data(data) - .build(); + return AttachmentImageResponseDto.builder() + .mimeType(getContentType(imagename)) + .data(data) + .build(); + } } } catch (FileNotFoundException | NoSuchFileException ex) { diff --git a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java index 78e62d7..bb4d4ce 100644 --- a/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java +++ b/backend/portal-service/src/main/java/org/egovframe/cloud/portalservice/utils/FtpStorageUtils.java @@ -208,7 +208,7 @@ public class FtpStorageUtils implements StorageUtils { * @param isTemp .temp 파일 생성 여부 * @return */ - public String storeFile(MultipartFile file, String basePath, boolean isTemp) { + public String storeFile(MultipartFile file, String basePath, boolean isTemp) throws BusinessMessageException { String filename = getPhysicalFileName(file.getOriginalFilename(), isTemp); if (filename.contains("..")) {