1 | /** |
2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
3 | * contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. jclouds licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. 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, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | package org.jclouds.io.payloads; |
20 | |
21 | import java.io.Serializable; |
22 | |
23 | import org.jclouds.javax.annotation.Nullable; |
24 | |
25 | import org.jclouds.io.ContentMetadata; |
26 | import org.jclouds.io.ContentMetadataBuilder; |
27 | import org.jclouds.io.MutableContentMetadata; |
28 | |
29 | import com.google.common.collect.Multimap; |
30 | |
31 | /** |
32 | * @author Adrian Cole |
33 | */ |
34 | public class BaseMutableContentMetadata extends ContentMetadataBuilder implements MutableContentMetadata, Serializable { |
35 | /** The serialVersionUID */ |
36 | private static final long serialVersionUID = 8364286391963469370L; |
37 | |
38 | @Override |
39 | public void setPropertiesFromHttpHeaders(Multimap<String, String> headers) { |
40 | fromHttpHeaders(headers); |
41 | } |
42 | |
43 | /** |
44 | * {@inheritDoc} |
45 | */ |
46 | @Override |
47 | public Long getContentLength() { |
48 | return contentLength; |
49 | } |
50 | |
51 | /** |
52 | * {@inheritDoc} |
53 | */ |
54 | @Override |
55 | public void setContentLength(@Nullable Long contentLength) { |
56 | contentLength(contentLength); |
57 | } |
58 | |
59 | /** |
60 | * {@inheritDoc} |
61 | */ |
62 | @Override |
63 | public byte[] getContentMD5() { |
64 | if (contentMD5 != null) { |
65 | byte[] retval = new byte[contentMD5.length]; |
66 | System.arraycopy(this.contentMD5, 0, retval, 0, contentMD5.length); |
67 | return retval; |
68 | } else { |
69 | return null; |
70 | } |
71 | } |
72 | |
73 | /** |
74 | * {@inheritDoc} |
75 | */ |
76 | @Override |
77 | public void setContentMD5(byte[] md5) { |
78 | contentMD5(md5); |
79 | } |
80 | |
81 | /** |
82 | * {@inheritDoc} |
83 | */ |
84 | @Override |
85 | public String getContentType() { |
86 | return contentType; |
87 | } |
88 | |
89 | /** |
90 | * {@inheritDoc} |
91 | */ |
92 | @Override |
93 | public void setContentType(@Nullable String contentType) { |
94 | contentType(contentType); |
95 | } |
96 | |
97 | /** |
98 | * {@inheritDoc} |
99 | */ |
100 | @Override |
101 | public void setContentDisposition(@Nullable String contentDisposition) { |
102 | contentDisposition(contentDisposition); |
103 | } |
104 | |
105 | /** |
106 | * {@inheritDoc} |
107 | */ |
108 | @Override |
109 | public String getContentDisposition() { |
110 | return this.contentDisposition; |
111 | } |
112 | |
113 | /** |
114 | * {@inheritDoc} |
115 | */ |
116 | @Override |
117 | public void setContentLanguage(@Nullable String contentLanguage) { |
118 | contentLanguage(contentLanguage); |
119 | } |
120 | |
121 | /** |
122 | * {@inheritDoc} |
123 | */ |
124 | @Override |
125 | public String getContentLanguage() { |
126 | return this.contentLanguage; |
127 | } |
128 | |
129 | /** |
130 | * {@inheritDoc} |
131 | */ |
132 | @Override |
133 | public void setContentEncoding(@Nullable String contentEncoding) { |
134 | contentEncoding(contentEncoding); |
135 | } |
136 | |
137 | /** |
138 | * {@inheritDoc} |
139 | */ |
140 | @Override |
141 | public String getContentEncoding() { |
142 | return this.contentEncoding; |
143 | } |
144 | |
145 | @Override |
146 | public BaseMutableContentMetadata toBuilder() { |
147 | return BaseMutableContentMetadata.fromContentMetadata(this); |
148 | } |
149 | |
150 | public static BaseMutableContentMetadata fromContentMetadata(ContentMetadata in) { |
151 | return (BaseMutableContentMetadata) new BaseMutableContentMetadata().contentType(in.getContentType()) |
152 | .contentLength(in.getContentLength()).contentMD5(in.getContentMD5()).contentDisposition( |
153 | in.getContentDisposition()).contentLanguage(in.getContentLanguage()).contentEncoding( |
154 | in.getContentEncoding()); |
155 | } |
156 | } |