package org.pEp.jniadapter; import java.util.ArrayList; import java.util.Vector; import java.io.UnsupportedEncodingException; import java.text.Normalizer; abstract class AbstractEngine implements AutoCloseable { static { System.loadLibrary("pEpJNI"); } private native void init() throws pEpException; private native void release(); private long handle; final protected long getHandle() { return handle; } public AbstractEngine() throws pEpException { init(); } final public void close() { release(); } private long keyserverThread; private long queueThread; public native void startKeyserverLookup(); public native void stopKeyserverLookup(); public static byte[] toUTF8(String str) { if (str == null) return null; try { String _str = Normalizer.normalize(str, Normalizer.Form.NFC); byte _buf[] = _str.getBytes("UTF-8"); // F*ck you, Java ! byte _cpy[] = new byte[_buf.length]; System.arraycopy(_buf,0,_cpy,0,_buf.length); return _cpy; } catch (UnsupportedEncodingException e) { assert false; return new byte[0]; } } public static Vector toUTF8(Vector list) { if (list == null) return null; Vector result = new Vector(list.size()); for (int i=0; i toUTF8(Pair pair) { if (pair == null) return null; Pair result = new Pair(); result.first = toUTF8(pair.first); result.second = toUTF8(pair.second); return result; } public static ArrayList> toUTF8(ArrayList> list) { if (list == null) return null; ArrayList> result = new ArrayList>(list.size()); for (int i=0; i toUTF16(Vector list) { if (list == null) return null; Vector result = new Vector(list.size()); for (int i=0; i toUTF16(Pair pair) { if (pair == null) return null; Pair result = new Pair(); result.first = toUTF16(pair.first); result.second = toUTF16(pair.second); return result; } public static ArrayList> toUTF16(ArrayList> list) { if (list == null) return null; ArrayList> result = new ArrayList>(list.size()); for (int i=0; i