From 62738fd7b60a078e54faee3bc62352376a160aef Mon Sep 17 00:00:00 2001 From: seungtaekhong Date: Sun, 28 Jan 2024 21:08:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/ClientInferenceController.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/solution/gdsc/PathPal/domain/inference/api/ClientInferenceController.java b/src/main/java/solution/gdsc/PathPal/domain/inference/api/ClientInferenceController.java index 0316441..dc40c1b 100644 --- a/src/main/java/solution/gdsc/PathPal/domain/inference/api/ClientInferenceController.java +++ b/src/main/java/solution/gdsc/PathPal/domain/inference/api/ClientInferenceController.java @@ -11,16 +11,21 @@ import solution.gdsc.PathPal.domain.inference.service.SocketClient; import solution.gdsc.PathPal.global.util.JsonUtil; +import javax.imageio.stream.FileImageOutputStream; +import java.io.File; import java.io.IOException; import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; @Component public class ClientInferenceController extends WebSocketClientController { private final String hostName = "127.0.0.1"; private final int port = 9999; + private String path = "/home/hsk4991149/static/image/"; + private final AtomicInteger imageNumber = new AtomicInteger(1); private final InferenceService inferenceService; private final Set sessions = ConcurrentHashMap.newKeySet(); @@ -53,6 +58,19 @@ protected void handleBinaryMessage(WebSocketSession session, BinaryMessage messa System.err.println("추론 실패"); responseMessage = "[]"; } + try { + int imageId = imageNumber.get(); + String fileFullName = path + imageId + ".jpeg"; + System.out.println(fileFullName); + + FileImageOutputStream imageOutput = new FileImageOutputStream(new File(fileFullName)); + imageOutput.write(bytes, 0, bytes.length); + imageOutput.close(); + imageNumber.incrementAndGet(); + System.out.println("이미지 저장 성공. id = " + imageId); + } catch (Exception e) { + System.out.println("이미지 저장 실패"); + } try { System.out.println("전송 메시지: " + responseMessage);