@@ -147,45 +147,35 @@ public Map<String, Host> refresh() {
147147 }
148148
149149 private Map <String , Host > parse (final InputStream in ) throws IOException {
150- final Map <String , Host > m = new LinkedHashMap <String , Host >();
150+ final Map <String , Host > m = new LinkedHashMap <>();
151151 final BufferedReader br = new BufferedReader (new InputStreamReader (in , StandardCharsets .UTF_8 ));
152- final List <Host > current = new ArrayList <Host >(4 );
152+ final List <Host > current = new ArrayList <>(4 );
153153 String line ;
154154
155155 while ((line = br .readLine ()) != null ) {
156156 line = line .trim ();
157- if (line .length () == 0 || line .startsWith ("#" )) {
157+ if (line .isEmpty () || line .startsWith ("#" )) {
158158 continue ;
159159 }
160-
161160 final String [] parts = line .split ("[ \t ]*[= \t ]" , 2 );
162161 if (parts .length != 2 ) {
163162 continue ;
164163 }
165164 final String keyword = parts [0 ].trim ();
166165 final String argValue = parts [1 ].trim ();
167-
168166 if ("Host" .equalsIgnoreCase (keyword )) {
169167 current .clear ();
170168 for (final String pattern : argValue .split ("[ \t ]" )) {
171169 final String name = dequote (pattern );
172- Host c = m .get (name );
173- if (c == null ) {
174- c = new Host ();
175- m .put (name , c );
176- }
170+ Host c = m .computeIfAbsent (name , k -> new Host ());
177171 current .add (c );
178172 }
179173 continue ;
180174 }
181-
182175 if (current .isEmpty ()) {
183- // We received an option outside of a Host block. We
184- // don't know who this should match against, so skip.
185- //
176+ // We received an option outside a Host block. We don't know who this should match against, so skip.
186177 continue ;
187178 }
188-
189179 if ("HostName" .equalsIgnoreCase (keyword )) {
190180 for (final Host c : current ) {
191181 if (c .hostName == null ) {
@@ -196,7 +186,7 @@ private Map<String, Host> parse(final InputStream in) throws IOException {
196186 else if ("ProxyJump" .equalsIgnoreCase (keyword )) {
197187 for (final Host c : current ) {
198188 if (c .proxyJump == null ) {
199- c .proxyJump = dequote (argValue );
189+ c .proxyJump = none ( dequote (argValue ) );
200190 }
201191 }
202192 }
@@ -223,21 +213,21 @@ else if("Port".equalsIgnoreCase(keyword)) {
223213 else if ("IdentityFile" .equalsIgnoreCase (keyword )) {
224214 for (final Host c : current ) {
225215 if (c .identityFile == null ) {
226- c .identityFile = LocalFactory . get (dequote (argValue ));
216+ c .identityFile = none (dequote (argValue ));
227217 }
228218 }
229219 }
230220 else if ("IdentityAgent" .equalsIgnoreCase (keyword )) {
231221 for (final Host c : current ) {
232222 if (c .identityAgent == null ) {
233- c .identityAgent = LocalFactory . get (dequote (argValue ));
223+ c .identityAgent = none (dequote (argValue ));
234224 }
235225 }
236226 }
237227 else if ("PreferredAuthentications" .equalsIgnoreCase (keyword )) {
238228 for (final Host c : current ) {
239229 if (c .preferredAuthentications == null ) {
240- c .preferredAuthentications = nows (dequote (argValue ));
230+ c .preferredAuthentications = none ( nows (dequote (argValue ) ));
241231 }
242232 }
243233 }
@@ -256,7 +246,6 @@ else if("BatchMode".equalsIgnoreCase(keyword)) {
256246 }
257247 }
258248 }
259-
260249 return m ;
261250 }
262251
@@ -300,6 +289,13 @@ private static Boolean yesno(final String value) {
300289 return Boolean .FALSE ;
301290 }
302291
292+ private static String none (final String value ) {
293+ if ("none" .equalsIgnoreCase (value )) {
294+ return null ;
295+ }
296+ return value ;
297+ }
298+
303299 /**
304300 * Configuration of one "Host" block in the configuration file.
305301 * <p/>
@@ -315,8 +311,8 @@ public static class Host {
315311 String hostName ;
316312 String proxyJump ;
317313 int port ;
318- Local identityFile ;
319- Local identityAgent ;
314+ String identityFile ;
315+ String identityAgent ;
320316 String user ;
321317 String preferredAuthentications ;
322318 Boolean identitiesOnly ;
@@ -374,14 +370,14 @@ public int getPort() {
374370 * @return path of the private key file to use for authentication; null if the caller should use default
375371 * authentication strategies.
376372 */
377- public Local getIdentityFile () {
373+ public String getIdentityFile () {
378374 return identityFile ;
379375 }
380376
381377 /**
382378 * @return Specifies the UNIX-domain socket used to communicate with the authentication agent.
383379 */
384- public Local getIdentityAgent () {
380+ public String getIdentityAgent () {
385381 return identityAgent ;
386382 }
387383
0 commit comments