+ /**
+ * Return the version of the program if it follows the VERSION convention
+ * (i.e., if it has a file called VERSION containing the version as a
+ * {@link String} on its binary root).
+ *
+ * @return the version, or NULL
+ */
+ public static String getVersion() {
+ String version = null;
+
+ InputStream in = openResource("VERSION");
+ if (in != null) {
+ try {
+ ByteArrayOutputStream ba = new ByteArrayOutputStream();
+ write(in, ba);
+ in.close();
+
+ version = ba.toString("UTF-8");
+ } catch (IOException e) {
+ }
+ }
+
+ return version;
+ }
+
+ /**
+ * Open the given /-separated resource (from the binary root).
+ *
+ * @param name
+ * the resource name
+ *
+ * @return the opened resource if found, NLL if not
+ */
+ public static InputStream openResource(String name) {
+ ClassLoader loader = IOUtils.class.getClassLoader();
+ if (loader == null) {
+ loader = ClassLoader.getSystemClassLoader();
+ }
+
+ return loader.getResourceAsStream(name);
+ }
+