@@ -210,26 +210,31 @@ private static void printActionResult(String action, Object result, PrintWriter
210210 if (result == null ) {
211211 writer .println ((Object ) null );
212212 } else if (result instanceof DnsCacheEntry ) {
213- final SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
214- DnsCacheEntry entry = (DnsCacheEntry ) result ;
215- writer .printf ("%s %s %s%n" , entry .getHost (), join (Arrays .asList (entry .getIps ()), "," ), dateFormat .format (entry .getExpiration ()));
213+ printDnsCacheEntry ((DnsCacheEntry ) result , writer );
216214 } else if (result instanceof DnsCache ) {
217- final SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
218215 DnsCache dnsCache = (DnsCache ) result ;
219216
220- writer .println ("Dns cache:" );
221- for (DnsCacheEntry entry : dnsCache .getCache ()) {
222- writer .printf (" %s %s %s%n" , entry .getHost (), join (Arrays .asList (entry .getIps ()), "," ), dateFormat .format (entry .getExpiration ()));
223- }
224- writer .println ("Dns negative cache: " );
225- for (DnsCacheEntry entry : dnsCache .getNegativeCache ()) {
226- writer .printf (" %s %s %s%n" , entry .getHost (), join (Arrays .asList (entry .getIps ()), "," ), dateFormat .format (entry .getExpiration ()));
227- }
217+ printDnsCacheEntryList ("Dns cache: " , dnsCache .getCache (), writer );
218+
219+ writer .println ();
220+ printDnsCacheEntryList ("Dns negative cache: " , dnsCache .getNegativeCache (), writer );
228221 } else {
229222 writer .println (result );
230223 }
231224 }
232225
226+ private static void printDnsCacheEntryList (String msg , List <DnsCacheEntry > dnsCacheEntries , PrintWriter writer ) {
227+ writer .println (msg );
228+ for (DnsCacheEntry entry : dnsCacheEntries ) {
229+ printDnsCacheEntry (entry , writer );
230+ }
231+ }
232+
233+ private static void printDnsCacheEntry (DnsCacheEntry entry , PrintWriter writer ) {
234+ final SimpleDateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd'T'HH:mm:ss.SSSZ" );
235+ writer .printf (" %s %s %s%n" , entry .getHost (), join (Arrays .asList (entry .getIps ()), "," ), dateFormat .format (entry .getExpiration ()));
236+ }
237+
233238 private static volatile Map <String , Method > action2Method ;
234239 private static volatile ArrayList <String > actionList ;
235240
0 commit comments