SQLite does not support BLOB or CLOB streaming. You have four options:
- Convert InputStream to byte []. This will only work if you have enough memory (see below).
- Use FileOutputStream or Android API that supports streaming
- Split data into small blocks and save it in SQLite
- , Android . H2. , Android H2 . API JDBC, , , LOB , BLOB .
InputStream , :
public static byte[] readBytesAndClose(InputStream in) throws IOException {
try {
int block = 4 * 1024;
ByteArrayOutputStream out = new ByteArrayOutputStream(block);
byte[] buff = new byte[block];
while (true) {
int len = in.read(buff, 0, block);
if (len < 0) {
break;
}
out.write(buff, 0, len);
}
return out.toByteArray();
} finally {
in.close();
}
}