View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.blobstore.options;
20  
21  /**
22   * Contains options supported in the put blob operation. <h2>
23   * Usage</h2> The recommended way to instantiate a PutOptions object is to statically import
24   * PutOptions.* and invoke a static creation method followed by an instance mutator (if needed):
25   * <p/>
26   * <code>
27   * import static org.jclouds.blobstore.options.PutOptions.Builder.*
28   * eTag = blobStore.putBlob("container", blob, multipart());
29   * <code>
30   * 
31   * @author Adrian Cole
32   */
33  public class PutOptions implements Cloneable {
34  
35     public static final ImmutablePutOptions NONE = new ImmutablePutOptions(new PutOptions());
36  
37     private boolean multipart;
38  
39     public PutOptions() {
40     }
41  
42     PutOptions(boolean multipart) {
43        this.multipart = multipart;
44     }
45  
46     public static class ImmutablePutOptions extends PutOptions {
47        private final PutOptions delegate;
48  
49        public ImmutablePutOptions(PutOptions delegate) {
50           this.delegate = delegate;
51        }
52  
53        @Override
54        public boolean isMultipart() {
55           return delegate.isMultipart();
56        }
57  
58        @Override
59        public PutOptions multipart() {
60           throw new UnsupportedOperationException();
61        }
62  
63        @Override
64        public PutOptions clone() {
65           return delegate.clone();
66        }
67  
68        @Override
69        public String toString() {
70           return delegate.toString();
71        }
72  
73     }
74  
75     public boolean isMultipart() {
76        return multipart;
77     }
78  
79     /**
80      * split large blobs into pieces, if supported by the provider
81      */
82     public PutOptions multipart() {
83        this.multipart = true;
84        return this;
85     }
86  
87     public static class Builder {
88  
89        /**
90         * @see PutOptions#multipart()
91         */
92        public static PutOptions multipart() {
93           PutOptions options = new PutOptions();
94           return options.multipart();
95        }
96  
97     }
98  
99     @Override
100    public PutOptions clone() {
101       return new PutOptions(multipart);
102    }
103 
104    @Override
105    public String toString() {
106       return "[multipart=" + multipart + "]";
107    }
108 }