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;
9 public class WindowsRegistry {
11 private static final String REG_SZ = "REG_SZ";
13 static class StreamReader extends Thread { //RKV: NOPMD: TODO: Clarify the purpose of this class and then fix
14 private transient final InputStream _is;
15 private transient final StringWriter _sw = new StringWriter();;
17 public StreamReader(final InputStream is) {
30 } catch (IOException e) {
31 e.printStackTrace(); // RKV: NOPMD: TODO: try to use logger
35 public String getResult() {
36 return _sw.toString();
40 public static final String readValue(final String location, final String key) {
43 // Run reg query, then read output with StreamReader (internal class)
45 if (key.length() == 0) {
46 aKey = "/ve"; // Looking for the default key
51 Process process = Runtime.getRuntime().exec(
52 "reg query " + location + " " + aKey);
53 BufferedReader buffer = new BufferedReader(new InputStreamReader(
54 process.getInputStream()));
56 // Output has the following format:
57 // \n<Version information>\n\n<key>\t<registry type>\t<value>
58 String output = buffer.readLine();
59 while (output != null) {
60 if (output.contains(REG_SZ)) {
61 int index = output.indexOf(REG_SZ) + REG_SZ.length() + 1;
62 res = output.substring(index).trim();
65 output = buffer.readLine();
67 // StreamReader reader = new StreamReader(process.getInputStream());
72 // String output = reader.getResult();
74 // Output has the following format:
75 // \n<Version information>\n\n<key>\t<registry type>\t<value>
76 // if( ! output.contains("\t") ){
79 // Parse out the value
80 // String[] parsed = output.split("\t");
81 // return parsed[parsed.length-1];
82 } catch (Exception e) {
83 e.printStackTrace(); // RKV: NOPMD: TODO: try to use logger