Added creation time

* Getter and setter for files and folders
* A way to determine if a file system supports creation dates
* WebDav compliant implementation in jackrabbit-adapter
* Tests
This commit is contained in:
Markus Kreusch
2016-01-09 00:51:25 +01:00
parent a746a73667
commit 415423abd7
40 changed files with 735 additions and 24 deletions
@@ -23,4 +23,8 @@ public interface FileSystem extends Folder {
return Optional.empty();
}
default boolean supports(FileSystemFeature feature) {
return false;
}
}
@@ -0,0 +1,5 @@
package org.cryptomator.filesystem;
public enum FileSystemFeature {
CREATION_TIME_FEATURE
}
@@ -7,6 +7,7 @@ package org.cryptomator.filesystem;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.stream.Stream;
/**
@@ -148,4 +149,18 @@ public interface Folder extends Node {
}
}
/**
* <p>
* Sets the creation time of the folder.
* <p>
* Setting the creation time may not be supported by all {@link FileSystem FileSystems}. If the {@code FileSystem} this {@code Folder} belongs to does not support the
* {@link FileSystemFeature#CREATION_TIME_FEATURE} the behavior of this method is unspecified.
*
* @param instant the time to set as creation time
* @see FileSystem#supports(Class)
*/
default void setCreationTime(Instant instant) throws UncheckedIOException {
throw new UncheckedIOException(new IOException("CreationTime not supported"));
}
}
@@ -5,6 +5,7 @@
******************************************************************************/
package org.cryptomator.filesystem;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.Optional;
@@ -33,6 +34,20 @@ public interface Node {
Instant lastModified() throws UncheckedIOException;
/**
* <p>
* Determines the creation time of this node.
* <p>
* Setting the creation time may not be supported by all {@link FileSystem FileSystems}. If the {@code FileSystem} this {@code Node} belongs to does not support the
* {@link FileSystemFeature#CREATION_TIME_FEATURE} the behavior of this method is unspecified.
*
* @returns the creation time of the file.
* @see FileSystem#supports(Class)
*/
default Instant creationTime() throws UncheckedIOException {
throw new UncheckedIOException(new IOException("CreationTime not supported"));
}
/**
* @return the {@link FileSystem} this Node belongs to
*/
@@ -24,6 +24,20 @@ public interface WritableFile extends WritableByteChannel {
void setLastModified(Instant instant) throws UncheckedIOException;
/**
* <p>
* Sets the creation time of the file.
* <p>
* Setting the creation time may not be supported by all {@link FileSystem FileSystems}. If the {@code FileSystem} this {@code WritableFile} belongs to does not support the
* {@link FileSystemFeature#CREATION_TIME_FEATURE} the behavior of this method is unspecified.
*
* @param instant the time to set as creation time
* @see FileSystem#supports(Class)
*/
default void setCreationTime(Instant instant) throws UncheckedIOException {
throw new UncheckedIOException(new IOException("CreationTime not supported"));
}
/**
* <p>
* Deletes this file from the file system.
@@ -9,6 +9,7 @@
package org.cryptomator.filesystem.delegating;
import java.io.UncheckedIOException;
import java.time.Instant;
import java.util.Optional;
import java.util.stream.Stream;
@@ -90,4 +91,9 @@ public abstract class DelegatingFolder<R extends DelegatingReadableFile, W exten
}
}
@Override
public void setCreationTime(Instant instant) throws UncheckedIOException {
delegate.setCreationTime(instant);
}
}
@@ -39,6 +39,11 @@ abstract class DelegatingNode<T extends Node> implements Node {
return delegate.lastModified();
}
@Override
public Instant creationTime() throws UncheckedIOException {
return delegate.creationTime();
}
@Override
public int hashCode() {
return delegate.hashCode();
@@ -67,4 +67,9 @@ public class DelegatingWritableFile implements WritableFile {
delegate.close();
}
@Override
public void setCreationTime(Instant instant) throws UncheckedIOException {
delegate.setCreationTime(instant);
}
}