Ein Beispiel für Ajax und Ping; sollte analog auch für PDF gehen
public void Ping(String IP, ObjGlob GL) {
try {
Vector pv = pingWin(IP, 4, 2000);
String CDA = "<![CDATA[";
String CDE = "]]>";
StringBuffer xml = new StringBuffer();
xml.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>");
xml.append("<response>");
xml.append("<document>");
xml.append("<docount>" + CDA + pv.size() + CDE + "</docount>");
for (int i = 0; i < pv.size(); i++) {
xml.append("<ping" + i + ">" + CDA + (String) pv.get(i) + CDE + "</ping" + i + ">");
}
xml.append("</document>");
xml.append("</response>");
GL.pw.println("Content-Type: text/xml; charset=\"ISO-8859-1\"");
GL.pw.println(xml);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private static Vector ping(String[] cmd) throws IOException, InterruptedException {
Process ping = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader(new InputStreamReader(ping.getInputStream(), "Cp850"));
String line = "";
Vector v = new Vector();
while ((line = input.readLine()) != null) {
if (line.indexOf("Pakete:") >= 0) {
v.addElement(line + "<br>");
}
if (line.indexOf("Minimum") >= 0) {
v.addElement(line + "<br>");
}
if (line.indexOf("Antwort") >= 0) {
v.addElement(line + "<br>");
}
if (line.indexOf("Zeit\u00fcberschreitung") >= 0) {
v.addElement(line + "<br>");
System.out.println(line.trim());
}
}
input.close();
// return ping.waitFor() == 0;
return (v);
}
private static Vector pingWin(String target, int count, long timeout) throws IOException, InterruptedException {
String[] cmd = {};
if (timeout == 0) {
cmd = new String[4];
} else {
cmd = new String[6];
cmd[3] = "-w";
cmd[4] = Long.toString(timeout);
}
cmd[0] = "ping";
cmd[1] = "-n";
cmd[2] = Integer.toString(count);
cmd[cmd.length - 1] = target;
Vector v = ping(cmd);
return (v);
}