This is an automated email from the ASF dual-hosted git repository.
fanjia pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/seatunnel.git
The following commit(s) were added to refs/heads/dev by this push:
new d0aff52425 [Chore] Using try-with-resources to simplify the code.
(#4995)
d0aff52425 is described below
commit d0aff52425df80e80568bec392e0bf40746004d2
Author: asia-zengtao <[email protected]>
AuthorDate: Thu Oct 26 13:54:33 2023 +0800
[Chore] Using try-with-resources to simplify the code. (#4995)
---------
Co-authored-by: hailin0 <[email protected]>
---
.../connectors/doris/rest/RestService.java | 25 +++++++++-------------
1 file changed, 10 insertions(+), 15 deletions(-)
diff --git
a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
index adb185dc9e..1b456de86c 100644
---
a/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
+++
b/seatunnel-connectors-v2/connector-doris/src/main/java/org/apache/seatunnel/connectors/doris/rest/RestService.java
@@ -209,31 +209,26 @@ public class RestService implements Serializable {
private static String parseResponse(HttpURLConnection connection, Logger
logger)
throws IOException {
- if (connection.getResponseCode() != HttpStatus.SC_OK) {
+ int responseCode = connection.getResponseCode();
+ if (responseCode != HttpStatus.SC_OK) {
logger.warn(
- "Failed to get response from Doris {}, http code is {}",
+ "Failed to get response from Doris {}, http code is {}",
connection.getURL(),
- connection.getResponseCode());
+ responseCode);
throw new IOException("Failed to get response from Doris");
}
+
StringBuilder result = new StringBuilder();
- BufferedReader in = null;
- try {
- in =
- new BufferedReader(
- new InputStreamReader(
- connection.getInputStream(),
StandardCharsets.UTF_8));
+ try (BufferedReader in =
+ new BufferedReader(
+ new InputStreamReader(
+ connection.getInputStream(),
StandardCharsets.UTF_8))) {
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
- } catch (IOException e) {
- throw new IOException(e);
- } finally {
- if (in != null) {
- in.close();
- }
}
+
return result.toString();
}