Skip to content

Commit

Permalink
use string() method in response.body() (minio#1047)
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana authored Sep 6, 2020
1 parent 323a89c commit 8c153fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions api/src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ protected Response execute(

String errorXml = null;
try (ResponseBody responseBody = response.body()) {
errorXml = new String(responseBody.bytes(), StandardCharsets.UTF_8);
errorXml = responseBody.string();
}

if (this.traceStream != null && !("".equals(errorXml) && method.equals(Method.HEAD))) {
Expand Down Expand Up @@ -5514,7 +5514,7 @@ public String getBucketLifeCycle(GetBucketLifeCycleArgs args)
XmlParserException {
checkArgs(args);
try (Response response = executeGet(args, null, newMultimap("lifecycle", ""))) {
return new String(response.body().bytes(), StandardCharsets.UTF_8);
return response.body().string();
} catch (ErrorResponseException e) {
if (!e.errorResponse().code().equals("NoSuchLifecycleConfiguration")) {
throw e;
Expand Down Expand Up @@ -7220,7 +7220,7 @@ protected ObjectWriteResponse completeMultipartUpload(
queryParams,
new CompleteMultipartUpload(parts),
0)) {
String bodyContent = new String(response.body().bytes(), StandardCharsets.UTF_8);
String bodyContent = response.body().string();
bodyContent = bodyContent.trim();
if (!bodyContent.isEmpty()) {
try {
Expand Down Expand Up @@ -7375,7 +7375,7 @@ protected DeleteObjectsResponse deleteObjects(
merge(extraQueryParams, newMultimap("delete", "")),
new DeleteRequest(objectList, quiet),
0)) {
String bodyContent = new String(response.body().bytes(), StandardCharsets.UTF_8);
String bodyContent = response.body().string();
try {
if (Xml.validate(DeleteError.class, bodyContent)) {
DeleteError error = Xml.unmarshal(DeleteError.class, bodyContent);
Expand Down
6 changes: 3 additions & 3 deletions functional/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static byte[] readObject(String urlString) throws Exception {
return response.body().bytes();
}

String errorXml = new String(response.body().bytes(), StandardCharsets.UTF_8);
String errorXml = response.body().string();
throw new Exception(
"failed to create object. Response: " + response + ", Response body: " + errorXml);
} finally {
Expand Down Expand Up @@ -350,7 +350,7 @@ public static void writeObject(String urlString, byte[] dataBytes) throws Except

try {
if (!response.isSuccessful()) {
String errorXml = new String(response.body().bytes(), StandardCharsets.UTF_8);
String errorXml = response.body().string();
throw new Exception(
"failed to create object. Response: " + response + ", Response body: " + errorXml);
}
Expand Down Expand Up @@ -1698,7 +1698,7 @@ public static void getPresignedPostFormData() throws Exception {

try {
if (!response.isSuccessful()) {
String errorXml = new String(response.body().bytes(), StandardCharsets.UTF_8);
String errorXml = response.body().string();
throw new Exception(
"failed to upload object. Response: " + response + ", Error: " + errorXml);
}
Expand Down

0 comments on commit 8c153fb

Please sign in to comment.