@Override public Object getAttribute(final Path path, final String attribute) throws UnsupportedOperationException, IllegalArgumentException, IOException, SecurityException { checkNotNull("path", path); Object value; try { value = Files.getAttribute(path, attribute); } catch (UnsupportedOperationException ex) { value = null; } if (value == null && path instanceof AttrHolder) { final AttrHolder holder = ((AttrHolder) path); final String[] attr = split(attribute); if (holder.getAttrStorage().getContent().isEmpty()) { loadDotFile(path); } return holder.getAttrStorage().getAllContent().get(attr[1]); } return value; }
protected <V extends AbstractBasicFileAttributeView> V newView(final AttrHolder holder, final Class<V> type) { if (NeedsPreloadedAttrs.class.isAssignableFrom(type) && holder.getAttrStorage().getContent().size() == 0) { readAttributes((Path) holder); } try { final Constructor<V> constructor = (Constructor<V>) type.getConstructors()[0]; final V view = constructor.newInstance(holder); holder.addAttrView(view); return view; } catch (final Exception e) { } return null; }
@Override public <V extends FileAttributeView> V getFileAttributeView(final Path path, final Class<V> type) throws IllegalArgumentException { final V value = Files.getFileAttributeView(path, type); if (value == null && path instanceof AttrHolder) { final AttrHolder holder = ((AttrHolder) path); final V holderView = holder.getAttrView(type); if (holderView == null && AbstractBasicFileAttributeView.class.isAssignableFrom(type)) { return (V) newView(holder, (Class<? extends AbstractBasicFileAttributeView>) type); } return holderView; } return value; }
@Override public boolean deleteIfExists(final Path path, final DeleteOption... options) throws IllegalArgumentException, DirectoryNotEmptyException, IOException, SecurityException { final boolean result = Files.deleteIfExists(path, options); try { Files.deleteIfExists(dot(path), options); } catch (Exception ex) { } if (path instanceof AttrHolder) { ((AttrHolder) path).getAttrStorage().clear(); } return result; }
@Override public void delete(final Path path, final DeleteOption... options) throws IllegalArgumentException, NoSuchFileException, DirectoryNotEmptyException, IOException, SecurityException { Files.delete(path, options); try { Files.deleteIfExists(dot(path), options); } catch (Exception ex) { } if (path instanceof AttrHolder) { ((AttrHolder) path).getAttrStorage().clear(); } }
protected void loadDotFile(final Path path) { final Properties content = new Properties(); content.load(newInputStream(dot(path))); if (path instanceof AttrHolder) { ((AttrHolder) path).getAttrStorage().loadContent(content); } }
@Override public Map<String, Object> readAttributes(final Path path, final String attributes) throws UnsupportedOperationException, NoSuchFileException, IllegalArgumentException, IOException, SecurityException { checkNotNull("path", path); checkNotEmpty("attributes", attributes); final Properties original = new Properties(Files.readAttributes(path, attributes)); if (attributes.equals("*") && exists(dot(path))) { boolean isAttrHolder = path instanceof AttrHolder; if (isAttrHolder && ((AttrHolder) path).getAttrStorage().getContent().size() > 0) { return ((AttrHolder) path).getAttrStorage().getAllContent(); } final Properties content = new Properties(); content.load(newInputStream(dot(path))); content.putAll(original); if (isAttrHolder) { ((AttrHolder) path).getAttrStorage().loadContent(content); } return content; } return original; }
((AttrHolder) path).getAttrStorage().loadContent(properties);
((AttrHolder) path).getAttrStorage().clear();
((AttrHolder) path).getAttrStorage().clear();
((AttrHolder) path).getAttrStorage().loadContent(properties);
((AttrHolder) path).getAttrStorage().clear();
((AttrHolder) path).getAttrStorage().clear();
assertFalse(((AttrHolder) file).getAttrStorage().getContent().isEmpty()); assertTrue(((AttrHolder) file).getAttrStorage().getContent().isEmpty());
assertFalse(((AttrHolder) file).getAttrStorage().getContent().isEmpty()); assertTrue(((AttrHolder) file).getAttrStorage().getContent().isEmpty());
assertTrue(ioService().exists(dot(file))); assertFalse(((AttrHolder) file).getAttrStorage().getContent().isEmpty()); assertTrue(((AttrHolder) file).getAttrStorage().getContent().isEmpty());
assertTrue(ioService().exists(dot(file))); assertFalse(((AttrHolder) file).getAttrStorage().getContent().isEmpty()); assertTrue(((AttrHolder) file).getAttrStorage().getContent().isEmpty());
attr.getAuthor()); ((AttrHolder) file).getAttrStorage().clear();
attr.getAuthor()); ((AttrHolder) file).getAttrStorage().clear();
"something")); ((AttrHolder) file).getAttrStorage().clear();