我使用HSQL测试内存持久性,持续存在blob,然后尝试检索此blob。
当我尝试从存储的Blob中获取输入流时,我收到以下错误:
java.io.IOException: java.lang.IndexOutOfBoundsException: Index out of bounds: 0 >= 0
at org.hsqldb.lib.java.JavaSystem.toIOException(Unknown Source)
at org.hsqldb.types.BlobInputStream.read(Unknown Source)
at java.base/java.io.InputStream.read(InputStream.java:175)
at java.base/java.io.InputStream.read(InputStream.java:106)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1792)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744)
at org.apache.commons.io.FileUtils.copyInputStreamToFile(FileUtils.java:1512)
at br.com.softplan.unj.peticionamento.rascunho.dao.impl.RascunhoDocDAOImpl.lambda$load$2(RascunhoDocDAOImpl.java:61)
尝试检索BLOB的代码:
StreamEx.ofNullable(this.entityManager.createQuery(query).getResultList()).flatMap(StreamEx::of).forEach(rascunhoDoc -> {
try {
this.entityManager.refresh(rascunhoDoc);
File documento = FileUtils.getFile(criarTempRascunho(), docPK.getCdUsuCadastrante()+"-"+UUID.randomUUID().toString() + ".pdf");
InputStream inputStream = rascunhoDoc.getBlPagina().getBinaryStream();
FileUtils.copyInputStreamToFile(inputStream, documento);
documentos.add(documento);
} catch (IOException | SQLException e) {
e.printStackTrace();
}
});