Package de.sosd.mediaserver

Source Code of de.sosd.mediaserver.PsTest

package de.sosd.mediaserver;

import java.util.ArrayList;
import java.util.List;

import de.sosd.mediaserver.bean.ProcessToWatch;


public class PsTest {

  /**
   * @param args
   */
  public static void main(final String[] args) {
    new PsTest().run();
  }
 
  public void run() {
    final String[] lines = new String[]{"  PID|COMMAND","    1|/sbin/init","     2|[kthreadd]","  868|/sbin/getty -8 38400 tty4"};
    final List<ProcessToWatch> result = new ArrayList<ProcessToWatch>();
    boolean first = true;
    int pid_col = 0;
    int cmd_col = 0
    for (final String line : lines) {
      if (first) {
        final String[] columns = line.split("\\|");
        int idx = 0;;
        for (final String col : columns) {
          if (col.toLowerCase().contains("pid")) {
            pid_col = idx;
          }
          if (col.toLowerCase().contains("command")) {
            cmd_col = idx;
          }
          idx++;
        }
       
        first = false;
      } else {
        final String[] columns = line.split("\\|");
        result.add(
            new ProcessToWatch(columns[pid_col].replaceAll(" ", ""), columns[cmd_col])
        );
      }
     
     
    }

    final StringBuilder sb = new StringBuilder();
    for (final ProcessToWatch proc : result) {
      sb.append(proc.toString());
      sb.append("\n");
    }
    System.out.println(sb);
  }

}
TOP

Related Classes of de.sosd.mediaserver.PsTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.