001/**
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 *
006 */
007package org.fcrepo.migration;
008
009import java.io.File;
010import java.io.IOException;
011import java.io.InputStream;
012import java.time.Instant;
013import java.util.Optional;
014
015/**
016 * An interface defining access to information about a version of a
017 * fedora datastream.
018 * @author mdurbin
019 */
020public interface DatastreamVersion {
021
022    /**
023     * Gets the information about the datastream for which this is
024     * a version.  (which in turn can be queried to get information about
025     * the object).
026     *
027     * @return {@link org.fcrepo.migration.DatastreamInfo}
028     */
029    public DatastreamInfo getDatastreamInfo();
030
031    /**
032     * Gets the id for this version.
033     *
034     * @return version id
035     */
036    public String getVersionId();
037
038    /**
039     * Gets the mime type for this version.
040     *
041     * @return mime-type
042     */
043    public String getMimeType();
044
045    /**
046     * Gets the label for this version.
047     *
048     * @return label
049     */
050    public String getLabel();
051
052    /**
053     * Gets the date when this version was created.
054     *
055     * @return creation date
056     */
057    public String getCreated();
058
059    /**
060     * Gets the date when this version was created.
061     *
062     * @return creation date
063     */
064    public Instant getCreatedInstant();
065
066    /**
067     * Gets the altIDs value for this version.
068     *
069     * @return alternate IDs
070     */
071    public String getAltIds();
072
073    /**
074     * Gets the format URI for this version.
075     *
076     * @return format URI
077     */
078    public String getFormatUri();
079
080    /**
081     * Gets the size (in bytes) for the content of this datastream
082     * version.
083     *
084     * @return size
085     */
086    public long getSize();
087
088    /**
089     * Gets the content digest (if available) for this version.
090     *
091     * @return {@link org.fcrepo.migration.ContentDigest}
092     */
093    public ContentDigest getContentDigest();
094
095    /**
096     * Gets access to the content of this datastream.  When text, the
097     * encoding can be expected to be UTF-8.
098     *
099     * @return {@link java.io.InputStream of content}
100     * @throws IllegalStateException if invoked outside of the call
101     *         to @{link StreamingFedoraObjectHandler#processDatastreamVersion}
102     * @throws IOException when unable to access the stream
103     */
104    public InputStream getContent() throws IOException;
105
106    /**
107     * Get the file backing this datastream if it exists.
108     * Used by fcrepo-migration-validator in order to get direct access to files.
109     *
110     * @return the file
111     */
112    default Optional<File> getFile() {
113        return Optional.empty();
114    }
115
116    /**
117     * Returns the URL to which an External (X) or Redirect (R) datastream
118     * points.  Throws IllegalStateException if this isn't an external or
119     * redirect datastream.
120     *
121     * @return URL of datastream
122     */
123    public String getExternalOrRedirectURL();
124
125    /**
126     * Determines if this is the first version of a datastream.
127     *
128     * @param obj to be tested whether is first version
129     *
130     * @return  True if this is the first version, false otherwise.
131     */
132    public boolean isFirstVersionIn(ObjectReference obj);
133
134    /**
135     * Determines if this is the last version of a datastream.
136     *
137     * @param obj to be tested whether is last version
138     *
139     * @return  True if this is the last version, false otherwise.
140     */
141    public boolean isLastVersionIn(ObjectReference obj);
142}