version_listing = s3.listNextBatchOfVersions( version_listing); } else {
private void prepareCurrentListing() { while (currentListing == null || (!currentIterator.hasNext() && currentListing .isTruncated())) { if (currentListing == null) { ListVersionsRequest req = new ListVersionsRequest(); req.setBucketName(getBucketName()); if (getKey() != null) { req.setPrefix(getKey()); } else { req.setPrefix(getPrefix()); } req.setMaxResults(getBatchSize()); currentListing = getS3().listVersions(req); } else { currentListing = getS3().listNextBatchOfVersions( currentListing); } currentIterator = currentListing.getVersionSummaries() .iterator(); } if (nextSummary == null && currentIterator.hasNext()) { nextSummary = currentIterator.next(); } }
@Test public void testGetsNextPageIfFirstPageIsTruncated() throws Exception { when(versionListing.isTruncated()).thenReturn(true); VersionListing secondPage = mock(VersionListing.class); when(s3.listNextBatchOfVersions(versionListing)).thenReturn(secondPage); s3Versions.iterator().hasNext(); verify(s3).listNextBatchOfVersions(versionListing); } }
@Test public void testDoesNotRequestNextPageIfNonMatchingKeyWasFound() throws Exception { VersionListing listing = mock(VersionListing.class); S3VersionSummary matchingSummary = mock(S3VersionSummary.class); S3VersionSummary nonMatchingSummary = mock(S3VersionSummary.class); when(listing.getVersionSummaries()).thenReturn( Arrays.asList(matchingSummary, nonMatchingSummary)); when(listing.isTruncated()).thenReturn(true); when(matchingSummary.getKey()).thenReturn("the-key"); when(nonMatchingSummary.getKey()).thenReturn("the-other-key"); when(s3.listVersions(any(ListVersionsRequest.class))).thenReturn(listing); Iterator<S3VersionSummary> iter = s3Versions.iterator(); assertTrue(iter.hasNext()); assertSame(matchingSummary, iter.next()); assertFalse(iter.hasNext()); verify(s3, never()).listNextBatchOfVersions(listing); }
private void prepareCurrentListing() { while (currentListing == null || (!currentIterator.hasNext() && currentListing .isTruncated())) { if (currentListing == null) { ListVersionsRequest req = new ListVersionsRequest(); req.setBucketName(getBucketName()); if (getKey() != null) { req.setPrefix(getKey()); } else { req.setPrefix(getPrefix()); } req.setMaxResults(getBatchSize()); currentListing = getS3().listVersions(req); } else { currentListing = getS3().listNextBatchOfVersions( currentListing); } currentIterator = currentListing.getVersionSummaries() .iterator(); } if (nextSummary == null && currentIterator.hasNext()) { nextSummary = currentIterator.next(); } }
@Override public VersionListing call() { return s3.listNextBatchOfVersions(versionListing); } }, OPERATION_LIST_VERSIONS);
@Override public VersionListing listNextBatchOfVersions(VersionListing previousVersionListing) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().listNextBatchOfVersions(previousVersionListing)); }
@Override public VersionListing listNextBatchOfVersions(ListNextBatchOfVersionsRequest listNextBatchOfVersionsRequest) throws SdkClientException, AmazonServiceException { return call(() -> getDelegate().listNextBatchOfVersions(listNextBatchOfVersionsRequest)); }
@Override public VersionListing call() { if (fListing == null) { return s3.listVersions(config.getBucketName(), key, null, null, "/", null); } else { return s3.listNextBatchOfVersions(fListing); } } }, OPERATION_LIST_VERSIONS);
@Override public List<FileData> list(String path) throws IOException { try { List<FileData> result = new ArrayList<>(); VersionListing versionListing = null; do { versionListing = versionListing == null ? s3.listVersions(bucketName, path) : s3.listNextBatchOfVersions(versionListing); List<S3VersionSummary> versionSummaries = versionListing.getVersionSummaries(); if (versionSummaries.isEmpty()) { return result; } for (S3VersionSummary versionSummary : versionSummaries) { if (versionSummary.isLatest()) { result.add(createFileData(versionSummary)); } } } while (versionListing.isTruncated()); return result; } catch (SdkClientException e) { throw new IOException(e); } }
@Override public List<FileData> listHistory(String name) throws IOException { try { List<FileData> result = new ArrayList<>(); VersionListing versionListing = null; do { versionListing = versionListing == null ? s3.listVersions(bucketName, name) : s3.listNextBatchOfVersions(versionListing); for (S3VersionSummary versionSummary : versionListing.getVersionSummaries()) { if (versionSummary.getKey().equals(name)) { result.add(createFileData(versionSummary)); } } } while (versionListing.isTruncated()); // OpenL expects that the last element in the list is last version. // AWS S3 returns last version first and older versions later. // So we reverse result to convert AWS S3 order to OpenL. Collections.reverse(result); return result; } catch (SdkClientException e) { throw new IOException(e); } }
@Override public FileData checkHistory(String name, String version) throws IOException { try { VersionListing versionListing = null; S3VersionSummary summary = null; do { versionListing = versionListing == null ? s3.listVersions(bucketName, name) : s3.listNextBatchOfVersions(versionListing); for (S3VersionSummary versionSummary : versionListing.getVersionSummaries()) { if (versionSummary.getKey().equals(name) && versionSummary.getVersionId().equals(version)) { return createFileData(versionSummary); } } } while (versionListing.isTruncated()); return null; } catch (SdkClientException e) { throw new IOException(e); } }
private void deleteAllVersions(String name) { VersionListing versionListing = null; do { versionListing = versionListing == null ? s3.listVersions(bucketName, name) : s3.listNextBatchOfVersions(versionListing); for (S3VersionSummary versionSummary : versionListing.getVersionSummaries()) { if (versionSummary.getKey().equals(name)) { s3.deleteVersion(bucketName, name, versionSummary.getVersionId()); } } } while (versionListing.isTruncated()); } }
@Override public FileItem readHistory(String name, String version) throws IOException { try { VersionListing versionListing = null; S3VersionSummary summary = null; do { versionListing = versionListing == null ? s3.listVersions(bucketName, name) : s3.listNextBatchOfVersions(versionListing); for (S3VersionSummary versionSummary : versionListing.getVersionSummaries()) { if (versionSummary.getKey().equals(name) && versionSummary.getVersionId().equals(version)) { InputStream content = null; if (!versionSummary.isDeleteMarker()) { S3Object object = s3.getObject(new GetObjectRequest(bucketName, name, version)); content = object.getObjectContent(); } return content == null ? null : new FileItem(checkHistory(name, version), content); } } } while (versionListing.isTruncated()); return null; } catch (SdkClientException e) { throw new IOException(e); } }
private List<S3VersionSummary> getVersions(String bucket, String key) { List<S3VersionSummary> summaries = new ArrayList<>(); VersionListing listing = null; do { if (listing == null) listing = s3.listVersions(bucket, key); else listing = s3.listNextBatchOfVersions(listing); for (S3VersionSummary summary : listing.getVersionSummaries()) { if (summary.getKey().equals(key)) summaries.add(summary); } } while (listing.isTruncated()); Collections.sort(summaries, new VersionComparator()); return summaries; }
versions.addAll(listing.getVersionSummaries()); while (listing.isTruncated()) { listing = client.listNextBatchOfVersions(listing); versions.addAll(listing.getVersionSummaries());
do { if (listing == null) listing = s3.listVersions(bucket, null); else listing = s3.listNextBatchOfVersions(listing);
private void prepareCurrentListing() { while (currentListing == null || (!currentIterator.hasNext() && currentListing .isTruncated())) { if (currentListing == null) { ListVersionsRequest req = new ListVersionsRequest(); req.setBucketName(getBucketName()); if (getKey() != null) { req.setPrefix(getKey()); } else { req.setPrefix(getPrefix()); } req.setMaxResults(getBatchSize()); currentListing = getS3().listVersions(req); } else { currentListing = getS3().listNextBatchOfVersions( currentListing); } currentIterator = currentListing.getVersionSummaries() .iterator(); } if (nextSummary == null && currentIterator.hasNext()) { nextSummary = currentIterator.next(); } }
private Map<String, SortedSet<S3VersionSummary>> getAllVersions(String bucket) { // build comprehensive key -> versions map // must sort by keys and mtime for simple comparison Map<String, SortedSet<S3VersionSummary>> map = new TreeMap<>(); VersionListing listing = null; do { if (listing == null) listing = s3.listVersions(bucket, null); else listing = s3.listNextBatchOfVersions(listing); for (S3VersionSummary summary : listing.getVersionSummaries()) { SortedSet<S3VersionSummary> versions = map.get(summary.getKey()); if (versions == null) { versions = new TreeSet<>(new VersionComparator()); map.put(summary.getKey(), versions); } versions.add(summary); } } while (listing.isTruncated()); return map; }
private void prepareCurrentListing() { while (currentListing == null || (!currentIterator.hasNext() && currentListing .isTruncated())) { if (currentListing == null) { ListVersionsRequest req = new ListVersionsRequest(); req.setBucketName(getBucketName()); if (getKey() != null) { req.setPrefix(getKey()); } else { req.setPrefix(getPrefix()); } req.setMaxResults(getBatchSize()); currentListing = getS3().listVersions(req); } else { currentListing = getS3().listNextBatchOfVersions( currentListing); } currentIterator = currentListing.getVersionSummaries() .iterator(); } if (nextSummary == null && currentIterator.hasNext()) { nextSummary = currentIterator.next(); } }