use of org.exist.util.FileInputSource in project exist by eXist-db.
the class RecoverBinaryTest method readAndVerify.
@Override
protected void readAndVerify(final DBBroker broker, final DocumentImpl doc, final InputSource data, final String dbFilename) throws IOException {
final Path file = ((FileInputSource) data).getFile();
final BinaryDocument binDoc = (BinaryDocument) doc;
// verify the size, to ensure it is the correct content
final long expectedSize = Files.size(file);
assertEquals(expectedSize, binDoc.getContentLength());
// check the actual content too!
final byte[] bdata = new byte[(int) binDoc.getContentLength()];
try (final CountingInputStream cis = new CountingInputStream(broker.getBinaryResource(binDoc))) {
final int read = cis.read(bdata);
assertEquals(bdata.length, read);
final String content = new String(bdata);
assertNotNull(content);
assertEquals(expectedSize, cis.getByteCount());
}
}
Aggregations