/************************************************************ * * @packageName : io.company.localhost.utils * @fileName : BlobUtil.java * @author : 서지희 * @date : 25.02.25 * @description : * * =========================================================== * DATE AUTHOR NOTE * ----------------------------------------------------------- * 25.02.25 서지희 최초 생성 * *************************************************************/ package io.company.localhost.utils; import java.nio.charset.StandardCharsets; import java.sql.Blob; public class BlobUtil { private BlobUtil() { // 객체 생성 방지 (유틸리티 클래스는 인스턴스를 만들 필요가 없음) } public static String procBlobToString(Object blob) { try { if (blob instanceof String) { return (String) blob; // 이미 문자열이면 그대로 반환 } else if (blob instanceof Blob) { Blob sqlBlob = (Blob) blob; long blobLength = sqlBlob.length(); byte[] blobBytes = sqlBlob.getBytes(1, (int) blobLength); return new String(blobBytes, StandardCharsets.UTF_8); // SQL BLOB → 바이트 배열 → 문자열 변환 } else { throw new UnsupportedOperationException("Unsupported blob type: " + blob.getClass()); // 지원되지 않는 타입이면 예외 발생 } } catch (Exception e) { throw new RuntimeException("Failed to convert Blob to String: " + e.getMessage(), e); // 변환 실패 시 예외 처리 } } }