Skip to content

Commit 9f9d9fa

Browse files
committed
Refactor messages by subclasses
merge SelectObjectContentRequest merge ListVersionsResult Remove unused CompleteMultipartUploadOutput.java merge ListMultipartUploadsResult merge NotificationRecords merge SseConfiguration merge DeleteRequest, DeleteResult merge RestoreRequest merge NotificationConfiguration merge LifecycleConfiguration merge ReplicationConfiguration merge Filter merge ObjectLockConfiguration merge ListAllMyBucketsResult merge Item merge ListObjectsResult Move common fields for ListPartsResult and GetObjectAttributesOutput Signed-off-by: Bala.FA <bala@minio.io>
1 parent 5e7e074 commit 9f9d9fa

File tree

203 files changed

+5170
-6458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+5170
-6458
lines changed

adminapi/src/main/java/io/minio/admin/MinioAdminClient.java

Lines changed: 51 additions & 55 deletions
Large diffs are not rendered by default.

api/src/main/java/io/minio/BaseArgs.java

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,75 +60,34 @@ public abstract static class Builder<B extends Builder<B, A>, A extends BaseArgs
6060

6161
protected abstract void validate(A args);
6262

63-
protected void validateNotNull(Object arg, String argName) {
64-
if (arg == null) {
65-
throw new IllegalArgumentException(argName + " must not be null.");
66-
}
67-
}
68-
69-
protected void validateNotEmptyString(String arg, String argName) {
70-
validateNotNull(arg, argName);
71-
if (arg.isEmpty()) {
72-
throw new IllegalArgumentException(argName + " must be a non-empty string.");
73-
}
74-
}
75-
76-
protected void validateNullOrNotEmptyString(String arg, String argName) {
77-
if (arg != null && arg.isEmpty()) {
78-
throw new IllegalArgumentException(argName + " must be a non-empty string.");
79-
}
80-
}
81-
82-
protected void validateNullOrPositive(Number arg, String argName) {
83-
if (arg != null && arg.longValue() < 0) {
84-
throw new IllegalArgumentException(argName + " cannot be non-negative.");
85-
}
86-
}
87-
8863
public Builder() {
8964
this.operations = new ArrayList<>();
9065
}
9166

92-
protected Multimap<String, String> copyMultimap(Multimap<String, String> multimap) {
93-
Multimap<String, String> multimapCopy = HashMultimap.create();
94-
if (multimap != null) {
95-
multimapCopy.putAll(multimap);
96-
}
97-
return Multimaps.unmodifiableMultimap(multimapCopy);
98-
}
99-
100-
protected Multimap<String, String> toMultimap(Map<String, String> map) {
101-
Multimap<String, String> multimap = HashMultimap.create();
102-
if (map != null) {
103-
multimap.putAll(Multimaps.forMap(map));
104-
}
105-
return Multimaps.unmodifiableMultimap(multimap);
106-
}
107-
10867
@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
10968
public B extraHeaders(Multimap<String, String> headers) {
110-
final Multimap<String, String> extraHeaders = copyMultimap(headers);
69+
final Multimap<String, String> extraHeaders = Utils.newMultimap(headers);
11170
operations.add(args -> args.extraHeaders = extraHeaders);
11271
return (B) this;
11372
}
11473

11574
@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
11675
public B extraQueryParams(Multimap<String, String> queryParams) {
117-
final Multimap<String, String> extraQueryParams = copyMultimap(queryParams);
76+
final Multimap<String, String> extraQueryParams = Utils.newMultimap(queryParams);
11877
operations.add(args -> args.extraQueryParams = extraQueryParams);
11978
return (B) this;
12079
}
12180

12281
@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
12382
public B extraHeaders(Map<String, String> headers) {
124-
final Multimap<String, String> extraHeaders = toMultimap(headers);
83+
final Multimap<String, String> extraHeaders = Utils.newMultimap(headers);
12584
operations.add(args -> args.extraHeaders = extraHeaders);
12685
return (B) this;
12786
}
12887

12988
@SuppressWarnings("unchecked") // Its safe to type cast to B as B extends this class.
13089
public B extraQueryParams(Map<String, String> queryParams) {
131-
final Multimap<String, String> extraQueryParams = toMultimap(queryParams);
90+
final Multimap<String, String> extraQueryParams = Utils.newMultimap(queryParams);
13291
operations.add(args -> args.extraQueryParams = extraQueryParams);
13392
return (B) this;
13493
}

api/src/main/java/io/minio/BucketArgs.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package io.minio;
1818

19-
import io.minio.http.HttpUtils;
20-
import io.minio.org.apache.commons.validator.routines.InetAddressValidator;
2119
import java.util.Objects;
2220
import java.util.regex.Pattern;
2321

@@ -42,7 +40,7 @@ public abstract static class Builder<B extends Builder<B, A>, A extends BucketAr
4240
protected boolean skipValidation = false;
4341

4442
protected void validateBucketName(String name) {
45-
validateNotNull(name, "bucket name");
43+
Utils.validateNotNull(name, "bucket name");
4644
if (skipValidation) {
4745
return;
4846
}
@@ -55,7 +53,7 @@ protected void validateBucketName(String name) {
5553
+ "https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html");
5654
}
5755

58-
if (InetAddressValidator.getInstance().isValidInet4Address(name)) {
56+
if (Utils.isValidIPv4(name)) {
5957
throw new IllegalArgumentException(
6058
"bucket name '" + name + "' must not be formatted as an IP address");
6159
}
@@ -67,7 +65,7 @@ protected void validateBucketName(String name) {
6765
}
6866

6967
private void validateRegion(String region) {
70-
if (!skipValidation && region != null && !HttpUtils.REGION_REGEX.matcher(region).find()) {
68+
if (!skipValidation && region != null && !Utils.REGION_REGEX.matcher(region).find()) {
7169
throw new IllegalArgumentException("invalid region " + region);
7270
}
7371
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2025 MinIO, Inc.
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+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.minio;
18+
19+
import java.util.zip.Checksum;
20+
21+
/** Collection of utility functions. */
22+
public class Checksum {
23+
/** Checksum Algorithm. */
24+
public static enum Algorithm {
25+
CRC32,
26+
CRC32C,
27+
CRC64NVME,
28+
SHA1,
29+
SHA256;
30+
}
31+
32+
/** CRC32 checksum is an alias of java.util.zip.CRC32. */
33+
public static class CRC32 extends java.util.zip.CRC32 {}
34+
35+
// {
36+
// CRC32 hasher = new CRC32();
37+
// hasher.update(value);
38+
// System.out.println("crc32: " + hasher.getValue());
39+
// }
40+
//
41+
// {
42+
// CRC32C hasher = new CRC32C();
43+
// hasher.update(value);
44+
// System.out.println("crc32c: " + hasher.getValue());
45+
// }
46+
//
47+
// {
48+
// CRC64NVME hasher = new CRC64NVME();
49+
// hasher.update(value);
50+
// System.out.println("crc64nvme: " + hasher.getValue());
51+
// }
52+
//
53+
// {
54+
// MessageDigest hasher = MessageDigest.getInstance("SHA-1");
55+
// hasher.update(value);
56+
// System.out.println("sha-1: " + Arrays.toString(toPositiveValues(hasher.digest())));
57+
// }
58+
//
59+
// {
60+
// MessageDigest hasher = MessageDigest.getInstance("SHA-256");
61+
// hasher.update(value);
62+
// System.out.println("sha-256: " + Arrays.toString(toPositiveValues(hasher.digest())));
63+
// }
64+
65+
/** CRC32C checksum. */
66+
public static class CRC32C implements Checksum {
67+
private static final int[] CRC32C_TABLE = new int[256];
68+
private int crc = 0xFFFFFFFF;
69+
70+
static {
71+
for (int i = 0; i < 256; i++) {
72+
int crc = i;
73+
for (int j = 0; j < 8; j++) {
74+
crc = (crc >>> 1) ^ ((crc & 1) != 0 ? 0x82F63B78 : 0);
75+
}
76+
CRC32C_TABLE[i] = crc;
77+
}
78+
}
79+
80+
@Override
81+
public void update(int b) {
82+
crc = CRC32C_TABLE[(crc ^ b) & 0xFF] ^ (crc >>> 8);
83+
}
84+
85+
@Override
86+
public void update(byte[] b, int off, int len) {
87+
for (int i = off; i < off + len; i++) {
88+
update(b[i]);
89+
}
90+
}
91+
92+
@Override
93+
public long getValue() {
94+
return (crc ^ 0xFFFFFFFFL) & 0xFFFFFFFFL;
95+
}
96+
97+
@Override
98+
public void reset() {
99+
crc = 0xFFFFFFFF;
100+
}
101+
}
102+
103+
/** CRC64NVME checksum logic copied from https://github.com/minio/crc64nvme. */
104+
public static class CRC64NVME implements Checksum {
105+
private static final long[] CRC64_TABLE = new long[256];
106+
private static final long[][] SLICING8_TABLE_NVME = new long[8][256];
107+
108+
static {
109+
long polynomial = 0x9A6C9329AC4BC9B5L;
110+
for (int i = 0; i < 256; i++) {
111+
long crc = i;
112+
for (int j = 0; j < 8; j++) {
113+
if ((crc & 1) == 1) {
114+
crc = (crc >>> 1) ^ polynomial;
115+
} else {
116+
crc >>>= 1;
117+
}
118+
}
119+
CRC64_TABLE[i] = crc;
120+
}
121+
122+
SLICING8_TABLE_NVME[0] = CRC64_TABLE;
123+
for (int i = 0; i < 256; i++) {
124+
long crc = CRC64_TABLE[i];
125+
for (int j = 1; j < 8; j++) {
126+
crc = CRC64_TABLE[(int) crc & 0xFF] ^ (crc >>> 8);
127+
SLICING8_TABLE_NVME[j][i] = crc;
128+
}
129+
}
130+
}
131+
132+
private long crc;
133+
134+
public CRC64NVME() {
135+
reset();
136+
}
137+
138+
@Override
139+
public void update(byte[] p, int off, int len) {
140+
ByteBuffer byteBuffer = ByteBuffer.wrap(p, off, len);
141+
byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
142+
int offset = byteBuffer.position();
143+
144+
crc = ~crc;
145+
while (p.length >= 64 && (p.length - offset) > 8) {
146+
long value = byteBuffer.getLong();
147+
crc ^= value;
148+
crc =
149+
SLICING8_TABLE_NVME[7][(int) (crc & 0xFF)]
150+
^ SLICING8_TABLE_NVME[6][(int) ((crc >>> 8) & 0xFF)]
151+
^ SLICING8_TABLE_NVME[5][(int) ((crc >>> 16) & 0xFF)]
152+
^ SLICING8_TABLE_NVME[4][(int) ((crc >>> 24) & 0xFF)]
153+
^ SLICING8_TABLE_NVME[3][(int) ((crc >>> 32) & 0xFF)]
154+
^ SLICING8_TABLE_NVME[2][(int) ((crc >>> 40) & 0xFF)]
155+
^ SLICING8_TABLE_NVME[1][(int) ((crc >>> 48) & 0xFF)]
156+
^ SLICING8_TABLE_NVME[0][(int) (crc >>> 56)];
157+
offset = byteBuffer.position();
158+
}
159+
160+
for (; offset < len; offset++) {
161+
crc = CRC64_TABLE[(int) ((crc ^ (long) p[offset]) & 0xFF)] ^ (crc >>> 8);
162+
}
163+
164+
crc = ~crc;
165+
}
166+
167+
@Override
168+
public void update(byte[] p) {
169+
update(p, 0, p.length);
170+
}
171+
172+
@Override
173+
public void update(int b) {
174+
update(new byte[] {(byte) b});
175+
}
176+
177+
@Override
178+
public long getValue() {
179+
return crc;
180+
}
181+
182+
@Override
183+
public void reset() {
184+
crc = 0;
185+
}
186+
187+
@Override
188+
public String toString() {
189+
return String.format("CRC64NVME{value=%016x}", crc);
190+
}
191+
}
192+
}

api/src/main/java/io/minio/CopyObjectArgs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static final class Builder extends ObjectWriteArgs.Builder<Builder, CopyO
6969
@Override
7070
protected void validate(CopyObjectArgs args) {
7171
super.validate(args);
72-
validateNotNull(args.source, "copy source");
72+
Utils.validateNotNull(args.source, "copy source");
7373
if (args.source.offset() != null || args.source.length() != null) {
7474
if (args.metadataDirective != null && args.metadataDirective == Directive.COPY) {
7575
throw new IllegalArgumentException(
@@ -83,7 +83,7 @@ protected void validate(CopyObjectArgs args) {
8383
}
8484

8585
public Builder source(CopySource source) {
86-
validateNotNull(source, "copy source");
86+
Utils.validateNotNull(source, "copy source");
8787
operations.add(args -> args.source = source);
8888
return this;
8989
}

0 commit comments

Comments
 (0)