1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.api
.blobstore
;
6 * Allows users to customize the behavior of a single upload to the
7 * {@link BlobstoreService}.
10 public final class UploadOptions
{
12 private Long maxUploadSizeBytesPerBlob
;
14 private Long maxUploadSizeBytes
;
16 private String gsBucketName
;
18 private UploadOptions() {
22 * Sets the maximum size in bytes for any one blob in the upload. If any blob
23 * in the upload exceeds this value then a 413 error will be returned to the
25 * @param maxUploadSizeBytesPerBlob The maximum size in bytes that any one
26 * blob in the upload can be.
27 * @return {@code this} (for chaining)
29 public UploadOptions
maxUploadSizeBytesPerBlob(long maxUploadSizeBytesPerBlob
) {
30 if (maxUploadSizeBytesPerBlob
< 1) {
31 throw new IllegalArgumentException("maxUploadSizeBytesPerBlob must be positive.");
33 this.maxUploadSizeBytesPerBlob
= maxUploadSizeBytesPerBlob
;
37 boolean hasMaxUploadSizeBytesPerBlob() {
38 return maxUploadSizeBytesPerBlob
!= null;
41 long getMaxUploadSizeBytesPerBlob() {
42 if (maxUploadSizeBytesPerBlob
== null) {
43 throw new IllegalStateException("maxUploadSizeBytesPerBlob has not been set.");
45 return maxUploadSizeBytesPerBlob
;
49 * Sets the maximum size in bytes that for the total upload. If the upload
50 * exceeds this value then a 413 error will be returned to the client.
51 * @param maxUploadSizeBytes The maximum size in bytes for the upload.
52 * @return {@code this} (for chaining)
54 public UploadOptions
maxUploadSizeBytes(long maxUploadSizeBytes
) {
55 if (maxUploadSizeBytes
< 1) {
56 throw new IllegalArgumentException("maxUploadSizeBytes must be positive.");
58 this.maxUploadSizeBytes
= maxUploadSizeBytes
;
62 boolean hasMaxUploadSizeBytes() {
63 return maxUploadSizeBytes
!= null;
66 long getMaxUploadSizeBytes() {
67 if (maxUploadSizeBytes
== null) {
68 throw new IllegalStateException("maxUploadSizeBytes has not been set.");
70 return maxUploadSizeBytes
;
73 public UploadOptions
googleStorageBucketName(String bucketName
) {
74 this.gsBucketName
= bucketName
;
78 boolean hasGoogleStorageBucketName() {
79 return this.gsBucketName
!= null;
82 String
getGoogleStorageBucketName() {
83 if (gsBucketName
== null) {
84 throw new IllegalStateException("gsBucketName has not been set.");
90 public int hashCode() {
92 if (maxUploadSizeBytesPerBlob
!= null) {
93 hash
= hash
* 37 + maxUploadSizeBytesPerBlob
.hashCode();
95 if (maxUploadSizeBytes
!= null) {
96 hash
= hash
* 37 + maxUploadSizeBytes
.hashCode();
98 if (gsBucketName
!= null) {
99 hash
= hash
* 37 + gsBucketName
.hashCode();
105 public boolean equals(Object object
) {
106 if (object
instanceof UploadOptions
) {
107 UploadOptions key
= (UploadOptions
) object
;
109 if (hasMaxUploadSizeBytesPerBlob() != key
.hasMaxUploadSizeBytesPerBlob()) {
112 if (hasMaxUploadSizeBytesPerBlob()) {
113 if (!maxUploadSizeBytesPerBlob
.equals(key
.getMaxUploadSizeBytesPerBlob())) {
118 if (hasMaxUploadSizeBytes() != key
.hasMaxUploadSizeBytes()) {
121 if (hasMaxUploadSizeBytes()) {
122 if (!maxUploadSizeBytes
.equals(key
.getMaxUploadSizeBytes())) {
127 if (hasGoogleStorageBucketName() != key
.hasGoogleStorageBucketName()) {
130 if (hasGoogleStorageBucketName()) {
131 if (!gsBucketName
.equals(key
.gsBucketName
)) {
141 public String
toString() {
142 StringBuilder buffer
= new StringBuilder("UploadOptions: maxUploadSizeBytes=");
143 if (maxUploadSizeBytes
!= null) {
144 buffer
.append(maxUploadSizeBytes
);
146 buffer
.append("unlimited");
148 buffer
.append(", maxUploadSizeBytesPerBlob=");
149 if (maxUploadSizeBytesPerBlob
!= null) {
150 buffer
.append(maxUploadSizeBytesPerBlob
);
152 buffer
.append("unlimited");
154 buffer
.append(", gsBucketName=");
155 if (gsBucketName
!= null) {
156 buffer
.append(gsBucketName
);
158 buffer
.append("None");
161 return buffer
.toString();
165 * Contains static creation methods for {@link UploadOptions}.
167 public static final class Builder
{
169 * Returns default {@link UploadOptions} and calls
170 * {@link UploadOptions#maxUploadSizeBytes(long)}.
172 public static UploadOptions
withMaxUploadSizeBytes(long maxUploadSizeBytes
) {
173 return withDefaults().maxUploadSizeBytes(maxUploadSizeBytes
);
177 * Returns default {@link UploadOptions} and calls
178 * {@link UploadOptions#maxUploadSizeBytesPerBlob(long)}.
180 public static UploadOptions
withMaxUploadSizeBytesPerBlob(long maxUploadSizeBytesPerBlob
) {
181 return withDefaults().maxUploadSizeBytesPerBlob(maxUploadSizeBytesPerBlob
);
185 * Returns default {@link UploadOptions} and calls
186 * {@link UploadOptions#googleStorageBucketName(String)}.
188 public static UploadOptions
withGoogleStorageBucketName(String gsBucketName
) {
189 return withDefaults().googleStorageBucketName(gsBucketName
);
193 * Returns default {@link UploadOptions} with default values.
195 public static UploadOptions
withDefaults() {
196 return new UploadOptions();