Skip to content

Commit

Permalink
feat: 이미지 저장하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
redcarrot1 committed Jan 28, 2024
1 parent 6528181 commit 62738fd
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebSocketSession> sessions = ConcurrentHashMap.newKeySet();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 62738fd

Please sign in to comment.