/** * Return a utf-8 encoded byte array from data ignoring the VM default data set. * @param data * @return utf-8 encoded byte array */ public static byte[] toBytes(String data) { if (data == null) return null; try { return data.getBytes(CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw new MRuntimeException(e); // this should never happen!!! } }
/** * Return a utf-8 decoded string from the data ignoring the VM default char set. * @param data * @return utf-8 decoded string */ public static String byteToString(byte[] data) { if (data == null) return null; try { return new String(data,CHARSET_UTF_8); } catch (UnsupportedEncodingException e) { throw new MRuntimeException(e); // this should never happen!!! } }
@Override public Object getValue() { try { return getProperty(key); } catch (Throwable e) { throw new MRuntimeException(e); } }
@Override public void update(Observable o, Object arg) { try { doit(); } catch (Exception e) { throw new MRuntimeException(e); } }
/** * <p>isPrimary.</p> * * @return a boolean. */ public boolean isPrimary() { try { return config.getName().equals("primary"); } catch (MException e) { throw new MRuntimeException(e); } }
/** * The task of the connector, e.g. data enabled or visible. * * @return a {@link java.lang.String} object. */ public String getTaskName() { try { return config.getName(); } catch (MException e) { throw new MRuntimeException(e); } }
@Override public void execute(StringBuilder out, Map<String, Object> attributes) { try { for (ParsingPart p : parts) { p.execute(out, attributes); } } catch (MException e) { throw new MRuntimeException(e); } }
/** {@inheritDoc} */ @Override public String toString() { try { return config.getName() + "=n:" + name + ",t:" + type + ",fw:" + isFullWidth + ",ti:" + isTitleInside; } catch (MException e) { throw new MRuntimeException(e); } }
public static String decodeToString(String encoded) { try { return new String(decode(encoded),"utf-8") ; } catch (UnsupportedEncodingException e) { throw new MRuntimeException(encoded,e); } }
/** * <p>isCancel.</p> * * @return a boolean. */ public boolean isCancel() { try{ return config.getName().equals("cancel"); } catch (MException e) { throw new MRuntimeException(e); } }
/** {@inheritDoc} */ @Override public void setPropertyData(String name, Object value) { if (model != null) { @SuppressWarnings("unchecked") PojoAttribute<Object> attr = model.getAttribute(name); if (attr == null) throw new MRuntimeException("attribute not found",name); try { attr.set(pojo,value); } catch (IOException e) { throw new MRuntimeException(name,e); } } }
@Override public void execute(StringBuilder out, Map<String, Object> attributes) { try { out.append(name).append("("); boolean first = true; for (ParsingPart p : parts) { if (!first) out.append(","); p.execute(out, attributes); first = false; } out.append(")"); } catch (MException e) { throw new MRuntimeException(e); } }
/** * <p>getNames.</p> * * @return an array of {@link java.lang.String} objects. */ public String[] getNames() { LinkedList<String> out = new LinkedList<String>(); for (IConfig c : config.getNodes()) { try { out.add(c.getName()); } catch (MException e) { throw new MRuntimeException(e); } } return out.toArray(new String[out.size()]); }
@Override public void doPreCreate(DbConnection con) { try { preChecksum(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException | ReadOnlyException e) { throw new MRuntimeException(e); } super.doPreCreate(con); }
@Override public void doPreSave(DbConnection con) { try { preChecksum(); } catch (NoSuchAlgorithmException | UnsupportedEncodingException | ReadOnlyException e) { throw new MRuntimeException(e); } super.doPreSave(con); }
@Override public PNodeInfo next() { if (res == null) return null; try { PNodeInfo out = newPNode(res); hasNext = res.next(); return out; } catch (Exception e) { throw new MRuntimeException(e); } } }
@Override public PCaseInfo next() { if (res == null) return null; try { PCaseInfo out = newPCase(res); hasNext = res.next(); return out; } catch (Exception e) { throw new MRuntimeException(e); } } }
MVault vault = MVaultUtil.loadDefault(); VaultEntry entry = vault.getEntry(UUID.fromString(keyId)); if (entry == null) throw new MRuntimeException("key not found",keyId); try { AsyncKey key = MVaultUtil.adaptTo(entry, AsyncKey.class); return MCrypt.decodeWithSalt(key, in); } catch (Exception e) { throw new MRuntimeException(e); throw new MRuntimeException("try to encode a dummy password"); if (in.startsWith(PREFIX_SPECIAL1)) { StringBuilder out = new StringBuilder();
protected String getExtracted(String key, String def,int level) { if (level > 10) return def; String value = getString(key,null); if (value == null) return def; if (value.indexOf('$') < 0) return value; synchronized (this) { if (compiler == null) { compiler = new ConfigStringCompiler(); compiledCache = new HashMap<String, CompiledString>(); } CompiledString cached = compiledCache.get(key); if (cached == null) { cached = compiler.compileString(value); compiledCache.put(key, cached); } try { return cached.execute(new ConfigMap(level,this)); } catch (MException e) { throw new MRuntimeException(key,e); } } }
public static String encode(METHOD method, String in, String secret) { if (in == null) return null; if (isEncoded(in)) return in; switch (method) { case DUMMY: // empty dummy password return PREFIX_DUMMY; case ROT13: return PREFIX_ROT13 + Rot13.encode(in); case RSA: MVault vault = MVaultUtil.loadDefault(); VaultEntry entry = vault.getEntry(UUID.fromString(secret)); if (entry == null) throw new MRuntimeException("key not found",secret); try { AsyncKey key = MVaultUtil.adaptTo(entry, AsyncKey.class); return PREFIX_RSA + entry.getId() + ":" + MCrypt.encodeWithSalt(key, in); } catch (Exception e) { throw new MRuntimeException(e); } case HASH_MD5: return PREFIX_HASH_MD5 + encodePasswordMD5(secret); default: throw new MRuntimeException("unknown encode method",method); } }