@Test public void testList() throws Exception { final B2FileidProvider fileid = new B2FileidProvider(session).withCache(cache); final Path bucket = new B2DirectoryFeature(session, fileid).mkdir( new Path(String.format("test-%s", new AsciiRandomStringService().random()), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final Path file = new Path(bucket, new AsciiRandomStringService().random(), EnumSet.of(Path.Type.file)); final TransferStatus status = new TransferStatus(); status.setChecksum(Checksum.parse("da39a3ee5e6b4b0d3255bfef95601890afd80709")); final HttpResponseOutputStream<BaseB2Response> out = new B2WriteFeature(session, fileid).write(file, status, new DisabledConnectionCallback()); IOUtils.write(new byte[0], out); out.close(); final B2FileResponse resopnse = (B2FileResponse) out.getStatus(); final AttributedList<Path> list = new B2ObjectListService(session, fileid).list(bucket, new DisabledListProgressListener()); assertNotNull(list.find(new SimplePathPredicate(file))); assertEquals(Long.valueOf(1L), list.find(new SimplePathPredicate(file)).attributes().getRevision()); assertEquals(0L, list.find(new SimplePathPredicate(file)).attributes().getSize()); new B2DeleteFeature(session, fileid).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback()); assertFalse(new B2ObjectListService(session, fileid).list(bucket, new DisabledListProgressListener()).contains(file)); new B2DeleteFeature(session, fileid).delete(Collections.singletonList(bucket), new DisabledLoginCallback(), new Delete.DisabledCallback()); }
@Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> objects = new AttributedList<Path>(); Marker marker; if(containerService.isContainer(directory)) { marker = new Marker(null, null); } else { marker = new Marker(String.format("%s%s", containerService.getKey(directory), Path.DELIMITER), null); } final String containerId = fileid.getFileid(containerService.getContainer(directory), new DisabledListProgressListener()); final Map<String, Long> revisions = new HashMap<>(); boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { if(log.isDebugEnabled()) { log.debug(String.format("List directory %s with marker %s", directory, marker)); } final B2ListFilesResponse response = session.getClient().listFileVersions( containerId, marker.nextFilename, marker.nextFileId, chunksize, containerService.isContainer(directory) ? null : String.format("%s%s", containerService.getKey(directory), String.valueOf(Path.DELIMITER)), String.valueOf(Path.DELIMITER)); marker = this.parse(directory, objects, response, revisions); if(null == marker.nextFileId) { if(!response.getFiles().isEmpty()) { hasDirectoryPlaceholder = true; } } listener.chunk(directory, objects); } while(marker.hasNext()); if(!hasDirectoryPlaceholder && objects.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return objects; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } }
B2ObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> objects = new AttributedList<Path>(); Marker marker; if(containerService.isContainer(directory)) { marker = new Marker(null, null); } else { marker = new Marker(String.format("%s%s", containerService.getKey(directory), Path.DELIMITER), null); } final String containerId = fileid.getFileid(containerService.getContainer(directory), new DisabledListProgressListener()); final Map<String, Long> revisions = new HashMap<>(); boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { if(log.isDebugEnabled()) { log.debug(String.format("List directory %s with marker %s", directory, marker)); } final B2ListFilesResponse response = session.getClient().listFileVersions( containerId, marker.nextFilename, marker.nextFileId, chunksize, containerService.isContainer(directory) ? null : String.format("%s%s", containerService.getKey(directory), String.valueOf(Path.DELIMITER)), String.valueOf(Path.DELIMITER)); marker = this.parse(directory, objects, response, revisions); if(null == marker.nextFileId) { if(!response.getFiles().isEmpty()) { hasDirectoryPlaceholder = true; } } listener.chunk(directory, objects); } while(marker.hasNext()); if(!hasDirectoryPlaceholder && objects.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return objects; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } }
B2ObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> objects = new AttributedList<Path>(); Marker marker; if(containerService.isContainer(directory)) { marker = new Marker(null, null); } else { marker = new Marker(String.format("%s%s", containerService.getKey(directory), Path.DELIMITER), null); } final String containerId = fileid.getFileid(containerService.getContainer(directory), new DisabledListProgressListener()); final Map<String, Long> revisions = new HashMap<>(); boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { if(log.isDebugEnabled()) { log.debug(String.format("List directory %s with marker %s", directory, marker)); } final B2ListFilesResponse response = session.getClient().listFileVersions( containerId, marker.nextFilename, marker.nextFileId, chunksize, containerService.isContainer(directory) ? null : String.format("%s%s", containerService.getKey(directory), String.valueOf(Path.DELIMITER)), String.valueOf(Path.DELIMITER)); marker = this.parse(directory, objects, response, revisions); if(null == marker.nextFileId) { if(!response.getFiles().isEmpty()) { hasDirectoryPlaceholder = true; } } listener.chunk(directory, objects); } while(marker.hasNext()); if(!hasDirectoryPlaceholder && objects.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return objects; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2ObjectListService(final B2Session session, final B2FileidProvider fileid);  B2ObjectListService(final B2Session session, final B2FileidProvider fileid, final int chunksize); }
B2ObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> objects = new AttributedList<Path>(); Marker marker; if(containerService.isContainer(directory)) { marker = new Marker(null, null); } else { marker = new Marker(String.format("%s%s", containerService.getKey(directory), Path.DELIMITER), null); } final String containerId = fileid.getFileid(containerService.getContainer(directory), new DisabledListProgressListener()); final Map<String, Long> revisions = new HashMap<>(); boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { if(log.isDebugEnabled()) { log.debug(String.format("List directory %s with marker %s", directory, marker)); } final B2ListFilesResponse response = session.getClient().listFileVersions( containerId, marker.nextFilename, marker.nextFileId, chunksize, containerService.isContainer(directory) ? null : String.format("%s%s", containerService.getKey(directory), String.valueOf(Path.DELIMITER)), String.valueOf(Path.DELIMITER)); marker = this.parse(directory, objects, response, revisions); if(null == marker.nextFileId) { if(!response.getFiles().isEmpty()) { hasDirectoryPlaceholder = true; } } listener.chunk(directory, objects); } while(marker.hasNext()); if(!hasDirectoryPlaceholder && objects.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return objects; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2ObjectListService(final B2Session session, final B2FileidProvider fileid);  B2ObjectListService(final B2Session session, final B2FileidProvider fileid, final int chunksize); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); @Override ListService withCache(final Cache<Path> cache); }
B2ObjectListService implements ListService { @Override public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException { try { final AttributedList<Path> objects = new AttributedList<Path>(); Marker marker; if(containerService.isContainer(directory)) { marker = new Marker(null, null); } else { marker = new Marker(String.format("%s%s", containerService.getKey(directory), Path.DELIMITER), null); } final String containerId = fileid.getFileid(containerService.getContainer(directory), new DisabledListProgressListener()); final Map<String, Long> revisions = new HashMap<>(); boolean hasDirectoryPlaceholder = containerService.isContainer(directory); do { if(log.isDebugEnabled()) { log.debug(String.format("List directory %s with marker %s", directory, marker)); } final B2ListFilesResponse response = session.getClient().listFileVersions( containerId, marker.nextFilename, marker.nextFileId, chunksize, containerService.isContainer(directory) ? null : String.format("%s%s", containerService.getKey(directory), String.valueOf(Path.DELIMITER)), String.valueOf(Path.DELIMITER)); marker = this.parse(directory, objects, response, revisions); if(null == marker.nextFileId) { if(!response.getFiles().isEmpty()) { hasDirectoryPlaceholder = true; } } listener.chunk(directory, objects); } while(marker.hasNext()); if(!hasDirectoryPlaceholder && objects.isEmpty()) { throw new NotfoundException(directory.getAbsolute()); } return objects; } catch(B2ApiException e) { throw new B2ExceptionMappingService().map("Listing directory {0} failed", e, directory); } catch(IOException e) { throw new DefaultIOExceptionMappingService().map(e); } } B2ObjectListService(final B2Session session, final B2FileidProvider fileid);  B2ObjectListService(final B2Session session, final B2FileidProvider fileid, final int chunksize); @Override AttributedList<Path> list(final Path directory, final ListProgressListener listener); @Override ListService withCache(final Cache<Path> cache);  }