/** * @param collection Default content */ public AttributedList(final Iterable<E> collection) { for(E e : collection) { this.add(e); } }
public boolean addAll(final Iterable<? extends E> c) { for(E file : c) { this.add(file); } return true; }
private void parse(final Path directory, final ListProgressListener listener, final AttributedList<Path> children, final ListFolderResult result) throws ConnectionCanceledException { for(Metadata md : result.getEntries()) { final Path child = this.parse(directory, md); if(child == null) { continue; } children.add(child); listener.chunk(directory, children); } }
public AttributedList<Local> list(final String path, final Filter<String> filter) throws AccessDeniedException { final AttributedList<Local> children = new AttributedList<Local>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(path), new DirectoryStream.Filter<Path>() { @Override public boolean accept(final Path entry) { if(null == entry.getFileName()) { return false; } return filter.accept(entry.getFileName().toString()); } })) { for(Path entry : stream) { children.add(LocalFactory.get(entry.toString())); } } catch(IOException e) { throw new LocalAccessDeniedException(MessageFormat.format( LocaleFactory.localizedString("Listing directory {0} failed", "Error"), this.getName()), e); } return children; }
paths.add(file); listener.chunk(directory, paths);
@Override public AttributedList<Path> search(final Path workdir, final Filter<Path> regex, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> list = new AttributedList<>(); final OneDriveFolder folder = session.toFolder(workdir); // The query text used to search for items. Values may be matched across several fields including filename, metadata, and file content. final Iterator<OneDriveItem.Metadata> iterator = folder.search(regex.toPattern().pattern()).iterator(); while(iterator.hasNext()) { final OneDriveItem.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e); continue; } list.add(new Path(String.format("/%s/%s/%s", metadata.getParentReference().getDriveId(), StringUtils.removeStart(metadata.getParentReference().getPath(), "/drive/root:"), metadata.getName()), metadata.isFolder() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attributes.toAttributes(metadata))); } return list; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); list.add(DriveHomeFinderService.MYDRIVE_FOLDER); list.add(DriveHomeFinderService.SHARED_FOLDER_NAME); list.add(DriveHomeFinderService.TEAM_DRIVES_NAME); listener.chunk(directory, list); return list; } else { if(DriveHomeFinderService.SHARED_FOLDER_NAME.equals(directory)) { return new DriveSharedFolderListService(session, fileid).list(directory, listener); } if(DriveHomeFinderService.TEAM_DRIVES_NAME.equals(directory)) { return new DriveTeamDrivesListService(session).list(directory, listener); } return new DriveDefaultListService(session, fileid).list(directory, listener); } }
protected final AttributedList<Path> iterate(final Iterator<OneDriveDrive.Metadata> iterator, final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); while(iterator.hasNext()) { final OneDriveDrive.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(metadata.getId()); attributes.setSize(metadata.getTotal()); String name = metadata.getName(); if(StringUtils.isBlank(metadata.getName())) { name = metadata.getId(); } children.add(new Path(directory, name, EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); listener.chunk(directory, children); } return children; }
@Override public AttributedList<Path> get(final Path folder) { final AttributedList<Path> decrypted = delegate.get(this.toDecrypted(folder)); final AttributedList<Path> list = new AttributedList<>(); // Swap with encrypted paths for(int i = 0; i < decrypted.size(); i++) { final Path f = decrypted.get(i); list.add(i, this.toEncrypted(f)); } return list; }
@Override public AttributedList<Path> put(final Path folder, final AttributedList<Path> encrypted) { final AttributedList<Path> list = new AttributedList<>(); // Swap with decrypted paths for(int i = 0; i < encrypted.size(); i++) { final Path f = encrypted.get(i); list.add(i, this.toDecrypted(f)); } return delegate.put(this.toDecrypted(folder), list); }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> children = new AttributedList<Path>(); for(final DavResource resource : this.list(directory)) { // Try to parse as RFC 2396 final String href = PathNormalizer.normalize(resource.getHref().getPath(), true); if(href.equals(directory.getAbsolute())) { log.warn(String.format("Ignore resource %s", href)); // Do not include self if(resource.isDirectory()) { continue; } throw new NotfoundException(directory.getAbsolute()); } final PathAttributes attr = attributes.toAttributes(resource); final Path file = new Path(directory, PathNormalizer.name(href), resource.isDirectory() ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file), attr); children.add(file); listener.chunk(directory, children); } return children; } catch(SardineException e) { throw new DAVExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new HttpExceptionMappingService().map(e, directory); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); final GroupsIterator groupsIterator = new GroupsIterator(session.getClient()); while(groupsIterator.hasNext()) { final GroupItem.Metadata metadata; try { metadata = groupsIterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(metadata.getId()); children.add(new Path(directory, metadata.getDisplayName(), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); listener.chunk(directory, children); } return children; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { final AttributedList<Path> children = new AttributedList<>(); final OneDriveFolder folder = session.toFolder(directory); try { final Iterator<OneDriveItem.Metadata> iterator = folder.iterator(PreferencesFactory.get().getInteger("onedrive.listing.chunksize")); while(iterator.hasNext()) { final OneDriveItem.Metadata metadata; try { metadata = iterator.next(); } catch(OneDriveRuntimeException e) { log.warn(e.getMessage()); continue; } final PathAttributes attr = attributes.toAttributes(metadata); children.add(new Path(directory, metadata.getName(), resolveType(metadata), attr)); listener.chunk(directory, children); } } catch(OneDriveRuntimeException e) { // this catches iterator.hasNext() which in return should fail fast throw new GraphExceptionMappingService().map("Listing directory {0} failed", e.getCause(), directory); } return children; }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> children = new AttributedList<>(); String page = null; do { final TeamDriveList list = session.getClient().teamdrives().list() .setPageToken(page) .setPageSize(pagesize) .execute(); for(TeamDrive f : list.getTeamDrives()) { final Path child = new Path(directory, f.getName(), EnumSet.of(Path.Type.directory, Path.Type.volume), new PathAttributes().withVersionId(f.getId())); children.add(child); } listener.chunk(directory, children); page = list.getNextPageToken(); if(log.isDebugEnabled()) { log.debug(String.format("Continue with next page token %s", page)); } } while(page != null); return children; } catch(IOException e) { throw new DriveExceptionMappingService().map("Listing directory failed", e, directory); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { if(directory.isRoot()) { final AttributedList<Path> list = new AttributedList<>(); list.add(DEFAULT_NAME); list.add(GROUPS_NAME); listener.chunk(directory, list); return list; } else { if(DEFAULT_NAME.equals(directory)) { return new GraphDrivesListService(session).list(directory, listener); } else if(GROUPS_NAME.equals(directory)) { return new SharepointGroupListService(session).list(directory, listener); } else if(GROUPS_NAME.equals(directory.getParent())) { return new SharepointGroupDrivesListService(session).list(directory, listener); } return new GraphItemListService(session).list(directory, listener); } }
EnumSet.of(o.isDirectory() ? Path.Type.directory : Path.Type.file), adapter.convert(o) ); children.add(file); listener.chunk(directory, children);
children.add(file); listener.chunk(directory, children);
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { ResultSegment<CloudBlobContainer> result; ResultContinuation token = null; try { final AttributedList<Path> containers = new AttributedList<Path>(); do { final BlobRequestOptions options = new BlobRequestOptions(); result = session.getClient().listContainersSegmented(null, ContainerListingDetails.NONE, preferences.getInteger("azure.listing.chunksize"), token, options, context); for(CloudBlobContainer container : result.getResults()) { final PathAttributes attributes = new PathAttributes(); attributes.setETag(container.getProperties().getEtag()); attributes.setModificationDate(container.getProperties().getLastModified().getTime()); containers.add(new Path(PathNormalizer.normalize(container.getName()), EnumSet.of(Path.Type.volume, Path.Type.directory), attributes)); } listener.chunk(directory, containers); token = result.getContinuationToken(); } while(result.getHasMoreResults()); return containers; } catch(StorageException e) { throw new AzureExceptionMappingService().map("Listing directory {0} failed", e, directory); } }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> buckets = new AttributedList<Path>(); for(B2BucketResponse bucket : session.getClient().listBuckets()) { final PathAttributes attributes = new PathAttributes(); attributes.setVersionId(bucket.getBucketId()); switch(bucket.getBucketType()) { case allPublic: attributes.setAcl(new Acl(new Acl.GroupUser(Acl.GroupUser.EVERYONE, false), new Acl.Role(Acl.Role.READ))); break; } buckets.add(new Path(PathNormalizer.normalize(bucket.getBucketName()), EnumSet.of(Path.Type.directory, Path.Type.volume), attributes)); } listener.chunk(directory, buckets); return buckets; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }