Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / files / GSFileOptions.java
blobec721eee5b2ad04648945b46f3f0582df3582a1e
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.files;
5 import com.google.common.base.Preconditions;
7 import java.util.Map;
8 import java.util.TreeMap;
10 /**
11 * Container class for holding options for creating Google Storage files.
13 * @see <a href="https://cloud.google.com/storage/docs/">Google Storage
14 * API</a>.
16 @Deprecated
17 public class GSFileOptions {
18 public static final String GS_USER_METADATA_PREFIX = "x-goog-meta-";
20 final String fileName;
21 final String mimeType;
22 final String acl;
23 final String cacheControl;
24 final String contentEncoding;
25 final String contentDisposition;
26 final Map<String, String> userMetadata = new TreeMap<String, String>();
28 private GSFileOptions(String bucket,
29 String key,
30 String mimeType,
31 String acl,
32 String cacheControl,
33 String contentEncoding,
34 String contentDisposition,
35 Map<String, String> userMetadata) {
36 Preconditions.checkArgument(bucket != null && !bucket.isEmpty(), "Must provide bucket");
37 Preconditions.checkArgument(key != null && !key.isEmpty(), "Must provide key");
38 this.fileName = FileServiceImpl.GS_FILESYSTEM_PREFIX + bucket + "/" + key;
39 this.mimeType = (mimeType == null || mimeType.trim().isEmpty())
40 ? FileServiceImpl.GS_DEFAULT_MIME_TYPE : mimeType;
41 this.acl = acl;
42 this.cacheControl = cacheControl;
43 this.contentEncoding = contentEncoding;
44 this.contentDisposition = contentDisposition;
45 if (userMetadata != null) {
46 this.userMetadata.putAll(userMetadata);
50 /**
51 * A builder of GSFileOptions.
53 public static class GSFileOptionsBuilder {
54 String bucket;
55 String key;
56 String mimeType;
57 String acl;
58 String cacheControl;
59 String contentEncoding;
60 String contentDisposition;
61 Map<String, String> userMetadata = new TreeMap<String, String>();
63 /**
64 * Sets the name of the bucket. Required.
65 * @param bucket name of the Google Storage bucket
66 * @return this for chaining.
68 public GSFileOptionsBuilder setBucket(String bucket) {
69 this.bucket = Preconditions.checkNotNull(bucket);
70 return this;
73 /**
74 * Sets the key of the object. Required.
75 * @param key of the Google Storage object
76 * @return this for chaining.
78 public GSFileOptionsBuilder setKey(String key) {
79 this.key = Preconditions.checkNotNull(key);
80 return this;
83 /**
84 * Sets the mime type of the object. If not set, default Google Storage
85 * mime type is used when served out of Google Storage.
86 * {@link "https://cloud.google.com/storage/docs/reference-headers#contenttype"}
87 * @param mimeType of the Google Storage object.
88 * @return this for chaining.
90 public GSFileOptionsBuilder setMimeType(String mimeType) {
91 this.mimeType = Preconditions.checkNotNull(mimeType);
92 return this;
95 /**
96 * Sets the acl of the object. If not set, defaults to none (ie, bucket default).
97 * {@link "https://cloud.google.com/storage/docs/access-control"}
98 * @param acl to use for the Google Storage object.
99 * @return this for chaining.
101 public GSFileOptionsBuilder setAcl(String acl) {
102 this.acl = Preconditions.checkNotNull(acl);
103 return this;
107 * Sets the cache control for the object. If not set, default value is used.
108 * {@link "https://cloud.google.com/storage/docs/reference-headers#cachecontrol"}
109 * @param cacheControl to use for the Google Storage object.
110 * @return this for chaining.
112 public GSFileOptionsBuilder setCacheControl(String cacheControl) {
113 this.cacheControl = Preconditions.checkNotNull(cacheControl);
114 return this;
118 * Sets the content encoding for the object. If not set, default value is used.
119 * {@link "https://cloud.google.com/storage/docs/reference-headers#contentencoding"}
120 * @param contentEncoding to use for the Google Storage object.
121 * @return this for chaining.
123 public GSFileOptionsBuilder setContentEncoding(String contentEncoding) {
124 this.contentEncoding = Preconditions.checkNotNull(contentEncoding);
125 return this;
129 * Sets the content disposition for the object. If not set, default value is used.
130 * {@link "https://cloud.google.com/storage/docs/reference-headers#contentdisposition"}
131 * @param contentDisposition to use for the Google Storage object.
132 * @return this for chaining.
134 public GSFileOptionsBuilder setContentDisposition(String contentDisposition) {
135 this.contentDisposition = Preconditions.checkNotNull(contentDisposition);
136 return this;
140 * Adds user specific metadata that will be added to object headers when
141 * served through Google Storage:
142 * {@link "https://cloud.google.com/storage/docs/reference-headers#xgoogmeta"}
143 * Each entry will be prefixed with x-goog-meta- when serving out.
144 * For example, if you add 'foo'->'bar' entry to userMetadata map,
145 * it will be served out as a header:
146 * x-goog-meta-foo: bar
147 * @param key
148 * @param value
149 * @return this for chaining.
151 public GSFileOptionsBuilder addUserMetadata(String key, String value) {
152 Preconditions.checkArgument(key != null && !key.isEmpty());
153 Preconditions.checkArgument(value != null && !value.isEmpty());
154 userMetadata.put(key, value);
155 return this;
158 public GSFileOptions build() {
159 return new GSFileOptions(bucket,
160 key,
161 mimeType,
162 acl,
163 cacheControl,
164 contentEncoding,
165 contentDisposition,
166 userMetadata);