From 924c46fdbfde8dc6737c087e27b10d8f0f4074fc Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 13 Jul 2005 00:17:24 +0000 Subject: [PATCH] convert Route to shell commmand and format the output --- .../java/src/net/hyperic/sigar/cmd/Route.java | 65 ++++++++++++++----- .../java/src/net/hyperic/sigar/cmd/Shell.java | 1 + 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/cmd/Route.java b/bindings/java/src/net/hyperic/sigar/cmd/Route.java index 8e866b7f..ed24df2b 100644 --- a/bindings/java/src/net/hyperic/sigar/cmd/Route.java +++ b/bindings/java/src/net/hyperic/sigar/cmd/Route.java @@ -1,10 +1,36 @@ package net.hyperic.sigar.cmd; -import net.hyperic.sigar.Sigar; +import java.util.ArrayList; + import net.hyperic.sigar.NetFlags; import net.hyperic.sigar.NetRoute; +import net.hyperic.sigar.Sigar; +import net.hyperic.sigar.SigarException; -public class Route { +public class Route extends SigarCommandBase { + private static final String OUTPUT_FORMAT = + "%-15s %-15s %-15s %-5s %-6s %-3s %-s"; + + //like df -h -a + private static final String[] HEADER = new String[] { + "Destination", + "Gateway", + "Genmask", + "Flags", + "Metric", + "Ref", + "Iface" + }; + + public Route(Shell shell) { + super(shell); + setOutputFormat(OUTPUT_FORMAT); + } + + public Route() { + super(); + setOutputFormat(OUTPUT_FORMAT); + } private static String flags(long flags) { StringBuffer sb = new StringBuffer(); @@ -17,26 +43,33 @@ public class Route { return sb.toString(); } + public String getUsageShort() { + return "Kernel IP routing table"; + } + //netstat -r - public static void main(String[] args) throws Exception { - Sigar sigar = new Sigar(); + public void output(String[] args) throws SigarException { + NetRoute[] routes = this.sigar.getNetRouteList(); - NetRoute[] routes = sigar.getNetRouteList(); - - System.out.println("Destination\tGateway\tGenmask" + - "\tFlags\tMSS\tWindow\tirtt\tIface"); + printf(HEADER); for (int i=0; i