From 60e47c2132664c29d388c9ecb1948cb9dac66c6a Mon Sep 17 00:00:00 2001 From: zgq <203083679@qq.com> Date: Tue, 16 Jul 2024 14:45:39 +0800 Subject: [PATCH] refactor(chat2db-spi): replace Clob reading logic with IOUtils.toString --- .../ai/chat2db/spi/model/JDBCDataValue.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/JDBCDataValue.java b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/JDBCDataValue.java index 685b3308a..c03618804 100644 --- a/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/JDBCDataValue.java +++ b/chat2db-server/chat2db-spi/src/main/java/ai/chat2db/spi/model/JDBCDataValue.java @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.Getter; +import org.apache.commons.io.IOUtils; import org.apache.tika.Tika; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -12,10 +13,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.math.BigDecimal; import java.sql.*; import java.util.Objects; @@ -126,7 +124,7 @@ public String getBlobString() { public String getClobString() { Clob clob = getClob(); - try (BufferedReader reader = new BufferedReader(clob.getCharacterStream())) { + try (Reader reader = clob.getCharacterStream()) { long length = clob.length(); LOBInfo cLobInfo = getLobInfo(length); double size = cLobInfo.getSize(); @@ -137,14 +135,7 @@ public String getClobString() { if (limitSize && isBigSize(unit)) { return String.format("[%s] %s", getType(), cLobInfo); } - StringBuilder builder = new StringBuilder((int) (Math.ceil(size))); - String line; - - while ((line = reader.readLine()) != null) { - // TODO: 优化换行符 - builder.append(line).append("\n"); - } - return builder.toString(); + return IOUtils.toString(reader); } catch (IOException | SQLException e) { log.warn("Error while reading clob stream", e); return getStringValue();