com.google.cloud.storage.BlobInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gcloud-java-storage Show documentation
Show all versions of gcloud-java-storage Show documentation
Java idiomatic client for Google Cloud Storage.
The newest version!
/*
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.cloud.storage;
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;
import com.google.api.client.util.Data;
import com.google.api.client.util.DateTime;
import com.google.api.services.storage.model.ObjectAccessControl;
import com.google.api.services.storage.model.StorageObject;
import com.google.api.services.storage.model.StorageObject.Owner;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.Serializable;
import java.math.BigInteger;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* Google Storage object metadata.
*
* @see Concepts and
* Terminology
*/
public class BlobInfo implements Serializable {
static final Function INFO_TO_PB_FUNCTION =
new Function() {
@Override
public StorageObject apply(BlobInfo blobInfo) {
return blobInfo.toPb();
}
};
private static final long serialVersionUID = -5625857076205028976L;
private final BlobId blobId;
private final String generatedId;
private final String selfLink;
private final String cacheControl;
private final List acl;
private final Acl.Entity owner;
private final Long size;
private final String etag;
private final String md5;
private final String crc32c;
private final String mediaLink;
private final Map metadata;
private final Long metageneration;
private final Long deleteTime;
private final Long updateTime;
private final Long createTime;
private final String contentType;
private final String contentEncoding;
private final String contentDisposition;
private final String contentLanguage;
private final Integer componentCount;
private final boolean isDirectory;
/**
* This class is meant for internal use only. Users are discouraged from using this class.
*/
public static final class ImmutableEmptyMap extends AbstractMap {
@Override
public Set> entrySet() {
return ImmutableSet.of();
}
}
/**
* Builder for {@code BlobInfo}.
*/
public abstract static class Builder {
/**
* Sets the blob identity.
*/
public abstract Builder blobId(BlobId blobId);
abstract Builder generatedId(String generatedId);
/**
* Sets the blob's data content type.
*
* @see Content-Type
*/
public abstract Builder contentType(String contentType);
/**
* Sets the blob's data content disposition.
*
* @see Content-Disposition
*/
public abstract Builder contentDisposition(String contentDisposition);
/**
* Sets the blob's data content language.
*
* @see Content-Language
*/
public abstract Builder contentLanguage(String contentLanguage);
/**
* Sets the blob's data content encoding.
*
* @see Content-Encoding
*/
public abstract Builder contentEncoding(String contentEncoding);
abstract Builder componentCount(Integer componentCount);
/**
* Sets the blob's data cache control.
*
* @see Cache-Control
*/
public abstract Builder cacheControl(String cacheControl);
/**
* Sets the blob's access control configuration.
*
* @see
* About Access Control Lists
*/
public abstract Builder acl(List acl);
abstract Builder owner(Acl.Entity owner);
abstract Builder size(Long size);
abstract Builder etag(String etag);
abstract Builder selfLink(String selfLink);
/**
* Sets the MD5 hash of blob's data. MD5 value must be encoded in base64.
*
* @see
* Hashes and ETags: Best Practices
*/
public abstract Builder md5(String md5);
/**
* Sets the CRC32C checksum of blob's data as described in
* RFC 4960, Appendix B; encoded in
* base64 in big-endian order.
*
* @see
* Hashes and ETags: Best Practices
*/
public abstract Builder crc32c(String crc32c);
abstract Builder mediaLink(String mediaLink);
/**
* Sets the blob's user provided metadata.
*/
public abstract Builder metadata(Map metadata);
abstract Builder metageneration(Long metageneration);
abstract Builder deleteTime(Long deleteTime);
abstract Builder updateTime(Long updateTime);
abstract Builder createTime(Long createTime);
abstract Builder isDirectory(boolean isDirectory);
/**
* Creates a {@code BlobInfo} object.
*/
public abstract BlobInfo build();
}
static final class BuilderImpl extends Builder {
private BlobId blobId;
private String generatedId;
private String contentType;
private String contentEncoding;
private String contentDisposition;
private String contentLanguage;
private Integer componentCount;
private String cacheControl;
private List acl;
private Acl.Entity owner;
private Long size;
private String etag;
private String selfLink;
private String md5;
private String crc32c;
private String mediaLink;
private Map metadata;
private Long metageneration;
private Long deleteTime;
private Long updateTime;
private Long createTime;
private Boolean isDirectory;
BuilderImpl(BlobId blobId) {
this.blobId = blobId;
}
BuilderImpl(BlobInfo blobInfo) {
blobId = blobInfo.blobId;
generatedId = blobInfo.generatedId;
cacheControl = blobInfo.cacheControl;
contentEncoding = blobInfo.contentEncoding;
contentType = blobInfo.contentType;
contentDisposition = blobInfo.contentDisposition;
contentLanguage = blobInfo.contentLanguage;
componentCount = blobInfo.componentCount;
acl = blobInfo.acl;
owner = blobInfo.owner;
size = blobInfo.size;
etag = blobInfo.etag;
selfLink = blobInfo.selfLink;
md5 = blobInfo.md5;
crc32c = blobInfo.crc32c;
mediaLink = blobInfo.mediaLink;
metadata = blobInfo.metadata;
metageneration = blobInfo.metageneration;
deleteTime = blobInfo.deleteTime;
updateTime = blobInfo.updateTime;
createTime = blobInfo.createTime;
isDirectory = blobInfo.isDirectory;
}
@Override
public Builder blobId(BlobId blobId) {
this.blobId = checkNotNull(blobId);
return this;
}
@Override
Builder generatedId(String generatedId) {
this.generatedId = generatedId;
return this;
}
@Override
public Builder contentType(String contentType) {
this.contentType = firstNonNull(contentType, Data.nullOf(String.class));
return this;
}
@Override
public Builder contentDisposition(String contentDisposition) {
this.contentDisposition = firstNonNull(contentDisposition, Data.nullOf(String.class));
return this;
}
@Override
public Builder contentLanguage(String contentLanguage) {
this.contentLanguage = firstNonNull(contentLanguage, Data.nullOf(String.class));
return this;
}
@Override
public Builder contentEncoding(String contentEncoding) {
this.contentEncoding = firstNonNull(contentEncoding, Data.nullOf(String.class));
return this;
}
@Override
Builder componentCount(Integer componentCount) {
this.componentCount = componentCount;
return this;
}
@Override
public Builder cacheControl(String cacheControl) {
this.cacheControl = firstNonNull(cacheControl, Data.nullOf(String.class));
return this;
}
@Override
public Builder acl(List acl) {
this.acl = acl != null ? ImmutableList.copyOf(acl) : null;
return this;
}
@Override
Builder owner(Acl.Entity owner) {
this.owner = owner;
return this;
}
@Override
Builder size(Long size) {
this.size = size;
return this;
}
@Override
Builder etag(String etag) {
this.etag = etag;
return this;
}
@Override
Builder selfLink(String selfLink) {
this.selfLink = selfLink;
return this;
}
@Override
public Builder md5(String md5) {
this.md5 = firstNonNull(md5, Data.nullOf(String.class));
return this;
}
@Override
public Builder crc32c(String crc32c) {
this.crc32c = firstNonNull(crc32c, Data.nullOf(String.class));
return this;
}
@Override
Builder mediaLink(String mediaLink) {
this.mediaLink = mediaLink;
return this;
}
@Override
public Builder metadata(Map metadata) {
this.metadata = metadata != null
? new HashMap<>(metadata) : Data.