public static boolean equals(Object[] nr1, Object[] nr2) { if (nr1 == null && nr2 == null) return true; if (nr1 == null || nr2 == null) return false; if (nr1.length != nr2.length) return false; for (int i = 0; i < nr1.length; i++) if (!MSystem.equals(nr1[i], nr2[i])) return false; return true; }
@Override public String toString() { return MSystem.toString(this, publicExponent, modulus); } }
@Override public String getName() { return MSystem.getObjectId(this); } }
/** * Get the identification of the application host:pid * * @return host:pid */ public static String getAppIdent() { return getHostname() + ":" + getPid(); }
public static IConfig createFromResource(Class<?> owner, String fileName) throws MException { try { URL url = MSystem.locateResource(owner, fileName); if (fileName.endsWith(".xml")) return new XmlConfigFile(url.openStream()); if (fileName.endsWith(".properties")) return new PropertiesConfigFile(url.openStream()); if (fileName.endsWith(".json")) return new JsonConfigFile(url.openStream()); } catch (Throwable t) { throw new MException(fileName,t); } throw new NotFoundException(fileName); }
public static String toResourceName(Object owner) { if (owner == null) return null; if (owner instanceof String) return (String)owner; return MSystem.getClassName(owner).replace('.', '/'); }
@Override public String hostname() { return MSystem.getHostname(); }
@SuppressWarnings("unchecked") @Override public void inject(Object object, Base base) { IgnoreBind classIgnoreBind = object.getClass().getAnnotation(IgnoreBind.class); // to save time use IgnoreBind ... if (classIgnoreBind != null) return; Bind classBind = MSystem.findAnnotation(object.getClass(), Bind.class); if (classBind == null) return; PojoModel model = new PojoParser().parse(object, new AttributesStrategy(false, false, null, new Class[] {Bind.class})).filter(new DefaultFilter(true,true,false,true,false)).getModel(); for (PojoAttribute<Object> attr : model) { try { Bind bind = attr.getAnnotation(Bind.class); if (bind != null) { Class<?> ifc = attr.getType(); if (bind.name() != Class.class) ifc = bind.name(); Object obj = base.lookup(ifc); attr.set(object, obj); } } catch (Throwable e) { e.printStackTrace(); //TODO } } }
public static synchronized List<String> getPasswordList() { if (passwordList != null) return passwordList; try { // from https://github.com/danielmiessler/SecLists - Please respect MIT License, is compatible with this Apache 2.0 license URL res = MSystem.locateResource(MValidator.class, "10-million-password-list-top-100000.txt"); InputStream is = res.openStream(); final LinkedList<String> list = new LinkedList<>(); MFile.readLines(is, new Observer() { @Override public void update(Observable o, Object arg) { String v = (String)arg; // to lower case and trimm v = v.trim().toLowerCase(); if (v.length() > 0) list.add(v); } }); is.close(); passwordList = Collections.unmodifiableList(list); } catch (Throwable t) { MLogUtil.log().i(MValidator.class,t); } return passwordList; }
/** * Returns the id of the object like the original toString() will do * * @param o * @return the id */ public static String getObjectId(Object o) { if (o == null) return "null"; String name = o.getClass().getName(); if (name == null) name = getClassName(o); return name + "@" + Integer.toHexString(System.identityHashCode(o)); }
public ServerIdent() { String persistence = MApi.getCfg(ServerIdent.class).getString("persistence", MApi.getFile(SCOPE.ETC, ServerIdent.class.getCanonicalName() + ".txt").getAbsolutePath() ); File file = new File(persistence); String def = ""; if (file.exists() && file.isFile()) def = MFile.readFile(file).trim(); else { def = MSystem.getHostname() + "." + String.valueOf(MMath.toBasis36((long)(Math.random()*36*36*36*36), 4 )); MFile.writeFile(file, def); } def = MFile.normalize(def); ident = new CfgString(ServerIdent.class, "ident", def ); }
DbTable table = MSystem.findAnnotation(clazz, DbTable.class); if (tableName != null) { name = tableName;
@Override public String toString() { return MSystem.toString(this, operationPath, successful, msg, nextOperation ); // result ? } public long getReturnCode() {
@Override public boolean equals(Integer p1, Integer p2) { return MSystem.equals(p1, p2); }
properties = new Properties(); try { URL m_url = locateResource(owner, propertyFile); if (m_url == null) { log.w("Properties file not found", propertyFile);
public synchronized String getObjectId(DbTransactionable owner) { String id = objectIdList.get(owner); if (id == null) { id = MSystem.getObjectId(owner); objectIdList.put(owner, id); } return id; }
@Override public String getName() { if (name != null) return name; if (task instanceof Named) return ((Named)task).getName(); return MSystem.getClassName(task.getClass()); };
/** {@inheritDoc} */ @Override public String toString() { return MSystem.toString(this, config); }
mhusConfigUrl = MSystem.locateResource(this, getApplicationConfigName()); } catch (IOException e) { log.i(getApplicationConfigName(),e);