Debian Codegraph @

src/main/org/h2/value/lob/LobDataInMemory.java

raw
1 /*
2 * Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0,
3 * and the EPL 1.0 (https://h2database.com/html/license.html).
4 * Initial Developer: H2 Group
5 */
6 package org.h2.value.lob;
7
8 import java.io.ByteArrayInputStream;
9 import java.io.InputStream;
10
11 /**
12 * LOB data stored in memory.
13 */
14 public final class LobDataInMemory extends LobData {
15
16 /**
17 * If the LOB is below the inline size, we just store/load it directly here.
18 */
19 private final byte[] small;
20
21 public LobDataInMemory(byte[] small) {
22 if (small == null) {
23 throw new IllegalStateException();
24 }
25 this.small = small;
26 }
27
28 @Override
29 public InputStream getInputStream(long precision) {
30 return new ByteArrayInputStream(small);
31 }
32
33 /**
34 * Get the data if this a small lob value.
35 *
36 * @return the data
37 */
38 public byte[] getSmall() {
39 return small;
40 }
41
42 @Override
43 public int getMemory() {
44 /*
45 * Java 11 with -XX:-UseCompressedOops 0 bytes: 120 bytes 1 byte: 128
46 * bytes
47 */
48 return small.length + 127;
49 }
50
51 }