1.9.30 sync.
[gae.git] / java / src / main / com / google / appengine / api / files / GSFileOptions.java
blobd597a8bbbb98018fa1393ff99d45fe533d1ca3b2
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 * See <a href="https://cloud.google.com/storage/docs/reference-headers#contenttype">
87 * Content-Type</a>.
88 * @param mimeType of the Google Storage object.
89 * @return this for chaining.
91 public GSFileOptionsBuilder setMimeType(String mimeType) {
92 this.mimeType = Preconditions.checkNotNull(mimeType);
93 return this;
96 /**
97 * Sets the acl of the object. If not set, defaults to none (ie, bucket default).
98 * See <a href="https://cloud.google.com/storage/docs/access-control">Access Control</a>.
99 * @param acl to use for the Google Storage object.
100 * @return this for chaining.
102 public GSFileOptionsBuilder setAcl(String acl) {
103 this.acl = Preconditions.checkNotNull(acl);
104 return this;
108 * Sets the cache control for the object. If not set, default value is used.
109 * See <a href="https://cloud.google.com/storage/docs/reference-headers#cachecontrol">
110 * Cache-Control</a>.
111 * @param cacheControl to use for the Google Storage object.
112 * @return this for chaining.
114 public GSFileOptionsBuilder setCacheControl(String cacheControl) {
115 this.cacheControl = Preconditions.checkNotNull(cacheControl);
116 return this;
120 * Sets the content encoding for the object. If not set, default value is used.
121 * See <a href="https://cloud.google.com/storage/docs/reference-headers#contentencoding">
122 * Content-Encoding</a>.
123 * @param contentEncoding to use for the Google Storage object.
124 * @return this for chaining.
126 public GSFileOptionsBuilder setContentEncoding(String contentEncoding) {
127 this.contentEncoding = Preconditions.checkNotNull(contentEncoding);
128 return this;
132 * Sets the content disposition for the object. If not set, default value is used.
133 * See <a href="https://cloud.google.com/storage/docs/reference-headers#contentdisposition">
134 * Content-Disposition</a>.
135 * @param contentDisposition to use for the Google Storage object.
136 * @return this for chaining.
138 public GSFileOptionsBuilder setContentDisposition(String contentDisposition) {
139 this.contentDisposition = Preconditions.checkNotNull(contentDisposition);
140 return this;
144 * Adds user specific metadata that will be added to object headers when
145 * served through Google Storage:
146 * Each entry will be prefixed with <a
147 * href="https://cloud.google.com/storage/docs/reference-headers#xgoogmeta">
148 * x-goog-meta-</a> when serving out.
149 * For example, if you add a {@literal 'foo'->'bar'} entry to userMetadata map,
150 * it will be served out as a header:
151 * x-goog-meta-foo: bar
152 * @param key
153 * @param value
154 * @return this for chaining.
156 public GSFileOptionsBuilder addUserMetadata(String key, String value) {
157 Preconditions.checkArgument(key != null && !key.isEmpty());
158 Preconditions.checkArgument(value != null && !value.isEmpty());
159 userMetadata.put(key, value);
160 return this;
163 public GSFileOptions build() {
164 return new GSFileOptions(bucket,
165 key,
166 mimeType,
167 acl,
168 cacheControl,
169 contentEncoding,
170 contentDisposition,
171 userMetadata);