From eb2b45a016704bea63eb25cf7b91438f46a09ac2 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 27 Jun 2013 11:48:42 +0200 Subject: fix get parentName in java version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/ArgParser.java | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/ArgParser.java b/src/ArgParser.java index 6983f19..efb5f5d 100644 --- a/src/ArgParser.java +++ b/src/ArgParser.java @@ -469,10 +469,13 @@ public class ArgParser InputStream is = null; try { is = new FileInputStream(new File("/proc/" + pid + "/status")); - byte[] data = new byte[is.available()]; - int off = 0; - while (off != data.length) - off += is.read(data, off, data.length - off); + byte[] data = new byte[1 << 12]; + int off = 0, read = 1; + while (read > 0) + { if (off == data.length) + System.arraycopy(data, 0, data = new byte[data.length << 1], 0, off); + off += read = is.read(data, off, data.length - off); + } String[] lines = (new String(data, "UTF-8")).split("\n"); for (String line : lines) { if (line.startsWith("PPid:")) @@ -496,11 +499,14 @@ public class ArgParser InputStream is = null; try { is = new FileInputStream(new File("/proc/" + pid + "/cmdline")); - byte[] data = new byte[is.available()]; - int off = 0; - while (off != data.length) - off += is.read(data, off, data.length - off); - String[] cmdline = new String(data, 0, off - 1, "UTF-8").split("\0"); + byte[] data = new byte[128]; + int off = 0, read = 1; + while (read > 0) + { if (off == data.length) + System.arraycopy(data, 0, data = new byte[data.length << 1], 0, off); + off += read = is.read(data, off, data.length - off); + } + String[] cmdline = new String(data, 0, off, "UTF-8").split("\0"); if (hasInterpretor == false) { String rc = cmdline[0]; return rc.length() == 0 ? null : rc; -- cgit v1.2.3-70-g09d2