From 6200efbbfd3bb7f7948a8cf725398989864b1f2e Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sun, 16 Sep 2007 21:55:48 +0000 Subject: [PATCH] revive /etc/rpc parser --- bindings/java/src/org/hyperic/sigar/RPC.java | 41 +++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/bindings/java/src/org/hyperic/sigar/RPC.java b/bindings/java/src/org/hyperic/sigar/RPC.java index d27afe9f..5613487e 100644 --- a/bindings/java/src/org/hyperic/sigar/RPC.java +++ b/bindings/java/src/org/hyperic/sigar/RPC.java @@ -18,9 +18,14 @@ package org.hyperic.sigar; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.StringTokenizer; public class RPC { @@ -56,13 +61,37 @@ public class RPC { private static void parse(String fileName) { programs = new HashMap(); - /* XXX - NetServices.parse("/etc/rpc", new NetServices.EntryReader() { - public void process(String program, String num, List aliases) { - programs.put(program, num); + File file = new File(fileName); + if (!file.exists()) { + return; + } + BufferedReader reader = null; + + try { + reader = new BufferedReader(new FileReader(file)); + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + if ((line.length() == 0) || (line.charAt(0) == '#')) { + continue; + } + StringTokenizer st = new StringTokenizer(line, " \t"); + if (st.countTokens() < 2) { + continue; + } + String name = st.nextToken().trim(); + String num = st.nextToken().trim(); + programs.put(name, num); } - }); - */ + } catch (IOException e) { + return; + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { } + } + } } /**