From: <ga...@us...> - 2012-12-21 15:07:40
|
Revision: 5940 http://jnode.svn.sourceforge.net/jnode/?rev=5940&view=rev Author: galatnm Date: 2012-12-21 15:07:28 +0000 (Fri, 21 Dec 2012) Log Message: ----------- NET : Improve netstat command output. Modified Paths: -------------- trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java Modified: trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java =================================================================== --- trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java 2012-12-21 14:21:00 UTC (rev 5939) +++ trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java 2012-12-21 15:07:28 UTC (rev 5940) @@ -36,7 +36,7 @@ public class NetstatCommand extends AbstractCommand { private static final String help_super = "Print statistics for all network devices"; - private static final String fmt_stat = "%s: ID %s"; + private static final String fmt_stat = "%s: ID %s\n"; private static final String str_none = "none"; public NetstatCommand() { @@ -60,42 +60,36 @@ private void showStats(PrintWriter out, NetworkLayer nl, int maxWidth) throws NetworkException { out.format(fmt_stat, nl.getName(), nl.getProtocolID()); - final String prefix = " "; - out.print(prefix); - showStats(out, nl.getStatistics(), maxWidth - prefix.length(), prefix); + padOutput(out, 4); + showStats(out, nl.getStatistics(), 4); for (TransportLayer tl : nl.getTransportLayers()) { - out.print(prefix); + padOutput(out, 4); out.format(fmt_stat, tl.getName(), tl.getProtocolID()); - final String prefix2 = prefix + prefix; - out.print(prefix2); - showStats(out, tl.getStatistics(), maxWidth - prefix2.length(), prefix2); + showStats(out, tl.getStatistics(),8); } out.println(); } - private void showStats(PrintWriter out, Statistics stat, int maxWidth, String prefix) + private void showStats(PrintWriter out, Statistics stat, int padSize) throws NetworkException { - final Statistic[] list = stat.getStatistics(); - if (list.length == 0) { + padOutput(out, padSize); + final Statistic[] statistics = stat.getStatistics(); + if (statistics.length == 0) { out.print(str_none); } else { - int width = 0; - for (int i = 0; i < list.length; i++) { - final Statistic st = list[i]; - String msg = st.getName() + ' ' + st.getValue(); - if (i + 1 < list.length) { - msg = msg + ", "; - } - if (width + msg.length() > maxWidth) { - out.println(); - out.print(prefix); - width = 0; - } - out.print(msg); - width += msg.length(); - } + StringBuffer buffer = new StringBuffer(); + for(Statistic statistic : statistics){ + buffer.append(statistic.getName()).append(' ').append(statistic.getValue()).append("\n"); + } + out.print(buffer.toString()); } out.println(); } + + private void padOutput(PrintWriter out, int size) { + for(int i = 0; i < size; i++){ + out.print(" "); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-12-21 15:17:32
|
Revision: 5941 http://jnode.svn.sourceforge.net/jnode/?rev=5941&view=rev Author: galatnm Date: 2012-12-21 15:17:21 +0000 (Fri, 21 Dec 2012) Log Message: ----------- NET : fix padding for netstat command output. Modified Paths: -------------- trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java Modified: trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java =================================================================== --- trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java 2012-12-21 15:07:28 UTC (rev 5940) +++ trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java 2012-12-21 15:17:21 UTC (rev 5941) @@ -60,7 +60,6 @@ private void showStats(PrintWriter out, NetworkLayer nl, int maxWidth) throws NetworkException { out.format(fmt_stat, nl.getName(), nl.getProtocolID()); - padOutput(out, 4); showStats(out, nl.getStatistics(), 4); for (TransportLayer tl : nl.getTransportLayers()) { padOutput(out, 4); @@ -72,20 +71,27 @@ private void showStats(PrintWriter out, Statistics stat, int padSize) throws NetworkException { - padOutput(out, padSize); final Statistic[] statistics = stat.getStatistics(); if (statistics.length == 0) { out.print(str_none); } else { StringBuffer buffer = new StringBuffer(); for(Statistic statistic : statistics){ - buffer.append(statistic.getName()).append(' ').append(statistic.getValue()).append("\n"); + buffer.append(paddedString(padSize)).append(statistic.getName()).append(' ').append(statistic.getValue()).append("\n"); } out.print(buffer.toString()); } out.println(); } + private String paddedString(int padSize) { + String result = ""; + for(int i = 0; i < padSize; i++){ + result += " "; + } + return result; + } + private void padOutput(PrintWriter out, int size) { for(int i = 0; i < size; i++){ out.print(" "); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-12-21 15:21:25
|
Revision: 5942 http://jnode.svn.sourceforge.net/jnode/?rev=5942&view=rev Author: galatnm Date: 2012-12-21 15:21:18 +0000 (Fri, 21 Dec 2012) Log Message: ----------- NET : fix padding when no statistics. Modified Paths: -------------- trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java Modified: trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java =================================================================== --- trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java 2012-12-21 15:17:21 UTC (rev 5941) +++ trunk/cli/src/commands/org/jnode/command/net/NetstatCommand.java 2012-12-21 15:21:18 UTC (rev 5942) @@ -73,6 +73,7 @@ throws NetworkException { final Statistic[] statistics = stat.getStatistics(); if (statistics.length == 0) { + padOutput(out, padSize); out.print(str_none); } else { StringBuffer buffer = new StringBuffer(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |