try harder to get a number out of the pid file, trim whitespace, etc.

This commit is contained in:
Doug MacEachern 2006-03-18 02:26:42 +00:00
parent 4c4a13570b
commit 4c7b451f69
1 changed files with 18 additions and 2 deletions

View File

@ -36,15 +36,31 @@ public class PidFileQuery extends PidQuery {
try {
BufferedReader in =
new BufferedReader(new FileReader(this.file));
line = in.readLine();
while ((line = in.readLine()) != null) {
line = line.trim();
if (line.length() != 0) {
break;
}
}
} catch (FileNotFoundException e) {
throw new SigarException(e.getMessage());
} catch (IOException e) {
throw new SigarException(e.getMessage());
}
int len = line.length();
StringBuffer number = new StringBuffer(len);
char[] chars = line.toCharArray();
for (int i=0; i<len; i++) {
char c = chars[i];
if (!Character.isDigit(c)) {
break;
}
number.append(c);
}
try {
this.pid = Long.parseLong(line);
this.pid = Long.parseLong(number.toString());
} catch (NumberFormatException e) {
throw new SigarException("Not a number: " + line);
}