Skip to content

Commit 2bd9395

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 <[email protected]>
1 parent 5e7e074 commit 2bd9395

File tree

220 files changed

+7953
-7570
lines changed

Some content is hidden

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

220 files changed

+7953
-7570
lines changed

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

+53-55
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.Objects;
20+
21+
/**
22+
* Argument class of {@link MinioAsyncClient#abortMultipartUpload} and {@link
23+
* MinioClient#abortMultipartUpload}.
24+
*/
25+
public class AbortMultipartUploadArgs extends ObjectArgs {
26+
private String uploadId;
27+
28+
public String uploadId() {
29+
return uploadId;
30+
}
31+
32+
public static Builder builder() {
33+
return new Builder();
34+
}
35+
36+
/** Argument builder of {@link AbortMultipartUploadArgs}. */
37+
public static final class Builder extends ObjectArgs.Builder<Builder, AbortMultipartUploadArgs> {
38+
@Override
39+
protected void validate(AbortMultipartUploadArgs args) {
40+
super.validate(args);
41+
Utils.validateNotEmptyString(args.uploadId, "upload ID");
42+
}
43+
44+
public Builder uploadId(String uploadId) {
45+
Utils.validateNotEmptyString(uploadId, "upload ID");
46+
operations.add(args -> args.uploadId = uploadId);
47+
return this;
48+
}
49+
}
50+
51+
@Override
52+
public boolean equals(Object o) {
53+
if (this == o) return true;
54+
if (!(o instanceof AbortMultipartUploadArgs)) return false;
55+
if (!super.equals(o)) return false;
56+
AbortMultipartUploadArgs that = (AbortMultipartUploadArgs) o;
57+
return Objects.equals(uploadId, that.uploadId);
58+
}
59+
60+
@Override
61+
public int hashCode() {
62+
return Objects.hash(super.hashCode(), uploadId);
63+
}
64+
}

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

+4-45
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

+3-5
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
}
+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage,
3+
* (C) 2025 MinIO, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.minio;
19+
20+
import java.io.ByteArrayInputStream;
21+
import java.io.ByteArrayOutputStream;
22+
import java.io.IOException;
23+
import java.io.InputStream;
24+
import java.io.OutputStream;
25+
import java.io.SequenceInputStream;
26+
import java.util.ArrayList;
27+
import java.util.Collections;
28+
import java.util.List;
29+
30+
public class ByteBuffer extends OutputStream {
31+
private static class Buffer extends ByteArrayOutputStream {
32+
public InputStream inputStream() {
33+
return (count > 0) ? new ByteArrayInputStream(buf, 0, count) : null;
34+
}
35+
}
36+
37+
private static final long MAX_SIZE = 5L * 1024 * 1024 * 1024;
38+
private static final int CHUNK_SIZE = Integer.MAX_VALUE;
39+
private final long totalSize;
40+
private final List<Buffer> buffers = new ArrayList<>();
41+
private int index = 0;
42+
private long writtenBytes = 0;
43+
private boolean isClosed = false;
44+
45+
public ByteBuffer(long totalSize) {
46+
if (totalSize > MAX_SIZE) {
47+
throw new IllegalArgumentException("Total size cannot exceed 5GiB");
48+
}
49+
this.totalSize = totalSize;
50+
}
51+
52+
private void updateIndex() {
53+
if (buffers.isEmpty()) {
54+
index = 0;
55+
buffers.add(new Buffer());
56+
} else if (writtenBytes >= (long) (index + 1) * CHUNK_SIZE) {
57+
index++;
58+
if (index > buffers.size() - 1) buffers.add(new Buffer());
59+
}
60+
}
61+
62+
@Override
63+
public void write(int b) throws IOException {
64+
if (isClosed) throw new IOException("Stream is closed");
65+
if (writtenBytes >= totalSize) throw new IOException("Exceeded total size limit");
66+
updateIndex();
67+
buffers.get(index).write(b);
68+
writtenBytes++;
69+
}
70+
71+
@Override
72+
public void write(byte[] b, int off, int len) throws IOException {
73+
if (isClosed) throw new IOException("Stream is closed");
74+
if (len > (totalSize - writtenBytes)) throw new IOException("Exceeded total size limit");
75+
int remaining = len;
76+
while (remaining > 0) {
77+
updateIndex();
78+
Buffer currentBuffer = buffers.get(index);
79+
int bytesToWrite = Math.min(remaining, CHUNK_SIZE - currentBuffer.size());
80+
currentBuffer.write(b, off + (len - remaining), bytesToWrite);
81+
writtenBytes += bytesToWrite;
82+
remaining -= bytesToWrite;
83+
}
84+
}
85+
86+
@Override
87+
public void write(byte[] b) throws IOException {
88+
write(b, 0, b.length);
89+
}
90+
91+
public long length() {
92+
return writtenBytes;
93+
}
94+
95+
public void reset() throws IOException {
96+
if (isClosed) throw new IOException("Cannot reset a closed stream");
97+
writtenBytes = 0;
98+
index = 0;
99+
for (Buffer buffer : buffers) buffer.reset();
100+
}
101+
102+
public void close() throws IOException {
103+
if (!isClosed) {
104+
isClosed = true;
105+
buffers.clear();
106+
}
107+
}
108+
109+
public InputStream inputStream() throws IOException {
110+
List<InputStream> streams = new ArrayList<>();
111+
for (Buffer buffer : buffers) {
112+
InputStream stream = buffer.inputStream();
113+
if (stream != null) streams.add(stream);
114+
}
115+
switch (streams.size()) {
116+
case 0:
117+
return new ByteArrayInputStream(Utils.EMPTY_BODY);
118+
case 1:
119+
return streams.get(0);
120+
default:
121+
return new SequenceInputStream(Collections.enumeration(streams));
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)