0

I got a test using HSQL for memory persisting that persists a blob and then tries to retrieve this blob.

When I try to get the input stream from the stored Blob I got the following error:

 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)

The code that tries to retrieve the 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();
            }
        });
fefedo
  • 11
  • 4

0 Answers0