Search in sources :

Example 6 with FileInputSource

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());
    }
}
Also used : Path(java.nio.file.Path) BinaryDocument(org.exist.dom.persistent.BinaryDocument) FileInputSource(org.exist.util.FileInputSource) CountingInputStream(org.apache.commons.io.input.CountingInputStream)

Aggregations

FileInputSource (org.exist.util.FileInputSource)6 Path (java.nio.file.Path)4 BinaryDocument (org.exist.dom.persistent.BinaryDocument)3 EXistInputSource (org.exist.util.EXistInputSource)2 URL (java.net.URL)1 CountingInputStream (org.apache.commons.io.input.CountingInputStream)1 Collection (org.exist.collections.Collection)1 CollectionConfigurationManager (org.exist.collections.CollectionConfigurationManager)1 BrokerPool (org.exist.storage.BrokerPool)1 DBBroker (org.exist.storage.DBBroker)1 Txn (org.exist.storage.txn.Txn)1