mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
= code cleanup
- for loop replaceable with enhanced 'for' loop - using diamond in generic type - collapse try catch exception - using try-with-resource - using List#sort instead of Collections#sort - replaced lambda with method reference - using native compare method to compare numbers - using switch instead of if for in ESSyncUtil
This commit is contained in:
@@ -18,20 +18,11 @@ public class AddressUtils {
|
||||
private static final Pattern IP_PATTERN = Pattern.compile("[0-9]{1,3}(\\.[0-9]{1,3}){3,}");
|
||||
|
||||
public static boolean isAvailablePort(int port) {
|
||||
ServerSocket ss = null;
|
||||
try {
|
||||
ss = new ServerSocket(port);
|
||||
try (ServerSocket ss = new ServerSocket(port)) {
|
||||
ss.bind(null);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (ss != null) {
|
||||
try {
|
||||
ss.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -71,14 +71,11 @@ public class JsonUtils {
|
||||
*/
|
||||
public static String marshalToString(Object obj, String... fliterFields) {
|
||||
final List<String> propertyFliters = Arrays.asList(fliterFields);
|
||||
SerializeWriter out = new SerializeWriter();
|
||||
try {
|
||||
try (SerializeWriter out = new SerializeWriter()) {
|
||||
JSONSerializer serializer = new JSONSerializer(out);
|
||||
serializer.getPropertyFilters().add((source, name, value) -> !propertyFliters.contains(name));
|
||||
serializer.write(obj);
|
||||
return out.toString();
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user