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