Search in sources :

Example 1 with CountingReaderInputStream

use of org.h2.store.CountingReaderInputStream in project h2database by h2database.

the class LobStorageMap method createClob.

@Override
public Value createClob(Reader reader, long maxLength) {
    init();
    int type = Value.CLOB;
    try {
        // we multiple by 3 here to get the worst-case size in bytes
        if (maxLength != -1 && maxLength * 3 <= database.getMaxLengthInplaceLob()) {
            char[] small = new char[(int) maxLength];
            int len = IOUtils.readFully(reader, small, (int) maxLength);
            if (len > maxLength) {
                throw new IllegalStateException("len > blobLength, " + len + " > " + maxLength);
            }
            byte[] utf8 = new String(small, 0, len).getBytes(StandardCharsets.UTF_8);
            if (utf8.length > database.getMaxLengthInplaceLob()) {
                throw new IllegalStateException("len > maxinplace, " + utf8.length + " > " + database.getMaxLengthInplaceLob());
            }
            return ValueLobDb.createSmallLob(type, utf8);
        }
        if (maxLength < 0) {
            maxLength = Long.MAX_VALUE;
        }
        CountingReaderInputStream in = new CountingReaderInputStream(reader, maxLength);
        ValueLobDb lob = createLob(in, type);
        // the length is not correct
        lob = ValueLobDb.create(type, database, lob.getTableId(), lob.getLobId(), null, in.getLength());
        return lob;
    } catch (IllegalStateException e) {
        throw DbException.get(ErrorCode.OBJECT_CLOSED, e);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    }
}
Also used : ValueLobDb(org.h2.value.ValueLobDb) IOException(java.io.IOException)

Example 2 with CountingReaderInputStream

use of org.h2.store.CountingReaderInputStream in project h2database by h2database.

the class LobStorageMap method createClob.

@Override
public ValueClob createClob(Reader reader, long maxLength) {
    MVStore.TxCounter txCounter = mvStore.registerVersionUsage();
    try {
        // we multiple by 3 here to get the worst-case size in bytes
        if (maxLength != -1 && maxLength * 3 <= database.getMaxLengthInplaceLob()) {
            char[] small = new char[(int) maxLength];
            int len = IOUtils.readFully(reader, small, (int) maxLength);
            if (len > maxLength) {
                throw new IllegalStateException("len > blobLength, " + len + " > " + maxLength);
            }
            byte[] utf8 = new String(small, 0, len).getBytes(StandardCharsets.UTF_8);
            if (utf8.length > database.getMaxLengthInplaceLob()) {
                throw new IllegalStateException("len > maxinplace, " + utf8.length + " > " + database.getMaxLengthInplaceLob());
            }
            return ValueClob.createSmall(utf8, len);
        }
        if (maxLength < 0) {
            maxLength = Long.MAX_VALUE;
        }
        CountingReaderInputStream in = new CountingReaderInputStream(reader, maxLength);
        ValueBlob blob = createBlob(in);
        LobData lobData = blob.getLobData();
        return new ValueClob(lobData, blob.octetLength(), in.getLength());
    } catch (IllegalStateException e) {
        throw DbException.get(ErrorCode.OBJECT_CLOSED, e);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    } finally {
        mvStore.deregisterVersionUsage(txCounter);
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) LobData(org.h2.value.lob.LobData) CountingReaderInputStream(org.h2.store.CountingReaderInputStream) ValueBlob(org.h2.value.ValueBlob) ValueClob(org.h2.value.ValueClob) IOException(java.io.IOException)

Example 3 with CountingReaderInputStream

use of org.h2.store.CountingReaderInputStream in project SpringStudy by myounghaklee.

the class LobStorageMap method createClob.

@Override
public ValueClob createClob(Reader reader, long maxLength) {
    MVStore.TxCounter txCounter = mvStore.registerVersionUsage();
    try {
        // we multiple by 3 here to get the worst-case size in bytes
        if (maxLength != -1 && maxLength * 3 <= database.getMaxLengthInplaceLob()) {
            char[] small = new char[(int) maxLength];
            int len = IOUtils.readFully(reader, small, (int) maxLength);
            if (len > maxLength) {
                throw new IllegalStateException("len > blobLength, " + len + " > " + maxLength);
            }
            byte[] utf8 = new String(small, 0, len).getBytes(StandardCharsets.UTF_8);
            if (utf8.length > database.getMaxLengthInplaceLob()) {
                throw new IllegalStateException("len > maxinplace, " + utf8.length + " > " + database.getMaxLengthInplaceLob());
            }
            return ValueClob.createSmall(utf8, len);
        }
        if (maxLength < 0) {
            maxLength = Long.MAX_VALUE;
        }
        CountingReaderInputStream in = new CountingReaderInputStream(reader, maxLength);
        ValueBlob blob = createBlob(in);
        LobData lobData = blob.getLobData();
        return new ValueClob(lobData, blob.octetLength(), in.getLength());
    } catch (IllegalStateException e) {
        throw DbException.get(ErrorCode.OBJECT_CLOSED, e);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    } finally {
        mvStore.deregisterVersionUsage(txCounter);
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) LobData(org.h2.value.lob.LobData) CountingReaderInputStream(org.h2.store.CountingReaderInputStream) ValueBlob(org.h2.value.ValueBlob) ValueClob(org.h2.value.ValueClob) IOException(java.io.IOException)

Example 4 with CountingReaderInputStream

use of org.h2.store.CountingReaderInputStream in project 468H2Project by lukeunderwood42.

the class LobStorageMap method createClob.

@Override
public ValueClob createClob(Reader reader, long maxLength) {
    MVStore.TxCounter txCounter = mvStore.registerVersionUsage();
    try {
        // we multiple by 3 here to get the worst-case size in bytes
        if (maxLength != -1 && maxLength * 3 <= database.getMaxLengthInplaceLob()) {
            char[] small = new char[(int) maxLength];
            int len = IOUtils.readFully(reader, small, (int) maxLength);
            if (len > maxLength) {
                throw new IllegalStateException("len > blobLength, " + len + " > " + maxLength);
            }
            byte[] utf8 = new String(small, 0, len).getBytes(StandardCharsets.UTF_8);
            if (utf8.length > database.getMaxLengthInplaceLob()) {
                throw new IllegalStateException("len > maxinplace, " + utf8.length + " > " + database.getMaxLengthInplaceLob());
            }
            return ValueClob.createSmall(utf8, len);
        }
        if (maxLength < 0) {
            maxLength = Long.MAX_VALUE;
        }
        CountingReaderInputStream in = new CountingReaderInputStream(reader, maxLength);
        ValueBlob blob = createBlob(in);
        LobData lobData = blob.getLobData();
        return new ValueClob(lobData, blob.octetLength(), in.getLength());
    } catch (IllegalStateException e) {
        throw DbException.get(ErrorCode.OBJECT_CLOSED, e);
    } catch (IOException e) {
        throw DbException.convertIOException(e, null);
    } finally {
        mvStore.deregisterVersionUsage(txCounter);
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) LobData(org.h2.value.lob.LobData) CountingReaderInputStream(org.h2.store.CountingReaderInputStream) ValueBlob(org.h2.value.ValueBlob) ValueClob(org.h2.value.ValueClob) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)4 MVStore (org.h2.mvstore.MVStore)3 CountingReaderInputStream (org.h2.store.CountingReaderInputStream)3 ValueBlob (org.h2.value.ValueBlob)3 ValueClob (org.h2.value.ValueClob)3 LobData (org.h2.value.lob.LobData)3 ValueLobDb (org.h2.value.ValueLobDb)1