private String fetchDBName(String property) { // internally spring use eureka VIP as service id (instead appName), so potentially we can have problems with invalid hostnames String dbname = StringUtils.before(property, '.'); Assert.isTrue(dbname != null, MYSQL_SERVICE_ID + "property doesn't match pattern dbname.dbserver, property is '" + property + "'"); // many db does not allow '-', but allow '_' which is forbidden in hostnames dbname = dbname.replace('-', '_'); return dbname; }
private static String strip(String address) { return StringUtils.beforeOr(address, '%', address::toString); }
/** * Test that specified codePoint is an ASCII letter, digit or hyphen '-', '_', ':', '.'. <p/> * It common matcher that limit alphabet acceptable for our system IDs. * @param cp codePoint * @return true for specified chars */ public static boolean isId(int cp) { return isAz09(cp) || cp == '-' || cp == '_' || cp == ':' || cp == '.'; }
@Override public MailTemplate getTemplate(String uri) { String path = StringUtils.after(uri, ':'); final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); // possibly we need to escape some chars like '..' ? final String templateName = this.prefix + "/" + path; MailTemplateImpl.Builder builder = Resources.load(classLoader, templateName + ".json", descriptorLoader); //in future we may implement MailPartTemplate which contains reference to another resource MailPartTemplate bodySource = builder.getBodySource(); if(bodySource == null) { MailPartTemplate templatePart = Resources.load(classLoader, templateName + suffix, templatePartLoader); builder.setBodySource(templatePart); } return builder.build(); } }
/** * Is a <code>match(str, StringUtils::isAz09);</code>. * @param str string * @return true if string match [A-Za-z0-9]* */ public static boolean matchAz09(String str) { return match(str, StringUtils::isAz09); }
public boolean isSystem() { return name != null && name.trim().length() == 64 && StringUtils.matchHex(name); } }
private int getMaxNumber(String applicationName, DockerService dockerService) { int last = -1; Set<String> names = new HashSet<>(); names.addAll(containerNames.apply(dockerService)); names.addAll(getRecentNames()); for (String name: names) { if (!(name.startsWith(applicationName))) { continue; } try { String s = StringUtils.afterLast(name, '-'); int i = Integer.parseInt(s); if(i > last) { last = i; } } catch(Exception e) { //it usual if last is word or string does not contains '-' if(last < 0) { last = 0; } } } return last; }
/** * @see StringUtils#matchAz09Hyp(String) * @param str string * @param thatIt that it string represent */ public static void matchAz09Hyp(String str, String thatIt) { badRequest(str != null && StringUtils.matchAz09Hyp(str), "The \"{0}\" is not match with '[A-Za-z0-9-]+': \"{1}\"", thatIt, str); }
public Peer from(Network.PeerInfo peer) { String nameAndId = peer.getName(); // see https://github.com/docker/docker/issues/28984 String name = StringUtils.beforeLast(nameAndId, '-'); setName(name); setIp(peer.getIp()); return this; } }
/** * Is a <code>match(str, StringUtils::isAz09Hyp);</code>. * @param str string * @return true if string match [A-Za-z0-9-]* */ public static boolean matchAz09Hyp(String str) { return match(str, StringUtils::isAz09Hyp); }
public static boolean isId(String image) { if(StringUtils.isEmpty(image)) { return false; } // see https://docs.docker.com/registry/spec/api/#/content-digests int length = SHA256.length(); if(image.regionMatches(true, 0, SHA256, 0, length)) { return true; } // sometime image name is created from id, // usual it has ImageName.NAME_ID_LEN first symbols from id return com.codeabovelab.dm.common.utils.StringUtils.matchHex(image); }
Set<String> ignored = hostConfig.getBinds().stream().map(s -> StringUtils.afterLast(s, ':')).collect(Collectors.toSet()); loadMounts(container.getMounts(), hostConfig.getMounts(), nc.getMounts(), ignored);
private String[] filterEnv(Collection<String> env) { log.info("All env {}", env); Set<String> filter = new HashSet<>(); String[] constraints = env.stream() .filter(e -> e.contains("=")) .filter(e -> { String before = before(e, '='); return before.contains("constraint") || filter.add(before(e, '=')); }).toArray(String[]::new); log.info("Filtered env {}", Arrays.toString(constraints)); return constraints; }
public static String before(String s, char c) { return beforeOr(s, c, () -> { // we throw exception for preserve old behavior throw new IllegalArgumentException("String '" + s + "' must contains '" + c + "'."); }); }
/** * Is a <code>match(str, StringUtils::isId);</code>. * @param str string * @return true if string match [A-Za-z0-9-_:.]* */ public static boolean matchId(String str) { return match(str, StringUtils::isId); }
/** * system mapping like: * "Type": "volume", * "Name": "810a2b9f8d08ba620612e1227d1214", * "Source": "/var/lib/docker/volumes/810a2b9f8d08ba620612e1/_data", * "Driver": "local", */ public boolean isSystem() { return Arrays.stream(getSource().split("/")).anyMatch(s -> s.trim().length() == 64 && StringUtils.matchHex(s)); }
/** * Chars which is acceptable as file name or part of url on most operation systems. <p/> * It: <code>'A'-'z', '0'-'9', '_', '-', '.'</code> * @param cp codePoint * @return true for specified chars */ public static boolean isForFileName(int cp) { return isAz09(cp) || cp == '-' || cp == '_' || cp == '.'; }
public Filter createFilter(String expr) { String proto = StringUtils.before(expr, ':'); Factory ff = factories.get(proto); Assert.notNull(ff, "can not find factory for: " + expr); return ff.create(expr.substring(proto.length() + 1)); }
public static boolean matchHex(String str) { return match(str, StringUtils::isHex); }