4141import java .net .URL ;
4242import java .text .SimpleDateFormat ;
4343import java .util .Date ;
44- import java .util .Iterator ;
4544import java .util .List ;
4645import java .util .Locale ;
4746import java .util .Map ;
@@ -120,7 +119,7 @@ public AWSAuthConnection(String awsAccessKeyId, String awsSecretAccessKey,
120119 * @throws MalformedURLException
121120 * @throws IOException
122121 */
123- public Response createBucket (String bucket , Map headers )
122+ public Response createBucket (String bucket , Map < String , List < String >> headers )
124123 throws MalformedURLException , IOException {
125124 return new Response (makeRequest ("PUT" , bucket , headers ));
126125 }
@@ -145,7 +144,7 @@ public Response createBucket(String bucket, Map headers)
145144 * @throws IOException
146145 */
147146 public ListBucketResponse listBucket (String bucket , String prefix ,
148- String marker , Integer maxKeys , Map headers )
147+ String marker , Integer maxKeys , Map < String , List < String >> headers )
149148 throws MalformedURLException , IOException {
150149 String path = Utils .pathForListOptions (bucket , prefix , marker , maxKeys );
151150 return new ListBucketResponse (makeRequest ("GET" , path , headers ));
@@ -163,7 +162,7 @@ public ListBucketResponse listBucket(String bucket, String prefix,
163162 * @throws MalformedURLException
164163 * @throws IOException
165164 */
166- public Response deleteBucket (String bucket , Map headers )
165+ public Response deleteBucket (String bucket , Map < String , List < String >> headers )
167166 throws MalformedURLException , IOException {
168167 return new Response (makeRequest ("DELETE" , bucket , headers ));
169168 }
@@ -184,7 +183,7 @@ public Response deleteBucket(String bucket, Map headers)
184183 * @throws MalformedURLException
185184 * @throws IOException
186185 */
187- public Response put (String bucket , String key , S3Object object , Map headers )
186+ public Response put (String bucket , String key , S3Object object , Map < String , List < String >> headers )
188187 throws MalformedURLException , IOException {
189188
190189 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
@@ -195,7 +194,7 @@ public Response put(String bucket, String key, S3Object object, Map headers)
195194 key = "" ;
196195
197196 HttpURLConnection request = makeRequest ("PUT" , bucket + pathSep
198- + Utils .urlencode (key ), headers , object );
197+ + Utils .urlencodePath (key ), headers , object );
199198
200199 request .setDoOutput (true );
201200 request .getOutputStream ().write (
@@ -221,7 +220,7 @@ public Response put(String bucket, String key, S3Object object, Map headers)
221220 * @throws IOException
222221 */
223222 public Response putStream (String bucket , String key , S3StreamObject object ,
224- Map headers ) throws MalformedURLException , IOException {
223+ Map < String , List < String >> headers ) throws MalformedURLException , IOException {
225224
226225 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
227226 || (key .trim ().length () == 0 );
@@ -230,7 +229,7 @@ public Response putStream(String bucket, String key, S3StreamObject object,
230229 if (key == null )
231230 key = "" ;
232231 HttpURLConnection request = makeStreamRequest ("PUT" , bucket + pathSep
233- + Utils .urlencode (key ), headers , object );
232+ + Utils .urlencodePath (key ), headers , object );
234233
235234 request .setDoOutput (true );
236235 if (object .length != 0 ) {
@@ -263,7 +262,7 @@ public Response putStream(String bucket, String key, S3StreamObject object,
263262 * @throws MalformedURLException
264263 * @throws IOException
265264 */
266- public GetResponse get (String bucket , String key , Map headers )
265+ public GetResponse get (String bucket , String key , Map < String , List < String >> headers )
267266 throws MalformedURLException , IOException {
268267
269268 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
@@ -274,7 +273,7 @@ public GetResponse get(String bucket, String key, Map headers)
274273 key = "" ;
275274
276275 return new GetResponse (makeRequest ("GET" , bucket + pathSep
277- + Utils .urlencode (key ), headers ));
276+ + Utils .urlencodePath (key ), headers ));
278277 }
279278
280279 /**
@@ -291,7 +290,7 @@ public GetResponse get(String bucket, String key, Map headers)
291290 * @throws MalformedURLException
292291 * @throws IOException
293292 */
294- public GetStreamResponse getStream (String bucket , String key , Map headers )
293+ public GetStreamResponse getStream (String bucket , String key , Map < String , List < String >> headers )
295294 throws MalformedURLException , IOException {
296295
297296 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
@@ -302,7 +301,7 @@ public GetStreamResponse getStream(String bucket, String key, Map headers)
302301 key = "" ;
303302
304303 return new GetStreamResponse (makeRequest ("GET" , bucket + pathSep
305- + Utils .urlencode (key ), headers ));
304+ + Utils .urlencodePath (key ), headers ));
306305 }
307306
308307 /**
@@ -319,7 +318,7 @@ public GetStreamResponse getStream(String bucket, String key, Map headers)
319318 * @throws MalformedURLException
320319 * @throws IOException
321320 */
322- public GetResponse getTorrent (String bucket , String key , Map headers )
321+ public GetResponse getTorrent (String bucket , String key , Map < String , List < String >> headers )
323322 throws MalformedURLException , IOException {
324323
325324 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
@@ -330,7 +329,7 @@ public GetResponse getTorrent(String bucket, String key, Map headers)
330329 key = "" ;
331330
332331 return new GetResponse (makeRequest ("GET" , bucket + pathSep
333- + Utils .urlencode (key ) + "?torrent" , headers ));
332+ + Utils .urlencodePath (key ) + "?torrent" , headers ));
334333 }
335334
336335 /**
@@ -347,7 +346,7 @@ public GetResponse getTorrent(String bucket, String key, Map headers)
347346 * @throws MalformedURLException
348347 * @throws IOException
349348 */
350- public Response delete (String bucket , String key , Map headers )
349+ public Response delete (String bucket , String key , Map < String , List < String >> headers )
351350 throws MalformedURLException , IOException {
352351 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
353352 || (key .trim ().length () == 0 );
@@ -356,7 +355,7 @@ public Response delete(String bucket, String key, Map headers)
356355 if (key == null )
357356 key = "" ;
358357 return new Response (makeRequest ("DELETE" , bucket + pathSep
359- + Utils .urlencode (key ), headers ));
358+ + Utils .urlencodePath (key ), headers ));
360359 }
361360
362361 /**
@@ -371,7 +370,7 @@ public Response delete(String bucket, String key, Map headers)
371370 * @throws MalformedURLException
372371 * @throws IOException
373372 */
374- public GetResponse getBucketACL (String bucket , Map headers )
373+ public GetResponse getBucketACL (String bucket , Map < String , List < String >> headers )
375374 throws MalformedURLException , IOException {
376375 return getACL (bucket , "" , headers );
377376 }
@@ -390,7 +389,7 @@ public GetResponse getBucketACL(String bucket, Map headers)
390389 * @throws MalformedURLException
391390 * @throws IOException
392391 */
393- public GetResponse getACL (String bucket , String key , Map headers )
392+ public GetResponse getACL (String bucket , String key , Map < String , List < String >> headers )
394393 throws MalformedURLException , IOException {
395394
396395 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
@@ -400,7 +399,7 @@ public GetResponse getACL(String bucket, String key, Map headers)
400399 if (key == null )
401400 key = "" ;
402401 return new GetResponse (makeRequest ("GET" , bucket + pathSep
403- + Utils .urlencode (key ) + "?acl" , headers ));
402+ + Utils .urlencodePath (key ) + "?acl" , headers ));
404403 }
405404
406405 /**
@@ -417,7 +416,7 @@ public GetResponse getACL(String bucket, String key, Map headers)
417416 * @throws MalformedURLException
418417 * @throws IOException
419418 */
420- public Response putBucketACL (String bucket , String aclXMLDoc , Map headers )
419+ public Response putBucketACL (String bucket , String aclXMLDoc , Map < String , List < String >> headers )
421420 throws MalformedURLException , IOException {
422421 return putACL (bucket , "" , aclXMLDoc , headers );
423422 }
@@ -439,7 +438,7 @@ public Response putBucketACL(String bucket, String aclXMLDoc, Map headers)
439438 * @throws IOException
440439 */
441440 public Response putACL (String bucket , String key , String aclXMLDoc ,
442- Map headers ) throws MalformedURLException , IOException {
441+ Map < String , List < String >> headers ) throws MalformedURLException , IOException {
443442 S3Object object = new S3Object (aclXMLDoc .getBytes (), null );
444443
445444 boolean isEmptyKey = (key == null ) || (key .length () == 0 )
@@ -449,7 +448,7 @@ public Response putACL(String bucket, String key, String aclXMLDoc,
449448 if (key == null )
450449 key = "" ;
451450 HttpURLConnection request = makeRequest ("PUT" , bucket + pathSep
452- + Utils .urlencode (key ) + "?acl" , headers , object );
451+ + Utils .urlencodePath (key ) + "?acl" , headers , object );
453452
454453 request .setDoOutput (true );
455454 request .getOutputStream ().write (
@@ -468,7 +467,7 @@ public Response putACL(String bucket, String key, String aclXMLDoc,
468467 * @throws MalformedURLException
469468 * @throws IOException
470469 */
471- public ListAllMyBucketsResponse listAllMyBuckets (Map headers )
470+ public ListAllMyBucketsResponse listAllMyBuckets (Map < String , List < String >> headers )
472471 throws MalformedURLException , IOException {
473472 return new ListAllMyBucketsResponse (makeRequest ("GET" , "" , headers ));
474473 }
@@ -477,7 +476,7 @@ public ListAllMyBucketsResponse listAllMyBuckets(Map headers)
477476 * Make a new HttpURLConnection without passing an S3Object parameter.
478477 */
479478 private HttpURLConnection makeRequest (String method , String resource ,
480- Map headers ) throws MalformedURLException , IOException {
479+ Map < String , List < String >> headers ) throws MalformedURLException , IOException {
481480 return makeRequest (method , resource , headers , null );
482481 }
483482
@@ -495,7 +494,7 @@ private HttpURLConnection makeRequest(String method, String resource,
495494 * The S3Object that is to be written (can be null).
496495 */
497496 private HttpURLConnection makeRequest (String method , String resource ,
498- Map headers , S3Object object ) throws MalformedURLException ,
497+ Map < String , List < String >> headers , S3Object object ) throws MalformedURLException ,
499498 IOException {
500499 URL url = makeURL (resource );
501500 HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
@@ -524,7 +523,7 @@ private HttpURLConnection makeRequest(String method, String resource,
524523 * The S3StreamObject that is to be written (can be null).
525524 */
526525 private HttpURLConnection makeStreamRequest (String method , String resource ,
527- Map headers , S3StreamObject object ) throws MalformedURLException ,
526+ Map < String , List < String >> headers , S3StreamObject object ) throws MalformedURLException ,
528527 IOException {
529528 URL url = makeURL (resource );
530529 HttpURLConnection connection = (HttpURLConnection ) url .openConnection ();
@@ -548,7 +547,7 @@ private HttpURLConnection makeStreamRequest(String method, String resource,
548547 * A Map of String to List of Strings representing the http
549548 * headers to pass (can be null).
550549 */
551- private void addHeaders (HttpURLConnection connection , Map headers ) {
550+ private void addHeaders (HttpURLConnection connection , Map < String , List < String >> headers ) {
552551 addHeaders (connection , headers , "" );
553552 }
554553
@@ -561,7 +560,7 @@ private void addHeaders(HttpURLConnection connection, Map headers) {
561560 * A Map of String to List of Strings representing the s3
562561 * metadata for this resource.
563562 */
564- private void addMetadataHeaders (HttpURLConnection connection , Map metadata ) {
563+ private void addMetadataHeaders (HttpURLConnection connection , Map < String , List < String >> metadata ) {
565564 addHeaders (connection , metadata , Utils .METADATA_PREFIX );
566565 }
567566
@@ -578,14 +577,11 @@ private void addMetadataHeaders(HttpURLConnection connection, Map metadata) {
578577 * The string to prepend to each key before adding it to the
579578 * connection.
580579 */
581- private void addHeaders (HttpURLConnection connection , Map headers ,
580+ private void addHeaders (HttpURLConnection connection , Map < String , List < String >> headers ,
582581 String prefix ) {
583582 if (headers != null ) {
584- for (Iterator i = headers .keySet ().iterator (); i .hasNext ();) {
585- String key = (String ) i .next ();
586- for (Iterator j = ((List ) headers .get (key )).iterator (); j
587- .hasNext ();) {
588- String value = (String ) j .next ();
583+ for (String key : headers .keySet ()) {
584+ for (String value :headers .get (key )) {
589585 connection .addRequestProperty (prefix + key , value );
590586 }
591587 }
0 commit comments