package net.hyperic.sigar.cmd;

import java.util.Date;
import java.text.SimpleDateFormat;

import net.hyperic.sigar.SigarException;

public class Who extends SigarCommandBase {

    public Who(Shell shell) {
        super(shell);
    }

    public Who() {
        super();
    }

    public String getUsageShort() {
        return "Show who is logged on";
    }

    private String getTime(long time) {
        if (time == 0) {
            return "unknown";
        }
        String fmt = "MMM dd HH:mm";
        return new SimpleDateFormat(fmt).format(new Date(time));
    }

    public void output(String[] args) throws SigarException {
        net.hyperic.sigar.Who[] who = this.sigar.getWhoList();
        for (int i=0; i<who.length; i++) {
            String host = who[i].getHost();
            if (host.length() != 0) {
                host = "(" + host + ")";
            }
            println(who[i].getUser() + "\t" +
                    who[i].getDevice() + "\t" +
                    getTime(who[i].getTime() * 1000) + "\t" +
                    host);
        }
    }

    public static void main(String[] args) throws Exception {
        new Who().processCommand(args);
    }
}

@@ -896,11 +896,41 @@
 rint
-ln(
+f(new String%5B%5D %7B%0A                
 who%5B
@@ -941,30 +941,18 @@
 etUser()
- + %22%5Ct%22 +%0A    
+,%0A
         
@@ -977,30 +977,18 @@
 Device()
- + %22%5Ct%22 +%0A    
+,%0A
         
@@ -1031,18 +1031,31 @@
 000)
- + %22%5Ct%22 +%0A
+,%0A                host 
     
@@ -1053,32 +1053,33 @@
 host            
+%0A
          host);%0A
@@ -1071,20 +1071,20 @@
         
-host
+   %7D
 );%0A     

use printf