diff options
author | Björn Hagemeister | 2014-11-11 14:40:18 +0100 |
---|---|---|
committer | Björn Hagemeister | 2014-11-11 14:40:18 +0100 |
commit | e70ee5b59306ea37dd0c72603c61b33b1555def9 (patch) | |
tree | e6f09d76449da54463b9b4fa408b7dfba4b4b7bf /src/main/java/com/btr/proxy/search/desktop/gnome/ProxySchemasGSettingsAccess.java | |
download | proxy-vole-e70ee5b59306ea37dd0c72603c61b33b1555def9.tar.gz proxy-vole-e70ee5b59306ea37dd0c72603c61b33b1555def9.tar.xz proxy-vole-e70ee5b59306ea37dd0c72603c61b33b1555def9.zip |
Added proxy java classes.
Diffstat (limited to 'src/main/java/com/btr/proxy/search/desktop/gnome/ProxySchemasGSettingsAccess.java')
-rw-r--r-- | src/main/java/com/btr/proxy/search/desktop/gnome/ProxySchemasGSettingsAccess.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/java/com/btr/proxy/search/desktop/gnome/ProxySchemasGSettingsAccess.java b/src/main/java/com/btr/proxy/search/desktop/gnome/ProxySchemasGSettingsAccess.java new file mode 100644 index 0000000..6e1b425 --- /dev/null +++ b/src/main/java/com/btr/proxy/search/desktop/gnome/ProxySchemasGSettingsAccess.java @@ -0,0 +1,60 @@ +package com.btr.proxy.search.desktop.gnome; + +import java.io.Closeable; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Map; + +public class ProxySchemasGSettingsAccess { + + private static void closeStream(Closeable c) { + try { + c.close(); + } catch (IOException e) { + // Ignore cleanup errors + } + } + + static void copy(InputStream source, OutputStream dest) throws IOException { + try { + byte[] buffer = new byte[1024]; + int read = 0; + while (read >= 0) { + dest.write(buffer, 0, read); + read = source.read(buffer); + } + dest.flush(); + } finally { + closeStream(source); + closeStream(dest); + } + } + + static { + String arch = System.getProperty("os.arch"); + if (arch.equals("x86_64") || arch.equals("x64") || arch.equals("x86-64")) { + arch = "amd64"; + } + if (arch.equals("i386") || arch.equals("i686")) { + arch = "x86"; + } + String libName = "gsettings-" + arch + ".so"; + File libFile; + try { + InputStream source = ProxySchemasGSettingsAccess.class.getResourceAsStream("/lib/" + libName); + libFile = File.createTempFile("gsettings", ".so"); + libFile.deleteOnExit(); + FileOutputStream destination = new FileOutputStream(libFile); + copy(source, destination); + } catch (IOException e) { + throw new RuntimeException(e); + } + System.load(libFile.getAbsolutePath()); + } + + public static native Map<String, Map<String, Object>> getValueByKeyBySchema(); + +} |