diff options
author | Colin Decker <cgdecker@google.com> | 2013-12-11 16:47:26 -0500 |
---|---|---|
committer | Colin Decker <cgdecker@google.com> | 2013-12-11 16:47:26 -0500 |
commit | b3ebabc6480ff6bb2dc8b6eabd0f9383ead8d879 (patch) | |
tree | 9b820652afa28024c72cc76cbfd1607cdc4e8f43 /jimfs/src/main | |
parent | 80a99d31a4d65ebd583c40255474bfa481ca0ff6 (diff) | |
download | jimfs-b3ebabc6480ff6bb2dc8b6eabd0f9383ead8d879.tar.gz |
Various changes in attribute package.
Diffstat (limited to 'jimfs/src/main')
13 files changed, 34 insertions, 40 deletions
diff --git a/jimfs/src/main/java/com/google/jimfs/Configuration.java b/jimfs/src/main/java/com/google/jimfs/Configuration.java index f990c99..e5fbe59 100644 --- a/jimfs/src/main/java/com/google/jimfs/Configuration.java +++ b/jimfs/src/main/java/com/google/jimfs/Configuration.java @@ -25,7 +25,6 @@ import static com.google.jimfs.path.Normalization.NFD; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.google.jimfs.attribute.AttributeProvider; diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/AbstractAttributeView.java b/jimfs/src/main/java/com/google/jimfs/attribute/AbstractAttributeView.java index 62424bd..c88e7ca 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/AbstractAttributeView.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/AbstractAttributeView.java @@ -30,14 +30,14 @@ abstract class AbstractAttributeView implements FileAttributeView { private final Inode.Lookup lookup; - public AbstractAttributeView(Inode.Lookup lookup) { + protected AbstractAttributeView(Inode.Lookup lookup) { this.lookup = checkNotNull(lookup); } /** * Gets the inode object to get or set attributes on. */ - public final Inode lookupInode() throws IOException { + protected final Inode lookupInode() throws IOException { return lookup.lookup(); } } diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/AclAttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/AclAttributeProvider.java index bb6c7f0..a106ce8 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/AclAttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/AclAttributeProvider.java @@ -62,7 +62,7 @@ final class AclAttributeProvider extends AttributeProvider { } @Override - public Map<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { + public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { Object userProvidedAcl = userProvidedDefaults.get("acl:acl"); ImmutableList<AclEntry> acl = DEFAULT_ACL; @@ -137,7 +137,7 @@ final class AclAttributeProvider extends AttributeProvider { @SuppressWarnings("unchecked") @Override public List<AclEntry> getAcl() throws IOException { - return lookupInode().getAttribute("acl:acl"); + return (List<AclEntry>) lookupInode().getAttribute("acl:acl"); } @Override diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/AttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/AttributeProvider.java index 9216269..01dcf5c 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/AttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/AttributeProvider.java @@ -71,7 +71,7 @@ public abstract class AttributeProvider { * that should be done. The resulting values should be included in the result map along with * default values for any attributes the user did not provide a value for. */ - public Map<String, ?> defaultValues(Map<String, ?> userDefaults) { + public ImmutableMap<String, ?> defaultValues(Map<String, ?> userDefaults) { return ImmutableMap.of(); } @@ -151,20 +151,12 @@ public abstract class AttributeProvider { */ protected static void checkNotCreate(String view, String attribute, boolean create) { if (create) { - throw unsettableOnCreate(view, attribute); + throw new UnsupportedOperationException( + "cannot set attribute '" + view + ":" + attribute + "' during file creation"); } } /** - * Throws an unsupported operation exception indicating that the given attribute cannot be set - * during file creation. - */ - protected static UnsupportedOperationException unsettableOnCreate(String view, String attribute) { - throw new UnsupportedOperationException( - "cannot set attribute '" + view + ":" + attribute + "' during file creation"); - } - - /** * Checks that the given value is of the given type, returning the value if so and throwing an * exception if not. */ diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/DosAttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/DosAttributeProvider.java index c83a157..1a37aec 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/DosAttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/DosAttributeProvider.java @@ -63,7 +63,7 @@ final class DosAttributeProvider extends AttributeProvider { } @Override - public Map<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { + public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { return ImmutableMap.of( "dos:readonly", getDefaultValue("dos:readonly", userProvidedDefaults), "dos:hidden", getDefaultValue("dos:hidden", userProvidedDefaults), @@ -183,10 +183,10 @@ final class DosAttributeProvider extends AttributeProvider { protected Attributes(Inode inode) { super(inode); - this.readOnly = inode.getAttribute("dos:readonly"); - this.hidden = inode.getAttribute("dos:hidden"); - this.archive = inode.getAttribute("dos:archive"); - this.system = inode.getAttribute("dos:system"); + this.readOnly = (boolean) inode.getAttribute("dos:readonly"); + this.hidden = (boolean) inode.getAttribute("dos:hidden"); + this.archive = (boolean) inode.getAttribute("dos:archive"); + this.system = (boolean) inode.getAttribute("dos:system"); } @Override diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/Inode.java b/jimfs/src/main/java/com/google/jimfs/attribute/Inode.java index 5e59ca1..9356784 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/Inode.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/Inode.java @@ -167,17 +167,14 @@ public abstract class Inode { } /** - * Gets the value of the attribute with the given key. The value is automatically cast to the - * target type inferred by the call site, as it is assumed that the caller knows what type the - * value will be. + * Gets the value of the attribute with the given key. */ - @SuppressWarnings("unchecked") @Nullable - public final synchronized <T> T getAttribute(String key) { + public final synchronized Object getAttribute(String key) { if (attributes == null) { return null; } - return (T) attributes.get(key); + return attributes.get(key); } /** diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/OwnerAttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/OwnerAttributeProvider.java index 5481a1d..ea24c85 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/OwnerAttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/OwnerAttributeProvider.java @@ -52,7 +52,7 @@ final class OwnerAttributeProvider extends AttributeProvider { } @Override - public Map<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { + public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { Object userProvidedOwner = userProvidedDefaults.get("owner:owner"); UserPrincipal owner = DEFAULT_OWNER; @@ -117,7 +117,7 @@ final class OwnerAttributeProvider extends AttributeProvider { @Override public UserPrincipal getOwner() throws IOException { - return lookupInode().getAttribute("owner:owner"); + return (UserPrincipal) lookupInode().getAttribute("owner:owner"); } @Override diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/PosixAttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/PosixAttributeProvider.java index 37a5c33..6a91f7c 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/PosixAttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/PosixAttributeProvider.java @@ -74,7 +74,7 @@ final class PosixAttributeProvider extends AttributeProvider { @SuppressWarnings("unchecked") @Override - public Map<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { + public ImmutableMap<String, ?> defaultValues(Map<String, ?> userProvidedDefaults) { Object userProvidedGroup = userProvidedDefaults.get("posix:group"); UserPrincipal group = DEFAULT_GROUP; @@ -245,9 +245,10 @@ final class PosixAttributeProvider extends AttributeProvider { @SuppressWarnings("unchecked") protected Attributes(Inode inode) { super(inode); - this.owner = inode.getAttribute("owner:owner"); - this.group = inode.getAttribute("posix:group"); - this.permissions = inode.getAttribute("posix:permissions"); + this.owner = (UserPrincipal) inode.getAttribute("owner:owner"); + this.group = (GroupPrincipal) inode.getAttribute("posix:group"); + this.permissions = + (ImmutableSet<PosixFilePermission>) inode.getAttribute("posix:permissions"); } @Override diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/StandardAttributeProviders.java b/jimfs/src/main/java/com/google/jimfs/attribute/StandardAttributeProviders.java index e410729..fa39473 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/StandardAttributeProviders.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/StandardAttributeProviders.java @@ -80,7 +80,6 @@ public final class StandardAttributeProviders { .put("basic", new BasicAttributeProvider()) .put("owner", new OwnerAttributeProvider()) .put("posix", new PosixAttributeProvider()) - .put("unix", new UnixAttributeProvider()) .put("dos", new DosAttributeProvider()) .put("acl", new AclAttributeProvider()) .put("user", new UserDefinedAttributeProvider()) diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/UnixAttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/UnixAttributeProvider.java index 68ee3b8..554e4d6 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/UnixAttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/UnixAttributeProvider.java @@ -77,7 +77,9 @@ final class UnixAttributeProvider extends AttributeProvider { @Override public UnixFileAttributeView view(Inode.Lookup lookup, ImmutableMap<String, FileAttributeView> inheritedViews) { - throw new UnsupportedOperationException(); // should not be called + // This method should not be called... and it cannot be called through the public APIs in + // java.nio.file since there is no public UnixFileAttributeView type. + throw new UnsupportedOperationException(); } // TODO(cgdecker): Since we can now guarantee that the owner/group for an inode are our own @@ -107,13 +109,14 @@ final class UnixAttributeProvider extends AttributeProvider { public Object get(Inode inode, String attribute) { switch (attribute) { case "uid": - UserPrincipal user = inode.getAttribute("owner:owner"); + UserPrincipal user = (UserPrincipal) inode.getAttribute("owner:owner"); return getUniqueId(user); case "gid": - GroupPrincipal group = inode.getAttribute("posix:group"); + GroupPrincipal group = (GroupPrincipal) inode.getAttribute("posix:group"); return getUniqueId(group); case "mode": - Set<PosixFilePermission> permissions = inode.getAttribute("posix:permissions"); + Set<PosixFilePermission> permissions = + (Set<PosixFilePermission>) inode.getAttribute("posix:permissions"); return toMode(permissions); case "ctime": return FileTime.fromMillis(inode.getCreationTime()); diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/UserDefinedAttributeProvider.java b/jimfs/src/main/java/com/google/jimfs/attribute/UserDefinedAttributeProvider.java index 6c0e878..c29abf6 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/UserDefinedAttributeProvider.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/UserDefinedAttributeProvider.java @@ -135,7 +135,7 @@ final class UserDefinedAttributeProvider extends AttributeProvider { } private byte[] getStoredBytes(String name) throws IOException { - byte[] bytes = lookupInode().getAttribute(name() + ":" + name); + byte[] bytes = (byte[]) lookupInode().getAttribute(name() + ":" + name); if (bytes == null) { throw new IllegalArgumentException("attribute '" + name() + ":" + name + "' is not set"); } diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/UserPrincipals.java b/jimfs/src/main/java/com/google/jimfs/attribute/UserPrincipals.java index aa589fc..2bcb846 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/UserPrincipals.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/UserPrincipals.java @@ -28,6 +28,8 @@ import java.nio.file.attribute.UserPrincipal; */ public final class UserPrincipals { + private UserPrincipals() {} + /** * Creates a {@link UserPrincipal} for the given user name. */ diff --git a/jimfs/src/main/java/com/google/jimfs/attribute/package-info.java b/jimfs/src/main/java/com/google/jimfs/attribute/package-info.java index e0e26fd..92774b8 100644 --- a/jimfs/src/main/java/com/google/jimfs/attribute/package-info.java +++ b/jimfs/src/main/java/com/google/jimfs/attribute/package-info.java @@ -15,7 +15,8 @@ */ /** - * Package containing classes used for configuration of file attribute handling. + * Package containing classes used for configuration of + * <a href="https://www.google.com/url?sa=D&q=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FFile_attribute">file attribute</a> handling. * * <p>Users can create a subclass of * {@link com.google.jimfs.attribute.AttributeProvider AttributeProvider} to implement handling of |