Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* eXist-db Open Source Native XML Database
* Copyright (C) 2001 The eXist-db Authors
*
* [email protected]
* http://www.exist-db.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.exist.xmldb;
import org.apache.commons.io.output.CountingOutputStream;
import org.apache.commons.io.output.NullOutputStream;
import org.exist.dom.persistent.BinaryDocument;
import org.exist.security.Subject;
import org.exist.storage.BrokerPool;
import org.exist.storage.blob.BlobId;
import org.exist.util.EXistInputSource;
import org.exist.util.FileUtils;
import org.exist.util.crypto.digest.DigestType;
import org.exist.util.crypto.digest.MessageDigest;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.exist.xquery.value.BinaryValue;
import org.w3c.dom.DocumentType;
import org.xml.sax.InputSource;
import org.xml.sax.ext.LexicalHandler;
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.XMLDBException;
import org.xmldb.api.modules.BinaryResource;
import javax.annotation.Nullable;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
import org.exist.storage.DBBroker;
import org.exist.storage.txn.Txn;
import com.evolvedbinary.j8fu.function.SupplierE;
public class LocalBinaryResource extends AbstractEXistResource implements ExtendedResource, EXistBinaryResource, EXistResource {
protected InputSource inputSource = null;
protected Path file = null;
protected byte[] rawData = null;
private BinaryValue binaryValue = null;
private boolean isExternal = false;
public LocalBinaryResource(final Subject user, final BrokerPool brokerPool, final LocalCollection collection, final XmldbURI docId) {
super(user, brokerPool, collection, docId, null);
}
@Override
public String getResourceType() throws XMLDBException {
return BinaryResource.RESOURCE_TYPE;
}
@Override
public BlobId getBlobId() throws XMLDBException {
return read((document, broker, transaction) -> ((BinaryDocument)document).getBlobId());
}
@Override
public MessageDigest getContentDigest(final DigestType digestType) throws XMLDBException {
return read((document, broker, transaction) ->
broker.getBinaryResourceContentDigest(transaction, (BinaryDocument)document, digestType));
}
@Override
public Object getExtendedContent() throws XMLDBException {
return getExtendedContent(() -> read((document, broker, transaction) -> broker.getBinaryResource(((BinaryDocument) document))));
}
/**
* Similar to {@link org.exist.xmldb.ExtendedResource#getExtendedContent()}
* but useful for operations within the XML:DB Local API
* that are already working within a transaction
*/
Object getExtendedContent(final DBBroker broker, final Txn transaction) throws XMLDBException {
return getExtendedContent(() -> read(broker, transaction).apply((document, broker1, transaction1) -> broker1.getBinaryResource(((BinaryDocument) document))));
}
private Object getExtendedContent(final SupplierE