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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations