Search in sources :

Example 1 with FoldersApi

use of ch.cyberduck.core.brick.io.swagger.client.api.FoldersApi in project cyberduck by iterate-ch.

the class BrickListService method list.

public AttributedList<Path> list(final Path directory, final ListProgressListener listener, final int chunksize) throws BackgroundException {
    try {
        final AttributedList<Path> children = new AttributedList<>();
        String cursor = null;
        List<FileEntity> response;
        final BrickApiClient client = new BrickApiClient(session);
        do {
            response = new FoldersApi(client).foldersListForPath(StringUtils.removeStart(directory.getAbsolute(), String.valueOf(Path.DELIMITER)), cursor, chunksize, null, null, null, null, null, null);
            for (FileEntity entity : response) {
                children.add(new Path(entity.getPath(), EnumSet.of("directory".equals(entity.getType()) ? Path.Type.directory : Path.Type.file), attributes.toAttributes(entity)));
            }
            if (client.getResponseHeaders().containsKey("X-Files-Cursor")) {
                final Optional<String> header = client.getResponseHeaders().get("X-Files-Cursor").stream().findFirst();
                cursor = header.orElse(null);
            } else {
                cursor = null;
            }
            listener.chunk(directory, children);
        } while (cursor != null);
        return children;
    } catch (ApiException e) {
        throw new BrickExceptionMappingService().map("Listing directory {0} failed", e, directory);
    }
}
Also used : Path(ch.cyberduck.core.Path) FoldersApi(ch.cyberduck.core.brick.io.swagger.client.api.FoldersApi) FileEntity(ch.cyberduck.core.brick.io.swagger.client.model.FileEntity) AttributedList(ch.cyberduck.core.AttributedList) ApiException(ch.cyberduck.core.brick.io.swagger.client.ApiException)

Aggregations

AttributedList (ch.cyberduck.core.AttributedList)1 Path (ch.cyberduck.core.Path)1 ApiException (ch.cyberduck.core.brick.io.swagger.client.ApiException)1 FoldersApi (ch.cyberduck.core.brick.io.swagger.client.api.FoldersApi)1 FileEntity (ch.cyberduck.core.brick.io.swagger.client.model.FileEntity)1