Made integration stubs's handling of markers more robust -- should now reliably return the correct number of results

git-svn-id: http://jclouds.googlecode.com/svn/trunk@839 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
jamurty 2009-05-22 20:14:11 +00:00
parent c514757242
commit 11f7e9900b
1 changed files with 15 additions and 3 deletions

View File

@ -279,10 +279,22 @@ public class StubS3Connection implements S3Connection {
S3Bucket returnVal = new S3Bucket(name);
if (options.getMarker() != null) {
contents = contents.tailSet(new S3Object.Metadata(URLDecoder.decode(options.getMarker())));
final String marker;
try {
marker = URLDecoder.decode(options.getMarker(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalArgumentException(e);
}
S3Object.Metadata lastMarkerMetadata =
Iterables.find(contents, new Predicate<S3Object.Metadata>() {
public boolean apply(S3Object.Metadata metadata) {
return metadata.getKey().equals(marker);
}
});
contents = contents.tailSet(lastMarkerMetadata);
// amazon spec means after the marker, not including it.
contents.remove(new S3Object.Metadata(options.getMarker()));
returnVal.setMarker(URLDecoder.decode(options.getMarker()));
contents.remove(lastMarkerMetadata);
returnVal.setMarker(marker);
}