Search in sources :

Example 31 with ValueClob

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);
    }
}
Also used : RangeReader(org.h2.store.RangeReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Aggregations

ValueBlob (org.h2.value.ValueBlob)13 ValueClob (org.h2.value.ValueClob)13 LobDataDatabase (org.h2.value.lob.LobDataDatabase)13 IOException (java.io.IOException)12 LobData (org.h2.value.lob.LobData)10 ValueBigint (org.h2.value.ValueBigint)7 ValueSmallint (org.h2.value.ValueSmallint)7 ValueTinyint (org.h2.value.ValueTinyint)7 BufferedReader (java.io.BufferedReader)6 BigDecimal (java.math.BigDecimal)6 BigInteger (java.math.BigInteger)6 DataUtils.readString (org.h2.mvstore.DataUtils.readString)6 MVStore (org.h2.mvstore.MVStore)6 RangeReader (org.h2.store.RangeReader)6 LobDataInMemory (org.h2.value.lob.LobDataInMemory)6 Reader (java.io.Reader)4 Value (org.h2.value.Value)4 ValueInterval (org.h2.value.ValueInterval)4 ValueTimeTimeZone (org.h2.value.ValueTimeTimeZone)4 ValueTimestamp (org.h2.value.ValueTimestamp)4