From 25fe9082e95e49632bb729c9b44ae9343bb84725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Lalire?= Date: Tue, 31 Jan 2023 16:28:54 +0100 Subject: [PATCH] Add small (4 Gb limit) clob support --- .../common/routine/AbstractRoutines.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/univocity/parsers/common/routine/AbstractRoutines.java b/src/main/java/com/univocity/parsers/common/routine/AbstractRoutines.java index 90a43f46..29458ab7 100644 --- a/src/main/java/com/univocity/parsers/common/routine/AbstractRoutines.java +++ b/src/main/java/com/univocity/parsers/common/routine/AbstractRoutines.java @@ -312,6 +312,27 @@ public final void write(ResultSet rs, Writer output) { while (rs.next()) { for (int i = 1; i <= columns; i++) { row[i - 1] = rs.getObject(i); + if (row[i - 1] instanceof Clob) { + StringWriter sw = new StringWriter(); + Clob clob = ((Clob) row[i - 1]); + if (clob.length() != 0) { + try { + Reader reader = clob.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); + } + } + row[i - 1] = sw.toString(); + } } if (hasWriterProcessor) { writer.processRecord(row);