Skip to content

Commit

Permalink
get_object: Support close explicitly & try-with-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
owarai committed Apr 29, 2024
1 parent d0c0d44 commit bba664e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
20 changes: 18 additions & 2 deletions src/main/java/com/qingstor/sdk/service/Bucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
import com.qingstor.sdk.service.Types.*;
import com.qingstor.sdk.utils.QSParamInvokeUtil;
import com.qingstor.sdk.utils.QSStringUtil;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -7125,7 +7127,7 @@ public String validateParam() {
* field ResponseExpires Specified the Expires response header <br>
* field VersionID Object version id <br>
*/
public static class GetObjectOutput extends OutputModel {
public static class GetObjectOutput extends OutputModel implements Closeable {

/** The response body */

Expand Down Expand Up @@ -7270,6 +7272,13 @@ public void setBodyInputStream(InputStream bodyInputStream) {
this.bodyInputStream = bodyInputStream;
}

@Override
public void close() throws IOException {
if (bodyInputStream != null) {
bodyInputStream.close();
}
}

/**
* The Cache-Control general-header field is used to specify directives for caching
* mechanisms in both requests and responses.
Expand Down Expand Up @@ -8158,7 +8167,7 @@ public String validateParam() {
* field ResponseContentType Specified the Content-Type response header <br>
* field ResponseExpires Specified the Expires response header <br>
*/
public static class ImageProcessOutput extends OutputModel {
public static class ImageProcessOutput extends OutputModel implements Closeable {

/** The response body */
private InputStream bodyInputStream;
Expand All @@ -8182,6 +8191,13 @@ public void setBodyInputStream(InputStream bodyInputStream) {
this.bodyInputStream = bodyInputStream;
}

@Override
public void close() throws IOException {
if (bodyInputStream != null) {
bodyInputStream.close();
}
}

/** Object content length */
private Long contentLength;

Expand Down
1 change: 1 addition & 0 deletions src/test/java/integration/cucumber/ImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ public void image_process_status_code_is(int statusCode) throws Throwable {
// Write code here that turns the phrase above into concrete actions
System.out.println("image_process_message:" + imageProcessOutput.getMessage());
TestUtil.assertEqual(imageProcessOutput.getStatueCode(), statusCode);
imageProcessOutput.close();
}
}
10 changes: 9 additions & 1 deletion template/shared.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@
* field {{$property.Name| camelCase}} {{replace $property.Description "<bucket-name>/<object-key>" "'bucket-name'/'object-key'" -1}} <br>
{{- end}}
*/
public static class {{$opID}}Output extends OutputModel{
public static class {{$opID}}Output extends OutputModel {{if eq $opID "GetObject" "ImageProcess"}} implements Closeable {{- end}} {
{{range $_, $response := $operation.Responses}}
{{if eq $response.Body.Type "string"}}
{{if $response.Body.Description -}}
Expand Down Expand Up @@ -961,6 +961,14 @@
public void setBodyInputStream(InputStream bodyInputStream) {
this.bodyInputStream=bodyInputStream;
}

@Override
public void close() throws IOException {
if (bodyInputStream != null) {
bodyInputStream.close();
}
}

{{end}}

{{if $response.Elements.Properties | len}}
Expand Down
2 changes: 2 additions & 0 deletions template/sub_services.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package com.qingstor.sdk.service;

import java.io.Closeable;
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down

0 comments on commit bba664e

Please sign in to comment.