Search in sources :

Example 1 with BlobId

use of org.exist.storage.blob.BlobId in project exist by eXist-db.

the class BinaryDocument method read.

/**
 * Deserialize the document object from bytes.
 *
 * @param pool the database
 * @param istream the byte stream to read
 *
 * @return the document object.
 * @throws IOException in case of an I/O error
 */
public static BinaryDocument read(final BrokerPool pool, final VariableByteInput istream) throws IOException {
    final int docId = istream.readInt();
    final XmldbURI fileURI = XmldbURI.create(istream.readUTF());
    final byte[] blobIdRaw = new byte[istream.readInt()];
    istream.read(blobIdRaw);
    final BlobId blobId = new BlobId(blobIdRaw);
    final Permission permissions = PermissionFactory.getDefaultResourcePermission(pool.getSecurityManager());
    permissions.read(istream);
    final long realSize = istream.readLong();
    // load document attributes
    final long created = istream.readLong();
    final long lastModified = istream.readLong();
    final int mimeTypeSymbolsIndex = istream.readInt();
    final String mimeType = pool.getSymbols().getMimeType(mimeTypeSymbolsIndex);
    final int pageCount = istream.readInt();
    final int userLock = istream.readInt();
    final DocumentTypeImpl docType;
    if (istream.readByte() == HAS_DOCTYPE) {
        docType = DocumentTypeImpl.read(istream);
    } else {
        docType = null;
    }
    final LockToken lockToken;
    if (istream.readByte() == HAS_LOCKTOKEN) {
        lockToken = LockToken.read(istream);
    } else {
        lockToken = null;
    }
    final BinaryDocument doc = new BinaryDocument(pool, null, docId, fileURI, blobId, permissions, realSize, created, lastModified, mimeType, docType);
    doc.pageCount = pageCount;
    doc.userLock = userLock;
    doc.lockToken = lockToken;
    return doc;
}
Also used : Permission(org.exist.security.Permission) BlobId(org.exist.storage.blob.BlobId) XmldbURI(org.exist.xmldb.XmldbURI)

Example 2 with BlobId

use of org.exist.storage.blob.BlobId in project exist by eXist-db.

the class NativeBroker method storeBinaryResource.

@Override
public void storeBinaryResource(final Txn transaction, final BinaryDocument blob, final InputStream is) throws IOException {
    final BlobStore blobStore = pool.getBlobStore();
    final Tuple2<BlobId, Long> blobIdLen = blobStore.add(transaction, is);
    blob.setBlobId(blobIdLen._1);
    blob.setContentLength(blobIdLen._2);
}
Also used : BlobId(org.exist.storage.blob.BlobId) BlobStore(org.exist.storage.blob.BlobStore)

Example 3 with BlobId

use of org.exist.storage.blob.BlobId in project exist by eXist-db.

the class NativeBroker method copyBinaryResource.

private void copyBinaryResource(final Txn transaction, final BinaryDocument srcDoc, final BinaryDocument dstDoc) throws IOException {
    final BlobStore blobStore = pool.getBlobStore();
    final BlobId dstBlobId = blobStore.copy(transaction, srcDoc.getBlobId());
    dstDoc.setBlobId(dstBlobId);
    dstDoc.setContentLength(srcDoc.getContentLength());
}
Also used : BlobId(org.exist.storage.blob.BlobId) BlobStore(org.exist.storage.blob.BlobStore)

Example 4 with BlobId

use of org.exist.storage.blob.BlobId in project exist by eXist-db.

the class RemoteCollection method getResource.

@Override
public Resource getResource(final String name) throws XMLDBException {
    final List<String> params = new ArrayList<>(1);
    XmldbURI docUri;
    try {
        docUri = XmldbURI.xmldbUriFor(name);
    } catch (final URISyntaxException e) {
        throw new XMLDBException(ErrorCodes.INVALID_URI, e);
    }
    params.add(getPathURI().append(docUri).toString());
    final Map hash;
    hash = (Map) execute("describeResource", params);
    final String docName = (String) hash.get("name");
    if (docName == null) {
        // resource does not exist!
        return null;
    }
    try {
        docUri = XmldbURI.xmldbUriFor(docName).lastSegment();
    } catch (final URISyntaxException e) {
        throw new XMLDBException(ErrorCodes.INVALID_URI, e);
    }
    final String owner = (String) hash.get("owner");
    final String group = (String) hash.get("group");
    final int mode = (Integer) hash.get("permissions");
    final Stream<ACEAider> aces = extractAces(hash.get("acl"));
    final Permission perm;
    try {
        perm = getPermission(owner, group, mode, aces);
    } catch (final PermissionDeniedException pde) {
        throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, "Unable to retrieve permissions for resource '" + name + "': " + pde.getMessage(), pde);
    }
    final String type = (String) hash.get("type");
    long contentLen = 0;
    if (hash.containsKey("content-length-64bit")) {
        final Object o = hash.get("content-length-64bit");
        if (o instanceof Long) {
            contentLen = (Long) o;
        } else {
            contentLen = Long.parseLong((String) o);
        }
    } else if (hash.containsKey("content-length")) {
        contentLen = (Integer) hash.get("content-length");
    }
    final AbstractRemoteResource r;
    if (type == null || "XMLResource".equals(type)) {
        r = new RemoteXMLResource(this, -1, -1, docUri, Optional.empty());
    } else {
        r = new RemoteBinaryResource(this, docUri);
        if (hash.containsKey("blob-id")) {
            final byte[] blobId = (byte[]) hash.get("blob-id");
            ((RemoteBinaryResource) r).setBlobId(new BlobId(blobId));
        }
        if (hash.containsKey("digest-algorithm") && hash.containsKey("digest")) {
            final String digestAlgorithm = (String) hash.get("digest-algorithm");
            final byte[] digest = (byte[]) hash.get("digest");
            final MessageDigest messageDigest = new MessageDigest(DigestType.forCommonName(digestAlgorithm), digest);
            ((RemoteBinaryResource) r).setContentDigest(messageDigest);
        }
    }
    r.setPermissions(perm);
    r.setContentLength(contentLen);
    r.dateCreated = (Date) hash.get("created");
    r.dateModified = (Date) hash.get("modified");
    if (hash.containsKey("mime-type")) {
        r.setMimeType((String) hash.get("mime-type"));
    }
    return r;
}
Also used : ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) ACEAider(org.exist.security.internal.aider.ACEAider) Permission(org.exist.security.Permission) PermissionDeniedException(org.exist.security.PermissionDeniedException) MessageDigest(org.exist.util.crypto.digest.MessageDigest) Map(java.util.Map) BlobId(org.exist.storage.blob.BlobId)

Example 5 with BlobId

use of org.exist.storage.blob.BlobId in project exist by eXist-db.

the class JournalBinaryTest method calcDocLocation.

@Override
protected BinaryDocLocator calcDocLocation(final Path content, final XmldbURI collectionUri, final String fileName) throws IOException {
    final StreamableDigest streamableDigest = DigestType.BLAKE_256.newStreamableDigest();
    FileUtils.digest(content, streamableDigest);
    return new BinaryDocLocator(collectionUri.append(fileName).getRawCollectionPath(), new BlobId(streamableDigest.getMessageDigest()));
}
Also used : StreamableDigest(org.exist.util.crypto.digest.StreamableDigest) BlobId(org.exist.storage.blob.BlobId)

Aggregations

BlobId (org.exist.storage.blob.BlobId)5 Permission (org.exist.security.Permission)2 BlobStore (org.exist.storage.blob.BlobStore)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PermissionDeniedException (org.exist.security.PermissionDeniedException)1 ACEAider (org.exist.security.internal.aider.ACEAider)1 MessageDigest (org.exist.util.crypto.digest.MessageDigest)1 StreamableDigest (org.exist.util.crypto.digest.StreamableDigest)1 XmldbURI (org.exist.xmldb.XmldbURI)1