下面列出了org.apache.commons.lang3.StringUtils#startsWithAny ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private int parseTreeLevel(final String line) {
if (StringUtils.startsWithAny(line, TREE_LEVEL_TERMINALS)) {
return 0;
}
String modifiedLine = DetectableStringUtils.removeEvery(line, TREE_LEVEL_TERMINALS);
if (!modifiedLine.startsWith("|") && modifiedLine.startsWith(" ")) {
modifiedLine = "|" + modifiedLine;
}
modifiedLine = modifiedLine.replace(" ", " |");
modifiedLine = modifiedLine.replace("||", "|");
if (modifiedLine.endsWith("|")) {
modifiedLine = modifiedLine.substring(0, modifiedLine.length() - 5);
}
final int matches = StringUtils.countMatches(modifiedLine, "|");
return matches;
}
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
WxMpService weixinService, WxSessionManager sessionManager) {
if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
// TODO 可以选择将消息保存到本地
}
// 当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
try {
if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
&& weixinService.getKefuService().kfOnlineList().getKfOnlineList().size() > 0) { return WxMpXmlOutMessage
.TRANSFER_CUSTOMER_SERVICE().fromUser(wxMessage.getToUser()).toUser(
wxMessage.getFromUser()).build(); }
} catch (WxErrorException e) {
e.printStackTrace();
}
// TODO 组装回复消息
String content = "收到信息内容:" + JsonUtils.toJson(wxMessage);
return new TextBuilder().build(content, wxMessage, weixinService);
}
private boolean skip(Item o) {
if ((StringUtils.length(o.getValue()) > 1) && (!StringUtils.startsWithAny(o.getValue(), SKIP_START_WITH))
&& (!StringUtils.endsWithAny(o.getValue(), SKIP_END_WITH))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "b"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "c"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "d"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "e"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "f"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "h"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "k"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "o"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "p"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "q"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "r"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "u"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "w")) && (!label_skip_m(o))) {
return false;
}
return true;
}
private boolean skip(Item o) {
if ((StringUtils.length(o.getValue()) > 1) && (!StringUtils.startsWithAny(o.getValue(), SKIP_START_WITH))
&& (!StringUtils.endsWithAny(o.getValue(), SKIP_END_WITH))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "b"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "c"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "d"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "e"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "f"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "h"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "k"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "o"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "p"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "q"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "r"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "u"))
&& (!StringUtils.startsWithIgnoreCase(o.getLabel(), "w")) && (!label_skip_m(o))) {
return false;
}
return true;
}
@RequestMapping(value = "/blur", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<InputStreamResource> blur(@RequestParam("source") String sourceUrl) {
if (!StringUtils.startsWithAny(sourceUrl, ALLOWED_PREFIX)) {
return ResponseEntity.badRequest().build();
}
String hash = DigestUtils.sha1Hex(sourceUrl);
try {
ImageInfo info = readCached(hash);
if (info == null) {
info = renderImage(sourceUrl);
saveCached(hash, info);
}
return ResponseEntity.ok()
.contentLength(info.contentLength)
.contentType(MediaType.IMAGE_JPEG)
.body(new InputStreamResource(info.inputStream));
} catch (IOException e) {
// fall down
}
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
/**
* 判断是否json串
* @param jsonStr JSON字符串
* @return java对象
*/
public static synchronized boolean isJson(String jsonStr) {
try {
return StringUtils.startsWithAny(jsonStr, "{", "[");
} catch (Exception e) {
LogBack.error(JACKSON_ERROR, e.getMessage());
return false;
}
}
@Test
public void string_starts_with_any_apache_commons() {
boolean startsWithHttpProtocol = StringUtils
.startsWithAny("http://www.leveluplunch.com", new String[] {
"http", "https" });
assertTrue(startsWithHttpProtocol);
}
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService weixinService,
WxSessionManager sessionManager) {
if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
//TODO 可以选择将消息保存到本地
}
//当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
try {
if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
&& weixinService.getKefuService().kfOnlineList()
.getKfOnlineList().size() > 0) {
return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
.fromUser(wxMessage.getToUser())
.toUser(wxMessage.getFromUser()).build();
}
} catch (WxErrorException e) {
e.printStackTrace();
}
//TODO 组装回复消息
String content = "yshop收到信息内容:" + wxMessage.getContent();
return new TextBuilder().build(content, wxMessage, weixinService);
}
@Override
protected boolean isValidScheme(String url) {
//check if url starts with one of the schemes
if(StringUtils.startsWithAny(url, schemes)) {
return true;
}
return false;
}
@Override
public String toModelImport(String name) {
String modelImport;
if (StringUtils.startsWithAny(name,"import", "from")) {
modelImport = name;
} else {
modelImport = "from ";
if (!"".equals(modelPackage())) {
modelImport += modelPackage() + ".";
}
modelImport += toModelFilename(name)+ " import " + name;
}
return modelImport;
}
@Override
public String toModelImport(String name) {
String modelImport;
if (StringUtils.startsWithAny(name,"import", "from")) {
modelImport = name;
} else {
modelImport = "from ";
if (!"".equals(modelPackage())) {
modelImport += modelPackage() + ".";
}
modelImport += toModelFilename(name)+ " import " + name;
}
return modelImport;
}
@Override
public String toModelImport(String name) {
String modelImport;
if (StringUtils.startsWithAny(name, "import", "from")) {
modelImport = name;
} else {
modelImport = "from ";
if (!"".equals(modelPackage())) {
modelImport += modelPackage() + ".";
}
modelImport += toModelFilename(name) + " import " + name;
}
return modelImport;
}
@Override
public String toModelImport(String name) {
String modelImport;
if (StringUtils.startsWithAny(name, "import", "from")) {
modelImport = name;
} else {
modelImport = "from ";
if (!"".equals(modelPackage())) {
modelImport += modelPackage() + ".";
}
modelImport += toModelFilename(name) + " import " + name;
}
return modelImport;
}
@Override
protected boolean isValidScheme(String url) {
//check if url starts with one of the schemes
if(StringUtils.startsWithAny(url, schemes)) {
return true;
}
return false;
}
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService weixinService,
WxSessionManager sessionManager) {
if (!wxMessage.getMsgType().equals(XmlMsgType.EVENT)) {
//TODO 可以选择将消息保存到本地
}
//当用户输入关键词如“你好”,“客服”等,并且有客服在线时,把消息转发给在线客服
try {
if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服")
&& weixinService.getKefuService().kfOnlineList()
.getKfOnlineList().size() > 0) {
return WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE()
.fromUser(wxMessage.getToUser())
.toUser(wxMessage.getFromUser()).build();
}
} catch (WxErrorException e) {
e.printStackTrace();
}
//TODO 组装回复消息
String content = "收到信息内容:" + JsonUtils.toJson(wxMessage);
return new TextBuilder().build(content, wxMessage, weixinService);
}
protected boolean isUserWritable(final MantaObject object) {
final MantaAccountHomeInfo account = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());
return StringUtils.startsWithAny(
object.getPath(),
account.getAccountPublicRoot().getAbsolute(),
account.getAccountPrivateRoot().getAbsolute());
}
@Before("execution(* com.appengine..*Dao.*(..))")
public void beforMethod(JoinPoint joinPoint) {
String methodName = joinPoint.getSignature().getName();
RequestContext rc = ThreadLocalContext.getRequestContext();
if (StringUtils.startsWithAny(methodName, writeMethodPrefixs)) {
rc.setShouldReadMasterDB(true);
} else if (StringUtils.startsWithAny(methodName, queryMethodPrefixs)) {
rc.setShouldReadMasterDB(false);
} else {
log.warn("cannot found handle db method for methodName is: " + methodName);
rc.setShouldReadMasterDB(true);
}
}
static boolean secondaryAttributeMatches(String eFlagsDecimalString, String attribute) {
// eFlagDecimalString is the elf e_flags value, as a decimal string
// sa is the secondary attribute string from the opinion file,
// and it must start with "0x" or "0b"
if (attribute == null) {
return false;
}
if (!StringUtils.startsWithAny(attribute.toLowerCase(), "0x", "0b")) {
return false;
}
int eFlagsInt = Integer.parseInt(eFlagsDecimalString);
String eFlagsBinaryString = Integer.toBinaryString(eFlagsInt);
if (eFlagsBinaryString == null) {
return false;
}
eFlagsBinaryString = StringUtils.leftPad(eFlagsBinaryString, 32, "0");
String eFlagsHexString = Integer.toHexString(eFlagsInt);
eFlagsHexString = StringUtils.leftPad(eFlagsHexString, 8, "0");
// Remove '_' and whitespace from the attribute string
String cleaned = attribute.replace("_", "").replaceAll("\\s+", "").trim();
String prefix = cleaned.substring(0, 2);
String value = cleaned.substring(2);
if (prefix.toLowerCase().startsWith("0x")) {
// It's a hex string
value = StringUtils.leftPad(value, 8, "0");
return value.equals(eFlagsHexString);
}
// It's a binary string
value = StringUtils.leftPad(value, 32, "0");
for (int i = 0; i < 32; i++) {
char c = value.charAt(i);
if (c == '.') { // wildcard
continue;
}
if (eFlagsBinaryString.charAt(i) != c) {
return false;
}
}
return true;
}
protected boolean isWorldReadable(final MantaObject object) {
final MantaAccountHomeInfo accountHomeInfo = new MantaAccountHomeInfo(host.getCredentials().getUsername(), host.getDefaultPath());
return StringUtils.startsWithAny(
object.getPath(),
accountHomeInfo.getAccountPublicRoot().getAbsolute());
}
/**
* at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
* at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
* at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
* at java.lang.reflect.Method.invoke(Method.java:498)
*/
private boolean isReflection(String stackClassName) {
return StringUtils.startsWithAny(stackClassName, REFLECTION_PREFIXES);
}