• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.core.internal.chunked;
17 
18 import software.amazon.awssdk.annotations.SdkInternalApi;
19 
20 @SdkInternalApi
21 public final class AwsChunkedEncodingConfig {
22 
23     private final int chunkSize;
24     private final int bufferSize;
25 
AwsChunkedEncodingConfig(BuilderImpl builder)26     private AwsChunkedEncodingConfig(BuilderImpl builder) {
27         this.chunkSize = builder.chunkSize;
28         this.bufferSize = builder.bufferSize;
29     }
30 
create()31     public static AwsChunkedEncodingConfig create() {
32         return builder().build();
33     }
34 
builder()35     public static Builder builder() {
36         return new BuilderImpl();
37     }
38 
chunkSize()39     public int chunkSize() {
40         return chunkSize;
41     }
42 
bufferSize()43     public int bufferSize() {
44         return bufferSize;
45     }
46 
47     public interface Builder {
48 
chunkSize(int chunkSize)49         Builder chunkSize(int chunkSize);
50 
bufferSize(int bufferSize)51         Builder bufferSize(int bufferSize);
52 
build()53         AwsChunkedEncodingConfig build();
54     }
55 
56     private static final class BuilderImpl implements Builder {
57         static final int DEFAULT_CHUNKED_ENCODING_ENABLED = 128 * 1024;
58         static final int DEFAULT_PAYLOAD_SIGNING_ENABLED = 256 * 1024;
59 
60         private int chunkSize = DEFAULT_CHUNKED_ENCODING_ENABLED;
61         private int bufferSize = DEFAULT_PAYLOAD_SIGNING_ENABLED;
62 
BuilderImpl()63         private BuilderImpl() {
64         }
65 
66         @Override
chunkSize(int chunkSize)67         public Builder chunkSize(int chunkSize) {
68             this.chunkSize = chunkSize;
69             return this;
70         }
71 
setChunkSize(int chunkSize)72         public void setChunkSize(int chunkSize) {
73             chunkSize(chunkSize);
74         }
75 
76         @Override
bufferSize(int bufferSize)77         public Builder bufferSize(int bufferSize) {
78             this.bufferSize = bufferSize;
79             return this;
80         }
81 
setBufferSize(int bufferSize)82         public void setBufferSize(int bufferSize) {
83             bufferSize(bufferSize);
84         }
85 
86         @Override
build()87         public AwsChunkedEncodingConfig build() {
88             return new AwsChunkedEncodingConfig(this);
89         }
90     }
91 }
92