mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-19 04:05:36 +00:00
Use try-with-resource statement
This commit is contained in:
+3
-4
@@ -5248,11 +5248,10 @@ Replicator {
|
||||
String message = e.getMessage();
|
||||
if (connection instanceof HttpURLConnection) {
|
||||
// try to obtain an error message from the connection's error stream:
|
||||
try {
|
||||
message = new BufferedReader(
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(((HttpURLConnection) connection).getErrorStream(),
|
||||
HttpUrlConnectionHelper.getCharsetFromConnectionOrDefault(connection, "UTF-8")))
|
||||
.readLine();
|
||||
HttpUrlConnectionHelper.getCharsetFromConnectionOrDefault(connection, "UTF-8")))) {
|
||||
message = reader.readLine();
|
||||
} catch (Exception exceptionTryingToReadErrorStream) {
|
||||
// in this case we just stay with the exception's message
|
||||
}
|
||||
|
||||
@@ -142,9 +142,10 @@ public class MongoDBServiceImpl implements MongoDBService {
|
||||
|
||||
@Override
|
||||
public MongoClient getMongo(ConnectionString mongoConnectionString) {
|
||||
MongoClient mongo = mongos.computeIfAbsent(mongoConnectionString,
|
||||
k-> MongoClients.create(mongoConnectionString));
|
||||
return mongo;
|
||||
try (MongoClient mongo = mongos.computeIfAbsent(mongoConnectionString,
|
||||
k-> MongoClients.create(mongoConnectionString))) {
|
||||
return mongo;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user