-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Args builder for getObject API (#954)
* Implement Args builder for getObject API New Argument class: `GetObjectArgs` Arguments supported: - offset (Long) - length (Long) - ssec (ServerSideEncryptionWithCustomerKey) Since there are multiple APIs / args classes that need sse as an argument, introduced an intermediate abstract class `SsecObjectArgs` that supports the `ssec` argument, and provides common logic related to it e.g. validations. Since the return type of the methods that support downloading the object as a file is `void`, we cannot name it same as `getObject`. So introduced a new method called `downloadObject` for downloading the object, which internally uses `getObject`. And created a separate args class `DownloadObjectArgs` for it. Also, - Enhanced the method `FunctionalTest#handleException` to support logging of the arguments as well. - Moved the class `ServerSideEncryptionWithCustomerKey` outside of `ServerSideEncryption` and made it into a standalone class. * Incorporate review comments - Change `sse` to `ssec` in javadoc comments on stateObject - Remove unused static variables from `SsecObjectArgs`
- Loading branch information
1 parent
19b2011
commit 928b31b
Showing
20 changed files
with
750 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.minio; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class DownloadObjectArgs extends SsecObjectArgs { | ||
private String fileName; | ||
|
||
public String fileName() { | ||
return fileName; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder extends SsecObjectArgs.Builder<Builder, DownloadObjectArgs> { | ||
public Builder fileName(String fileName) { | ||
validateFileName(fileName); | ||
operations.add(args -> args.fileName = fileName); | ||
return this; | ||
} | ||
|
||
private void validateFileName(String fileName) { | ||
if (fileName == null) { | ||
return; | ||
} | ||
|
||
if (fileName.isEmpty()) { | ||
throw new IllegalArgumentException("filename should be either null or non-empty"); | ||
} | ||
|
||
Path filePath = Paths.get(fileName); | ||
boolean fileExists = Files.exists(filePath); | ||
|
||
if (fileExists && !Files.isRegularFile(filePath)) { | ||
throw new IllegalArgumentException(fileName + ": not a regular file"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.minio; | ||
|
||
public class GetObjectArgs extends SsecObjectArgs { | ||
private Long offset; | ||
private Long length; | ||
|
||
public Long length() { | ||
return length; | ||
} | ||
|
||
public Long offset() { | ||
return offset; | ||
} | ||
|
||
public static Builder builder() { | ||
return new Builder(); | ||
} | ||
|
||
public static final class Builder extends SsecObjectArgs.Builder<Builder, GetObjectArgs> { | ||
public Builder offset(Long offset) { | ||
validateOffset(offset); | ||
operations.add(args -> args.offset = offset); | ||
return this; | ||
} | ||
|
||
public Builder length(Long length) { | ||
validateLength(length); | ||
operations.add(args -> args.length = length); | ||
return this; | ||
} | ||
|
||
private void validateLength(Long length) { | ||
if (length != null && length <= 0) { | ||
throw new IllegalArgumentException("length should be greater than zero"); | ||
} | ||
} | ||
|
||
private void validateOffset(Long offset) { | ||
if (offset != null && offset < 0) { | ||
throw new IllegalArgumentException("offset should be zero or greater"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.