1 package org.splat.launcher;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.io.InputStreamReader;
7 import java.io.StringWriter;
10 public class WindowsRegistry {
12 static class StreamReader extends Thread {
13 // ----------------------------------------
14 private InputStream is;
15 private StringWriter sw= new StringWriter();;
17 public StreamReader(InputStream is) {
23 while ((c = is.read()) != -1) sw.write(c);
25 catch (IOException e) {
28 public String getResult() {
33 public static final String readValue (String location, String key) {
34 // ------------------------------------------------------------------
36 // Run reg query, then read output with StreamReader (internal class)
37 if (key.length() == 0) key = "/ve"; // Looking for the default key
38 else key = "/v " + key;
40 Process process = Runtime.getRuntime().exec("reg query " + location + " " + key);
41 BufferedReader buffer = new BufferedReader( new InputStreamReader(process.getInputStream()) );
43 // Output has the following format:
44 // \n<Version information>\n\n<key>\t<registry type>\t<value>
46 String value = "REG_SZ";
47 while ((output = buffer.readLine()) != null) {
48 if (output.contains(value)) {
49 int index = output.indexOf(value) + value.length() + 1;
50 return output.substring(index).trim();
54 // StreamReader reader = new StreamReader(process.getInputStream());
59 // String output = reader.getResult();
61 // Output has the following format:
62 // \n<Version information>\n\n<key>\t<registry type>\t<value>
63 // if( ! output.contains("\t") ){
66 // Parse out the value
67 // String[] parsed = output.split("\t");
68 // return parsed[parsed.length-1];