Skip to content

Commit

Permalink
Move list object API to java storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
shilpi23pandey committed Dec 19, 2023
1 parent 0acb27a commit 611f17f
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -108,7 +110,6 @@
*/
@VisibleForTesting
public class GoogleCloudStorageClientImpl extends ForwardingGoogleCloudStorage {

private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();

// Maximum number of times to retry deletes in the case of precondition failures.
Expand Down Expand Up @@ -483,6 +484,8 @@ public List<GoogleCloudStorageItemInfo> listObjectInfo(
} while (pageToken != null
&& getMaxRemainingResults(listOptions.getMaxResults(), objectInfos) > 0);

objectInfos.sort(Comparator.comparing(GoogleCloudStorageItemInfo::getObjectName));

return objectInfos;
}

Expand Down Expand Up @@ -563,8 +566,7 @@ && getMaxRemainingResults(listOptions.getMaxResults(), objectInfos) > 0) {
objectInfos.add(createItemInfoForBlob(blob));
} else if (blob.getName().equals(objectNamePrefix) && listOptions.isIncludePrefix()) {
// Handle object prefixes. Object prefixes show up as non-directory.
objectInfos.add(
createInferredDirectory(new StorageResourceId(bucketName, blob.getName())));
objectInfos.add(createItemInfoForBlob(blob));
objectPrefixIncluded = true;
}
}
Expand Down Expand Up @@ -630,11 +632,11 @@ private static GoogleCloudStorageItemInfo createItemInfoForBlob(Blob blob) {
checkNotNull(blob, "object must not be null");
checkArgument(!isNullOrEmpty(blob.getBucket()), "object must have a bucket: %s", blob);
checkArgument(!isNullOrEmpty(blob.getName()), "object must have a name: %s", blob);
return createItemInfoForStorageBlob(new StorageResourceId(blob.getBucket(), blob.getName()),
return createItemInfoForBlob(new StorageResourceId(blob.getBucket(), blob.getName()),
blob);
}

private static GoogleCloudStorageItemInfo createItemInfoForStorageBlob(
private static GoogleCloudStorageItemInfo createItemInfoForBlob(
StorageResourceId resourceId, Blob blob) {
checkArgument(resourceId != null, "resourceId must not be null");
checkArgument(blob != null, "object must not be null");
Expand Down Expand Up @@ -667,12 +669,13 @@ private static GoogleCloudStorageItemInfo createItemInfoForStorageBlob(
md5Hash = BaseEncoding.base64().decode(blob.getMd5());
}

// TODO : Replace the deprecated time fields.
return GoogleCloudStorageItemInfo.createObject(
resourceId,
blob.getCreateTime() == null ? 0 : blob.getCreateTime(),
blob.getUpdateTime() == null ? 0 : blob.getUpdateTime(),
blob.getSize() == null ? 0 : blob.getSize().longValue(),
blob.getCreateTimeOffsetDateTime() == null ? 0
: blob.getCreateTimeOffsetDateTime().toInstant().toEpochMilli(),
blob.getUpdateTimeOffsetDateTime() == null ? 0
: blob.getUpdateTimeOffsetDateTime().toInstant().toEpochMilli(),
blob.getSize() == null ? 0 : blob.getSize(),
blob.getContentType(),
blob.getContentEncoding(),
decodedMetadata,
Expand Down

0 comments on commit 611f17f

Please sign in to comment.