Skip to content

Commit

Permalink
Add small (4 Gb limit) clob support
Browse files Browse the repository at this point in the history
  • Loading branch information
gaellalire committed Jan 31, 2023
1 parent 7e7d1b3 commit 66e566c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/main/java/com/univocity/parsers/common/AbstractWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.*;
import java.nio.charset.*;
import java.sql.Clob;
import java.util.*;

/**
Expand Down Expand Up @@ -1079,7 +1080,27 @@ protected String getStringValue(Object element) {
usingNullOrEmptyValue = true;
return nullValue;
}
String string = String.valueOf(element);
String string;
if (element instanceof Clob) {
StringWriter sw = new StringWriter();
try {
Reader reader = ((Clob) element).getCharacterStream();
try {
char[] buffer = new char[8192];
int n;
while (-1 != (n = reader.read(buffer))) {
sw.write(buffer, 0, n);
}
} finally {
reader.close();
}
} catch (Exception e) {
throw new RuntimeException("Unable to convert clob", e);
}
string = sw.toString();
} else {
string = String.valueOf(element);
}
if (string.isEmpty()) {
usingNullOrEmptyValue = true;
return emptyValue;
Expand Down Expand Up @@ -2580,4 +2601,4 @@ private String getContent(CharSequence tmp) {
protected final boolean allowTrim(int fieldIndex) {
return !writingHeaders || fieldIndex >= headerTrimFlags.length || headerTrimFlags[fieldIndex];
}
}
}

0 comments on commit 66e566c

Please sign in to comment.