@@ -636,8 +636,7 @@ public FileTime getCreationTime(MCRVersionedPath path) throws IOException {
636
636
boolean added = this .isAdded (lockedPath );
637
637
boolean inLocalStorage = this .isLocal (lockedPath );
638
638
if (added && inLocalStorage ) {
639
- Path physicalPath = this .localStorage .toPhysicalPath (lockedPath );
640
- return Files .readAttributes (physicalPath , BasicFileAttributes .class ).creationTime ();
639
+ return this .localStorage .readAttributes (lockedPath , BasicFileAttributes .class ).creationTime ();
641
640
}
642
641
FileChangeHistory changeHistory = getChangeHistory (lockedPath );
643
642
return FileTime .from (changeHistory .getOldest ().getTimestamp ().toInstant ());
@@ -676,8 +675,7 @@ public long getSize(MCRVersionedPath path) throws IOException {
676
675
return 0 ;
677
676
}
678
677
if (this .localStorage .exists (lockedPath )) {
679
- Path physicalPath = this .localStorage .toPhysicalPath (lockedPath );
680
- return Files .size (physicalPath );
678
+ return this .localStorage .size (lockedPath );
681
679
}
682
680
OcflObjectVersionFile ocflObjectVersionFile = fromOcfl (lockedPath );
683
681
String sizeAsString = ocflObjectVersionFile .getFixity ().get (new SizeDigestAlgorithm ());
@@ -687,48 +685,56 @@ public long getSize(MCRVersionedPath path) throws IOException {
687
685
/**
688
686
* Returns the `filekey` of the given path.
689
687
* <p>
690
- * Because OCFL is a version file system and the mycore implementation uses transactions this `filekey`
691
- * implementation differs from a Unix like system.
692
- * </p>
688
+ * Because OCFL is a version file system and the mycore implementation uses transactions this `filekey`
689
+ * implementation differs from a Unix like system.
693
690
* <p>
694
- * The Unix `filekey` is typically derived from the inode and device ID, ensuring uniqueness within the
695
- * filesystem. When a file is modified (written, moved...), the Unix `filekey` remains unchanged as long as the
696
- * inode remains the same.
697
- * </p>
691
+ * The Unix `filekey` is typically derived from the inode and device ID, ensuring uniqueness within the
692
+ * filesystem. When a file is modified (written, moved...), the Unix `filekey` remains unchanged as long as the
693
+ * inode remains the same.
698
694
* <p>
699
- * In contrast this implementation returns a new `filekey` as soon as a file is written or moved. The `filekey`
700
- * then remains constant as long as the transaction is open. After the transaction is committed the `filekey`
701
- * may change again.
702
- * </p>
695
+ * In contrast, this implementation returns a new `filekey` as soon as a file is written or moved. The `filekey`
696
+ * then remains constant as long as the transaction is open. After the transaction is committed the `filekey`
697
+ * may change again.
703
698
* <p>
704
- * Implementation detail: Be aware that this method calls {@link #toPhysicalPath(MCRVersionedPath)}. For remote
705
- * virtual objects this means that the whole file is copied to the local storage. Because the fileKey is not
706
- * accessed frequently this should be acceptable. If this assumption proves to be wrong a special implementation
707
- * for remote virtual objects is required!
708
- * </p>
699
+ * Implementation detail: Be aware that for remote virtual objects the whole file is copied to the local
700
+ * storage. Because the fileKey is not accessed frequently this should be acceptable. If this assumption proves
701
+ * to be wrong a special implementation for remote virtual objects is required!
709
702
*
710
703
* @param path versioned path
711
704
* @return fileKey
712
705
* @throws IOException if an I/O error occurs.
713
706
*/
714
- public Object getFileKey (MCRVersionedPath path ) throws IOException {
707
+ public abstract Object getFileKey (MCRVersionedPath path ) throws IOException ;
708
+
709
+ /**
710
+ * Identifies the MIME type of a give path.
711
+ * <p>
712
+ * Implementation detail: Be aware that for remote virtual objects the whole file is copied to the local
713
+ * storage. Because the MIME type is not accessed frequently this should be acceptable. If this assumption proves
714
+ * to be wrong a special implementation for remote virtual objects is required!
715
+ *
716
+ * @param path versioned path
717
+ * @return the mime type
718
+ * @throws IOException if an I/O error occurs.
719
+ */
720
+ public String probeContentType (MCRVersionedPath path ) throws IOException {
715
721
MCRVersionedPath lockedPath = lockVersion (path );
716
- Path physicalPath = toPhysicalPath (lockedPath );
717
- return Files .readAttributes ( physicalPath , BasicFileAttributes . class ). fileKey ( );
722
+ checkExists (lockedPath );
723
+ return Files .probeContentType ( toPhysicalPath ( lockedPath ) );
718
724
}
719
725
720
726
/**
721
727
* Converts the specified versioned path to a local file system path. The path can either point at the local
722
728
* temporary storage (if it exists) or at the original OCFL file or directory.
723
729
* <p>
724
- * Use the returned path ONLY for read operations. It's not allowed to write/move or remove the returned path.
730
+ * Use the returned path ONLY for read operations. It's not allowed to write/move or remove the returned path.
725
731
* Because this would create inconsistencies in the OCFL repository or the local storage.
726
732
*
727
733
* @param path the virtual path.
728
734
* @return the physical path.
729
735
* @throws IOException if an I/O error occurs.
730
736
*/
731
- public abstract Path toPhysicalPath (MCRVersionedPath path ) throws IOException ;
737
+ protected abstract Path toPhysicalPath (MCRVersionedPath path ) throws IOException ;
732
738
733
739
/**
734
740
* Returns the change history of a path.
@@ -1001,7 +1007,7 @@ protected MCRVersionedPath lockVersion(MCRVersionedPath versionedPath) {
1001
1007
}
1002
1008
1003
1009
/**
1004
- * Releases the version on a given {@link MCRVersionedPath}, returning the path
1010
+ * Releases the version on a given {@link MCRVersionedPath}, returning the path
1005
1011
* that points to the latest (head) version of the virtual object.
1006
1012
* <p>
1007
1013
* This is necessary for the mycore event system. Due to the fact that the metadata is not yet
@@ -1012,7 +1018,7 @@ protected MCRVersionedPath lockVersion(MCRVersionedPath versionedPath) {
1012
1018
* TODO: This should be removed when the metadata is also included in the transaction system!
1013
1019
*
1014
1020
* @param versionedPath the {@link MCRVersionedPath} to release, retaining the same owner.
1015
- * @return a {@link MCRVersionedPath} that points to the head (latest) version of
1021
+ * @return a {@link MCRVersionedPath} that points to the head (latest) version of
1016
1022
* the path for the specified owner.
1017
1023
*/
1018
1024
protected MCRVersionedPath releaseVersion (MCRVersionedPath versionedPath ) {
@@ -1162,5 +1168,4 @@ protected MCRDigest calculateDigest(MCRVersionedPath path) {
1162
1168
throw new UncheckedIOException ("Unable to calculate digest for path '" + path + "'." , ioException );
1163
1169
}
1164
1170
}
1165
-
1166
1171
}
0 commit comments