public void setBucketAcl ( SetBucketAclRequest request ) { checkNotNull ( request , "request should not be null." ) ; InternalRequest internalRequest = this . createRequest ( request , HttpMethodName . PUT ) ; internalRequest . addParameter ( "acl" , null ) ; if ( request . getCannedAcl ( ) != null ) { internalRequest . addHeader ( Headers . BCE_ACL , request . getCannedAcl ( ) . toString ( ) ) ; this . setZeroContentLength ( internalRequest ) ; } else if ( request . getAccessControlList ( ) != null ) { byte [ ] json = null ; List < Grant > grants = request . getAccessControlList ( ) ; StringWriter writer = new StringWriter ( ) ; try { JsonGenerator jsonGenerator = JsonUtils . jsonGeneratorOf ( writer ) ; jsonGenerator . writeStartObject ( ) ; jsonGenerator . writeArrayFieldStart ( "accessControlList" ) ; for ( Grant grant : grants ) { jsonGenerator . writeStartObject ( ) ; jsonGenerator . writeArrayFieldStart ( "grantee" ) ; for ( Grantee grantee : grant . getGrantee ( ) ) { jsonGenerator . writeStartObject ( ) ; jsonGenerator . writeStringField ( "id" , grantee . getId ( ) ) ; jsonGenerator . writeEndObject ( ) ; } jsonGenerator . writeEndArray ( ) ; jsonGenerator . writeArrayFieldStart ( "permission" ) ; for ( Permission permission : grant . getPermission ( ) ) { jsonGenerator . writeString ( permission . toString ( ) ) ; } jsonGenerator . writeEndArray ( ) ; jsonGenerator . writeEndObject ( ) ; } jsonGenerator . writeEndArray ( ) ; jsonGenerator . writeEndObject ( ) ; jsonGenerator . close ( ) ; } catch ( IOException e ) { throw new BceClientException ( "Fail to generate json" , e ) ; } try { json = writer . toString ( ) . getBytes ( DEFAULT_ENCODING ) ; } catch ( UnsupportedEncodingException e ) { throw new BceClientException ( "Fail to get UTF-8 bytes" , e ) ; } internalRequest . addHeader ( Headers . CONTENT_LENGTH , String . valueOf ( json . length ) ) ; internalRequest . addHeader ( Headers . CONTENT_TYPE , "application/json" ) ; internalRequest . setContent ( RestartableInputStream . wrap ( json ) ) ; } else if ( request . getJsonAcl ( ) != null ) { byte [ ] json = null ; try { json = request . getJsonAcl ( ) . getBytes ( DEFAULT_ENCODING ) ; } catch ( UnsupportedEncodingException e ) { throw new BceClientException ( "Fail to get UTF-8 bytes" , e ) ; } internalRequest . addHeader ( Headers . CONTENT_LENGTH , String . valueOf ( json . length ) ) ; internalRequest . addHeader ( Headers . CONTENT_TYPE , "application/json" ) ; internalRequest . setContent ( RestartableInputStream . wrap ( json ) ) ; } else { checkNotNull ( null , "request.acl should not be null." ) ; } this . invokeHttpClient ( internalRequest , BosResponse . class ) ; }
Sets the Acl for the specified Bos bucket .