@Override public T getContents() { return filterReadData(path, resource.getContents()); } };
@Override public Path getPath() { return delegate.getPath(); }
@Override public Resource<T> getResource(Path path) { final Resource<T> resource = super.getResource(path); if (!resource.isDirectory() && MatcherUtil.matches(path, resource.getContents(), pathSelector, resourceSelector)) { return filterGetResource(path, resource); } return resource; }
/** * Delete all resources and subdirectories of the given resource path * @param tree tree * @param path path * @return true if all resources were deleted successfully. */ public static boolean deletePathRecursive(Tree<ResourceMeta> tree, Path path){ if(tree.hasResource(path)) { //delete just this resource return tree.deleteResource(path); }else if (tree.hasDirectory(path)) { //list resources and delete Set<Resource<ResourceMeta>> resources = tree.listDirectory(path); boolean failed=false; for (Resource<ResourceMeta> resource : resources) { if(resource.isDirectory()){ if(!deletePathRecursive(tree,resource.getPath())){ failed=true; } }else { if(!tree.deleteResource(resource.getPath())){ failed=true; } } } return !failed; }else{ return true; } }
@Override public boolean isDirectory() { return delegate.isDirectory(); } }
@Override public Resource<ResourceMeta> getPath(AuthContext auth, Path path) { if (!authorizedPath(auth, path, READ)) { throw new StorageAuthorizationException("Unauthorized access", StorageException.Event.READ, path); } Resource<ResourceMeta> resource = storageTree.getPath(path); if (resource.isDirectory()) { return resource; } return resource; }
@Override public T getContents() { return delegate.getContents(); }
@Override public Resource<T> getPath(Path path) { final Resource<T> resource = super.getPath(path); if (!resource.isDirectory() && MatcherUtil.matches(path, resource.getContents(), pathSelector, resourceSelector)) { return filterGetResource(path, resource); } return resource; }
private Map<String, Resource<T>> asMap(Set<Resource<T>> matchedList) { HashMap<String, Resource<T>> map = new HashMap<>(); for (Resource<T> tResource : matchedList) { map.put(tResource.getPath().getPath(), tResource); } return map; }
private static byte[] readBytes(Resource<ResourceMeta> resource) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); resource.getContents().writeContent(byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); }
private Set<Resource<ResourceMeta>> filteredResources(AuthContext auth, Set<Resource<ResourceMeta>> resources, String action) { HashSet<Resource<ResourceMeta>> resources1 = new HashSet<Resource<ResourceMeta>>(); for (Resource<ResourceMeta> resource : resources) { if (authorizedPath(auth, resource.getPath(), action)) { resources1.add(resource); } } return resources1; }
@Override public void didGetPath(Path path, Resource<ResourceMeta> resource) { log(path, "get", resource.getContents() == null, null, null); }
/** * Expose a resource with a path that maps to external path * * @param resource * * @return */ private Resource<T> translateResourceExternal(Resource<T> resource) { if (fullPath) { return resource; } return new translatedResource<T>(resource, translatePathExternal(resource.getPath())); }
private byte[] loadStoragePathData(final String passwordStoragePath) throws IOException { if (null == passwordStoragePath) { return null; } ResourceMeta contents = context.getStorageTree().getResource(passwordStoragePath).getContents(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); contents.writeContent(byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); }
private boolean deleteRes(DirRes<T> dirRes) { boolean removed = false; if (!dirRes.dir) { Resource<T> res = dirRes.res; removed = index.remove(res.getPath()) != null; Path parentPath = PathUtil.parentPath(res.getPath()); if (!PathUtil.isRoot(parentPath) && null != index.get(parentPath)) { DirRes<T> parentRes = index.get(parentPath); parentRes.dirList.remove(res.getPath()); //remove parent dir if empty dirRes = parentRes; } else { return removed; } } while (null != dirRes && dirRes.dir && dirRes.dirList.size() < 1) { index.remove(dirRes.getPath()); Path parentPath = PathUtil.parentPath(dirRes.getPath()); if (parentPath != null && !PathUtil.isRoot(parentPath)) { DirRes<T> parentRes = index.get(parentPath); parentRes.dirList.remove(dirRes.getPath()); dirRes = parentRes; } else { dirRes = null; } } return removed; }
private byte[] loadStoragePathData(final String passwordStoragePath) throws IOException { if (null == passwordStoragePath) { return null; } ResourceMeta contents = context.getStorageTree().getResource(passwordStoragePath).getContents(); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); contents.writeContent(byteArrayOutputStream); return byteArrayOutputStream.toByteArray(); }
@Override public void didGetResource(Path path, Resource<ResourceMeta> resource) { log(path, "get", false, resource.getContents().getMeta(), null); }
@Override public boolean hasResourceWithType(final Path path, final String contentType) { boolean exists = hasResource(path); if (!exists) { return false; } Resource<ResourceMeta> resource = getResource(path); return resource.getContents().getContentType().equals(contentType); }
@Override public Resource<ResourceMeta> getResourceWithType(Path path, String contentType) { Resource<ResourceMeta> resource = getResource(path); if (resource.getContents().getContentType().equals(contentType)) { return resource; } throw new WrongContentType( "Path ${path} does not store a password, content-type: ${resource.contents.contentType}", StorageException.Event.READ, path ); }
@Override public Resource<T> getPath(Path path) { Resource<T> path1 = super.getPath(path); if (matches(path, null != path1 ? path1.getContents() : null)) { listener.didGetPath(path, path1); } return path1; }