public static String getCookie(int displayNumber) throws IOException {
log.debug("Getting cookie for " + displayNumber + " using xauth");
Process process = null;
InputStream in = null;
InputStream err = null;
OutputStream out = null;
// try {
byte[] foo = new byte[16];
ConfigurationLoader.getRND().nextBytes(foo);
byte[] bar = new byte[32];
for (int i = 0; i < 16; i++) {
bar[2 * i] = table[(foo[i] > > > 4) & 0xf];
bar[(2 * i) + 1] = table[(foo[i]) & 0xf];
}
return new String(bar);
/* String cmd = "xauth list :" + displayNumber;
log.debug("Executing " + cmd);
process = Runtime.getRuntime().exec(cmd);
IOStreamConnector connect = new IOStreamConnector(
err = process.getErrorStream(), System.out);
BufferedReader reader = new BufferedReader(
new InputStreamReader(in = process.getInputStream()));
out = process.getOutputStream();
String line = null;
String cookie = null;
while( ( line = reader.readLine() ) != null) {
log.debug(line);
StringTokenizer t = new StringTokenizer(line);
try {
String host = t.nextToken();
String type = t.nextToken();
String value = t.nextToken();
if(cookie == null) {
cookie = value;
log.debug("Using cookie " + cookie);
}
}
catch(Exception e) {
log.error("Unexpected response from xauth.", e);
}
}
return cookie;
}
finally {
IOUtil.closeStream(in);
IOUtil.closeStream(err);
IOUtil.closeStream(out);
}*/
}
|