class B2BucketListService implements RootListService {

    @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);
        }
    }

    public  B2BucketListService(final B2Session session);

}