src/share/classes/sun/nio/fs/AbstractBasicFileAttributeView.java

Print this page

        

*** 44,53 **** --- 44,65 ---- private static final String IS_DIRECTORY_NAME = "isDirectory"; private static final String IS_REGULAR_FILE_NAME = "isRegularFile"; private static final String IS_SYMBOLIC_LINK_NAME = "isSymbolicLink"; private static final String IS_OTHER_NAME = "isOther"; + // the names of the basic attributes + static final Set<String> basicAttributeNames = + Util.newSet(SIZE_NAME, + CREATION_TIME_NAME, + LAST_ACCESS_TIME_NAME, + LAST_MODIFIED_TIME_NAME, + FILE_KEY_NAME, + IS_DIRECTORY_NAME, + IS_REGULAR_FILE_NAME, + IS_SYMBOLIC_LINK_NAME, + IS_OTHER_NAME); + protected AbstractBasicFileAttributeView() { } @Override public String name() { return "basic";
*** 67,116 **** } if (attribute.equals(CREATION_TIME_NAME)) { setTimes(null, null, (FileTime)value); return; } ! throw new UnsupportedOperationException("'" + attribute + ! "' is unknown or read-only attribute"); } /** * Used to build a map of attribute name/values. */ static class AttributesBuilder { ! private Set<String> set = new HashSet<>(); private Map<String,Object> map = new HashMap<>(); private boolean copyAll; ! private AttributesBuilder(String[] attributes) { ! for (String attribute: attributes) { ! if (attribute.equals("*")) { copyAll = true; } else { ! set.add(attribute); } } } /** * Creates builder to build up a map of the matching attributes */ ! static AttributesBuilder create(String[] attributes) { ! return new AttributesBuilder(attributes); } /** * Returns true if the attribute should be returned in the map */ ! boolean match(String attribute) { ! if (copyAll) ! return true; ! return set.contains(attribute); } ! void add(String attribute, Object value) { ! map.put(attribute, value); } /** * Returns the map. Discard all references to the AttributesBuilder * after invoking this method. --- 79,128 ---- } if (attribute.equals(CREATION_TIME_NAME)) { setTimes(null, null, (FileTime)value); return; } ! throw new IllegalArgumentException("'" + name() + ":" + ! attribute + "' not recognized"); } /** * Used to build a map of attribute name/values. */ static class AttributesBuilder { ! private Set<String> names = new HashSet<>(); private Map<String,Object> map = new HashMap<>(); private boolean copyAll; ! private AttributesBuilder(Set<String> allowed, String[] requested) { ! for (String name: requested) { ! if (name.equals("*")) { copyAll = true; } else { ! if (!allowed.contains(name)) ! throw new IllegalArgumentException("'" + name + "' not recognized"); ! names.add(name); } } } /** * Creates builder to build up a map of the matching attributes */ ! static AttributesBuilder create(Set<String> allowed, String[] requested) { ! return new AttributesBuilder(allowed, requested); } /** * Returns true if the attribute should be returned in the map */ ! boolean match(String name) { ! return copyAll || names.contains(name); } ! void add(String name, Object value) { ! map.put(name, value); } /** * Returns the map. Discard all references to the AttributesBuilder * after invoking this method.
*** 122,132 **** /** * Invoked by readAttributes or sub-classes to add all matching basic * attributes to the builder */ ! final void addBasicAttributesToBuilder(BasicFileAttributes attrs, AttributesBuilder builder) { if (builder.match(SIZE_NAME)) builder.add(SIZE_NAME, attrs.size()); if (builder.match(CREATION_TIME_NAME)) --- 134,144 ---- /** * Invoked by readAttributes or sub-classes to add all matching basic * attributes to the builder */ ! final void addRequestedBasicAttributes(BasicFileAttributes attrs, AttributesBuilder builder) { if (builder.match(SIZE_NAME)) builder.add(SIZE_NAME, attrs.size()); if (builder.match(CREATION_TIME_NAME))
*** 146,156 **** if (builder.match(IS_OTHER_NAME)) builder.add(IS_OTHER_NAME, attrs.isOther()); } @Override ! public Map<String,Object> readAttributes(String[] attributes) throws IOException { ! AttributesBuilder builder = AttributesBuilder.create(attributes); ! addBasicAttributesToBuilder(readAttributes(), builder); return builder.unmodifiableMap(); } } --- 158,171 ---- if (builder.match(IS_OTHER_NAME)) builder.add(IS_OTHER_NAME, attrs.isOther()); } @Override ! public Map<String,Object> readAttributes(String[] requested) ! throws IOException ! { ! AttributesBuilder builder = ! AttributesBuilder.create(basicAttributeNames, requested); ! addRequestedBasicAttributes(readAttributes(), builder); return builder.unmodifiableMap(); } }