Hello everybody,
I am using the jets3t library v0.9.4 for some time now, with a fair amount of success.
I know how to deal with existence or not of objects, but I cannot find an efficient way to deal with how to check for the existence of *prefixes*.
This is what I have:
public static boolean prefixExists(S3Service service, String bucket, String prefix) {
S3Object[] objects = new S3Object[0];
try {
objects = service.listObjects(bucket, prefix, null, 2); // 2 is the maxListingLength. Could possibly be '1' instead.
} catch (S3ServiceException e) {
// some error handling
}
return objects.length > 0;
}
I was hoping that calling this for prefix="results/2016-10-24" would yield true if and only if there are actual objects under it.
Which certainly works, except that my arbitrary limit ( 2 ) does not really get acknowledged.
In fact, i get returned all 3996 objects that lie under the given prefix. This is wasteful and slow, because some other "folders" would list tens of thousands of contained objects, while a single one would have sufficed.
Is there a reason why the limit doesn't work?
Or, better yet, is there a more efficient way to ascertain the existence of a prefix?
Thank you all for reading!