forked from aws/aws-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathS3Object.java
More file actions
206 lines (185 loc) · 6.19 KB
/
S3Object.java
File metadata and controls
206 lines (185 loc) · 6.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Portions copyright 2006-2009 James Murty. Please see LICENSE.txt
* for applicable license terms and NOTICE.txt for applicable notices.
*/
package com.amazonaws.services.s3.model;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import com.amazonaws.services.s3.AmazonS3;
/**
* Represents an object stored in Amazon S3. This object contains
* the data content
* and the object metadata stored by Amazon S3, such as content type,
* content length, etc.
*
* @see ObjectMetadata
*/
public class S3Object implements Closeable {
private static final long serialVersionUID = -2883501141593631181L;
/** The key under which this object is stored */
private String key = null;
/** The name of the bucket in which this object is contained */
private String bucketName = null;
/** The metadata stored by Amazon S3 for this object */
private ObjectMetadata metadata = new ObjectMetadata();
/** The stream containing the contents of this object from S3 */
private S3ObjectInputStream objectContent;
/** The redirect location for this object */
private String redirectLocation;
/**
* Gets the metadata stored by Amazon S3 for this object. The
* {@link ObjectMetadata} object includes any custom user metadata supplied by the
* caller when the object was uploaded, as well as HTTP metadata such as
* content length and content type.
*
* @return The metadata stored by Amazon S3 for this object.
*
* @see S3Object#getObjectContent()
*/
public ObjectMetadata getObjectMetadata() {
return metadata;
}
/**
* Sets the object metadata for this object.
* <p>
* <b>NOTE:</b> This does not update the object metadata stored in Amazon
* S3, but only updates this object in local memory. To update an object's
* metadata in S3, use {@link AmazonS3#copyObject(CopyObjectRequest)} to
* copy the object to a new (or the same location) and specify new object
* metadata then.
*
* @param metadata The new metadata to set for this object in memory.
*/
public void setObjectMetadata(ObjectMetadata metadata) {
this.metadata = metadata;
}
/**
* Gets an input stream containing the contents of this object. Callers
* should close this input stream as soon as possible, because the
* object contents aren't buffered in memory and stream directly from Amazon
* S3.
*
* @return An input stream containing the contents of this object.
*
* @see S3Object#getObjectMetadata()
* @see S3Object#setObjectContent(InputStream)
*/
public S3ObjectInputStream getObjectContent() {
return objectContent;
}
/**
* Sets the input stream containing this object's contents.
*
* @param objectContent
* The input stream containing this object's contents.
*
* @see S3Object#getObjectContent()
*/
public void setObjectContent(S3ObjectInputStream objectContent) {
this.objectContent = objectContent;
}
/**
* Sets the input stream containing this object's contents.
*
* @param objectContent
* The input stream containing this object's contents. Will get
* wrapped in an S3ObjectInputStream.
* @see S3Object#getObjectContent()
*/
public void setObjectContent(InputStream objectContent) {
setObjectContent(new S3ObjectInputStream(objectContent,
this.objectContent != null ? this.objectContent.getHttpRequest() : null));
}
/**
* Gets the name of the bucket in which this object is contained.
*
* @return The name of the bucket in which this object is contained.
*
* @see S3Object#setBucketName(String)
*/
public String getBucketName() {
return bucketName;
}
/**
* Sets the name of the bucket in which this object is contained.
*
* @param bucketName
* The name of the bucket containing this object.
*
* @see S3Object#getBucketName()
*/
public void setBucketName(String bucketName) {
this.bucketName = bucketName;
}
/**
* Gets the key under which this object is stored.
*
* @return The key under which this object is stored.
*
* @see S3Object#setKey(String)
*/
public String getKey() {
return key;
}
/**
* Sets the key under which this object is stored.
*
* @param key
* The key under which this object is stored.
*
* @see S3Object#getKey()
*/
public void setKey(String key) {
this.key = key;
}
/**
* Gets the redirect location for this object.
*
*/
public String getRedirectLocation() {
return this.redirectLocation;
}
/**
* Sets the redirect location for this object.
*
* @param redirectLocation
* the redirect location for that object.
*/
public void setRedirectLocation(String redirectLocation) {
this.redirectLocation = redirectLocation;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return "S3Object [key=" + getKey()
+ ",bucket=" + (bucketName == null ? "<Unknown>" : bucketName)
+ "]";
}
/**
* Releases any underlying system resources. If the resources
* are already released then invoking this method has no effect.
*
* @throws IOException if an I/O error occurs
*/
@Override
public void close() throws IOException {
if(getObjectContent() != null){
getObjectContent().close();
}
}
}