use of org.h2.value.ValueClob in project 468H2Project by lukeunderwood42.
the class ValueClob method createTempClob.
/**
* Create a temporary CLOB value from a stream.
*
* @param in
* the reader
* @param length
* the number of characters to read, or -1 for no limit
* @param handler
* the data handler
* @return the lob value
*/
public static ValueClob createTempClob(Reader in, long length, DataHandler handler) {
if (length >= 0) {
// blocks the network level
try {
in = new RangeReader(in, 0, length);
} catch (IOException e) {
throw DbException.convert(e);
}
}
BufferedReader reader;
if (in instanceof BufferedReader) {
reader = (BufferedReader) in;
} else {
reader = new BufferedReader(in, Constants.IO_BUFFER_SIZE);
}
try {
long remaining = Long.MAX_VALUE;
if (length >= 0 && length < remaining) {
remaining = length;
}
int len = ValueLob.getBufferSize(handler, remaining);
char[] buff;
if (len >= Integer.MAX_VALUE) {
String data = IOUtils.readStringAndClose(reader, -1);
buff = data.toCharArray();
len = buff.length;
} else {
buff = new char[len];
reader.mark(len);
len = IOUtils.readFully(reader, buff, len);
}
if (len <= handler.getMaxLengthInplaceLob()) {
return ValueClob.createSmall(new String(buff, 0, len));
}
reader.reset();
return createTemporary(handler, reader, remaining);
} catch (IOException e) {
throw DbException.convertIOException(e, null);
}
}
Aggregations