Bladeren bron

use try-with-resource

Armin Schrenk 2 jaren geleden
bovenliggende
commit
93500a4efd
1 gewijzigde bestanden met toevoegingen van 4 en 2 verwijderingen
  1. 4 2
      src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java

+ 4 - 2
src/main/java/org/cryptomator/ui/keyloading/hub/RegisterDeviceController.java

@@ -78,8 +78,10 @@ public class RegisterDeviceController implements FxController {
 	}
 
 	private String determineHostname() {
-		try {
-			return new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec("hostname").getInputStream())).readLine();
+		try (var inputStream = Runtime.getRuntime().exec("hostname").getInputStream(); //
+			 var streamReader = new InputStreamReader(inputStream); //
+			 var bufferedReader = new BufferedReader(streamReader)) {
+			return bufferedReader.readLine();
 		} catch (IOException e) {
 			return String.valueOf(ThreadLocalRandom.current().nextInt());
 		}