001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.kernel.api.models;
019
020import com.hp.hpl.jena.rdf.model.Resource;
021import org.fcrepo.kernel.api.exception.InvalidChecksumException;
022import org.fcrepo.kernel.api.identifiers.IdentifierConverter;
023import org.fcrepo.kernel.api.RdfStream;
024import org.fcrepo.kernel.api.services.policy.StoragePolicyDecisionPoint;
025
026import java.io.InputStream;
027import java.net.URI;
028
029/**
030 * @author cabeer
031 * @since 9/19/14
032 */
033public interface FedoraBinary extends FedoraResource {
034
035    /**
036     * @return The InputStream of content associated with this datastream.
037     */
038    InputStream getContent();
039
040    /**
041     * Sets the content of this Datastream.
042     *
043     * @param content  InputStream of binary content to be stored
044     * @param contentType MIME type of content (optional)
045     * @param checksum Checksum URI of the content (optional)
046     * @param originalFileName Original file name of the content (optional)
047     * @param storagePolicyDecisionPoint Policy decision point for storing the content (optional)
048     * @throws org.fcrepo.kernel.api.exception.InvalidChecksumException if invalid checksum exception occurred
049     */
050    void setContent(InputStream content, String contentType, URI checksum,
051                    String originalFileName,
052                    StoragePolicyDecisionPoint storagePolicyDecisionPoint)
053            throws InvalidChecksumException;
054
055    /**
056     * @return The size in bytes of content associated with this datastream.
057     */
058    long getContentSize();
059
060    /**
061     * Get the pre-calculated content digest for the binary payload
062     * @return a URI with the format algorithm:value
063     */
064    URI getContentDigest();
065
066    /**
067     * @return The MimeType of content associated with this datastream.
068     */
069    String getMimeType();
070
071    /**
072     * Return the file name for the binary content
073     * @return original file name for the binary content, or the object's id.
074     */
075    String getFilename();
076
077    /**
078     * Get the fixity of this datastream compared to metadata stored in the repository
079     * @param idTranslator the id translator
080     * @return the fixity of this datastream compared to metadata stored in the repository
081     */
082    RdfStream getFixity(IdentifierConverter<Resource, FedoraResource> idTranslator);
083
084    /**
085     * Get the fixity of this datastream in a given repository's binary store.
086     * @param idTranslator the id translator
087     * @param contentDigest the checksum to compare against
088     * @param size the expected size of the binary
089     * @return the fixity of the datastream
090     */
091    RdfStream getFixity(IdentifierConverter<Resource, FedoraResource> idTranslator,
092                        URI contentDigest, long size);
093}