Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return higher level object GetObjectResponse for getObject API #998

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/main/java/io/minio/GenericResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import okhttp3.Headers;

/** Generic response class of any APIs. */
public abstract class GenericResponse {
public class GenericResponse {
private Headers headers;
private String bucket;
private String region;
Expand Down
47 changes: 47 additions & 0 deletions api/src/main/java/io/minio/GetObjectResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.io.FilterInputStream;
import java.io.InputStream;
import okhttp3.Headers;

public class GetObjectResponse extends FilterInputStream {
private GenericResponse response;

public GetObjectResponse(
Headers headers, String bucket, String region, String object, InputStream body) {
super(body);
this.response = new GenericResponse(headers, bucket, region, object);
}

public Headers headers() {
return response.headers();
}

public String bucket() {
return response.bucket();
}

public String region() {
return response.region();
}

public String object() {
return response.object();
}
}
9 changes: 7 additions & 2 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ public InputStream getObject(
* @throws NoSuchAlgorithmException thrown to indicate missing of MD5 or SHA-256 digest library.
* @throws XmlParserException thrown to indicate XML parsing error.
*/
public InputStream getObject(GetObjectArgs args)
public GetObjectResponse getObject(GetObjectArgs args)
throws ErrorResponseException, IllegalArgumentException, InsufficientDataException,
InternalException, InvalidBucketNameException, InvalidKeyException,
InvalidResponseException, IOException, NoSuchAlgorithmException, ServerException,
Expand Down Expand Up @@ -1695,7 +1695,12 @@ public InputStream getObject(GetObjectArgs args)
if (args.versionId() != null) queryParams.put("versionId", args.versionId());

Response response = executeGet(args, headers, queryParams);
return response.body().byteStream();
return new GetObjectResponse(
response.headers(),
args.bucket(),
args.region(),
args.object(),
response.body().byteStream());
}

/**
Expand Down