Skip to content

Commit

Permalink
refactor(chat2db-spi): replace Clob reading logic with IOUtils.toString
Browse files Browse the repository at this point in the history
  • Loading branch information
pdxzzz committed Jul 16, 2024
1 parent 95db332 commit 60e47c2
Showing 1 changed file with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
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;
import org.slf4j.LoggerFactory;

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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 60e47c2

Please sign in to comment.