@@ -111,20 +111,10 @@ public static Credentials promptCredentials(Credentials c, File passfile) {
111
111
Properties props = new EncryptedProperties ();
112
112
props .setProperty ("username" , username );
113
113
props .setProperty ("passwd" , passwd );
114
- FileOutputStream fos = null ;
115
- try {
116
- fos = new FileOutputStream (passfile );
114
+ try (FileOutputStream fos = new FileOutputStream (passfile )) {
117
115
props .store (fos , "" );
118
116
} catch (Exception e ) {
119
117
Message .warn ("error occurred while saving password file " + passfile , e );
120
- } finally {
121
- if (fos != null ) {
122
- try {
123
- fos .close ();
124
- } catch (Exception e ) {
125
- // ignored
126
- }
127
- }
128
118
}
129
119
}
130
120
c = new Credentials (c .getRealm (), c .getHost (), username , passwd );
@@ -135,9 +125,7 @@ public static Credentials promptCredentials(Credentials c, File passfile) {
135
125
public static Credentials loadPassfile (Credentials c , File passfile ) {
136
126
if (passfile != null && passfile .exists ()) {
137
127
Properties props = new EncryptedProperties ();
138
- FileInputStream fis = null ;
139
- try {
140
- fis = new FileInputStream (passfile );
128
+ try (FileInputStream fis = new FileInputStream (passfile )) {
141
129
props .load (fis );
142
130
String username = c .getUserName ();
143
131
String passwd = c .getPasswd ();
@@ -150,14 +138,6 @@ public static Credentials loadPassfile(Credentials c, File passfile) {
150
138
return new Credentials (c .getRealm (), c .getHost (), username , passwd );
151
139
} catch (IOException e ) {
152
140
Message .warn ("error occurred while loading password file " + passfile , e );
153
- } finally {
154
- if (fis != null ) {
155
- try {
156
- fis .close ();
157
- } catch (IOException e ) {
158
- // ignored
159
- }
160
- }
161
141
}
162
142
}
163
143
return c ;
0 commit comments