org.apache.commons.lang3.StringUtils.substringAfter()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(13.0k)|赞(0)|评价(0)|浏览(346)

本文整理了Java中org.apache.commons.lang3.StringUtils.substringAfter()方法的一些代码示例,展示了StringUtils.substringAfter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.substringAfter()方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:substringAfter

StringUtils.substringAfter介绍

[英]Gets the substring after the first occurrence of a separator. The separator is not returned.

A null string input will return null. An empty ("") string input will return the empty string. A null separator will return the empty string if the input string is not null.

If nothing is found, the empty string is returned.

StringUtils.substringAfter(null, *)      = null 
StringUtils.substringAfter("", *)        = "" 
StringUtils.substringAfter(*, null)      = "" 
StringUtils.substringAfter("abc", "a")   = "bc" 
StringUtils.substringAfter("abcba", "b") = "cba" 
StringUtils.substringAfter("abc", "c")   = "" 
StringUtils.substringAfter("abc", "d")   = "" 
StringUtils.substringAfter("abc", "")    = "abc"

[中]获取第一次出现分隔符后的子字符串。未返回分隔符。
空字符串输入将返回空值。空(“”)字符串输入将返回空字符串。如果输入字符串不为null,则null分隔符将返回空字符串。
如果未找到任何内容,则返回空字符串。

StringUtils.substringAfter(null, *)      = null 
StringUtils.substringAfter("", *)        = "" 
StringUtils.substringAfter(*, null)      = "" 
StringUtils.substringAfter("abc", "a")   = "bc" 
StringUtils.substringAfter("abcba", "b") = "cba" 
StringUtils.substringAfter("abc", "c")   = "" 
StringUtils.substringAfter("abc", "d")   = "" 
StringUtils.substringAfter("abc", "")    = "abc"

代码示例

代码示例来源:origin: zhegexiaohuozi/SeimiCrawler

public static String getDodmain(String url){
    String[] pies = url.split("/");
    return StringUtils.substringAfter(pies[2],".");
  }
}

代码示例来源:origin: xtuhcy/gecco

try {
  String before =  StringUtils.substringBefore(imgUrl, "?");
  String last =  StringUtils.substringAfter(imgUrl, "?");
  String fileName = StringUtils.substringAfterLast(before, "/");
  if(StringUtils.isNotEmpty(last)) {

代码示例来源:origin: joelittlejohn/jsonschema2pojo

private String getListType(JType jType) {
  final String typeName = jType.fullName();
  return substringBeforeLast(substringAfter(typeName, "<"), ">");
}

代码示例来源:origin: jamesdbloom/mockserver

public void renderDashboard(final ChannelHandlerContext ctx, final HttpRequest request) throws Exception {
  HttpResponse response = notFoundResponse();
  if (request.getMethod().getValue().equals("GET")) {
    String path = StringUtils.substringAfter(request.getPath().getValue(), PATH_PREFIX + "/dashboard");
    if (path.isEmpty() || path.equals("/")) {
      path = "/index.html";

代码示例来源:origin: Activiti/Activiti

public Optional<ActionDefinition> find(String implementation){

    Optional<ActionDefinition> actionDefinitionOptional = Optional.empty();

    String connectorId = StringUtils.substringBefore(implementation,
                             ".");
    String actionId = StringUtils.substringAfter(implementation,
                           ".");

    List<ConnectorDefinition> resultingConnectors = connectorDefinitions.stream().filter(c -> c.getId().equals(connectorId)).collect(Collectors.toList());
    if (resultingConnectors != null && resultingConnectors.size() != 0) {
      if (resultingConnectors.size() != 1) {
        throw new RuntimeException("Mismatch connector id mapping: " + connectorId);
      }
      ConnectorDefinition connectorDefinition = resultingConnectors.get(0);

      ActionDefinition actionDefinition = connectorDefinition.getActions().get(actionId);
      if (actionDefinition == null) {
        throw new RuntimeException("Mismatch action id mapping: " + actionId);
      }

      actionDefinitionOptional = Optional.ofNullable(actionDefinition);
    }

    return actionDefinitionOptional;
  }
}

代码示例来源:origin: apache/nifi

@Override
public Response toResponse(WebApplicationException exception) {
  // get the message and ensure it is not blank
  String message = exception.getMessage();
  if (message == null) {
    message = StringUtils.EMPTY;
  }
  // format the message
  if (message.contains(EXCEPTION_SEPARATOR)) {
    message = StringUtils.substringAfter(message, EXCEPTION_SEPARATOR);
  }
  // get the response
  final Response response = exception.getResponse();
  // log the error
  logger.info(String.format("%s. Returning %s response.", exception, response.getStatus()));
  if (logger.isDebugEnabled()) {
    logger.debug(StringUtils.EMPTY, exception);
  }
  // generate the response
  return Response.status(response.getStatus()).entity(message).type("text/plain").build();
}

代码示例来源:origin: springside/springside4

/**
 * 兼容无前缀, classpath://, file:// 的情况获取文件
 * 
 * 如果以classpath:// 定义的文件不存在会抛出IllegalArgumentException异常,以file://定义的则不会
 */
public static File asFile(String generalPath) throws IOException {
  if (StringUtils.startsWith(generalPath, CLASSPATH_PREFIX)) {
    String resourceName = StringUtils.substringAfter(generalPath, CLASSPATH_PREFIX);
    return getFileByURL(ResourceUtil.asUrl(resourceName));
  }
  try {
    // try URL
    return getFileByURL(new URL(generalPath));
  } catch (MalformedURLException ex) {
    // no URL -> treat as file path
    return new File(generalPath);
  }
}

代码示例来源:origin: apache/nifi

private Authorizable getAccessPolicy(final ResourceType resourceType, final String resource) {
  final String slashComponentId = StringUtils.substringAfter(resource, resourceType.getValue());
  if (slashComponentId.startsWith("/")) {
    return getAccessPolicyByResource(resourceType, slashComponentId.substring(1));
  } else {
    return getAccessPolicyByResource(resourceType);
  }
}

代码示例来源:origin: springside/springside4

/**
 * 兼容file://与classpath://的情况的打开文件成Stream
 */
public static InputStream asStream(String generalPath) throws IOException {
  if (StringUtils.startsWith(generalPath, CLASSPATH_PREFIX)) {
    String resourceName = StringUtils.substringAfter(generalPath, CLASSPATH_PREFIX);
    return ResourceUtil.asStream(resourceName);
  }
  try {
    // try URL
    return FileUtil.asInputStream(getFileByURL(new URL(generalPath)));
  } catch (MalformedURLException ex) {
    // no URL -> treat as file path
    return FileUtil.asInputStream(generalPath);
  }
}

代码示例来源:origin: apache/incubator-gobblin

@SuppressWarnings("unchecked")
 protected VersionSelectionPolicy<DatasetVersion> createSelectionPolicy(Config selectionConfig, Config jobConfig) {
  try {
   String selectionPolicyKey =
     StringUtils.substringAfter(ConfigurableCleanableDataset.SELECTION_POLICY_CLASS_KEY,
       ConfigurableCleanableDataset.CONFIGURATION_KEY_PREFIX);
   Preconditions.checkArgument(selectionConfig.hasPath(selectionPolicyKey));
   String className = selectionConfig.getString(selectionPolicyKey);
   return (VersionSelectionPolicy<DatasetVersion>) GobblinConstructorUtils.invokeFirstConstructor(
     this.versionSelectionAliasResolver.resolveClass(className), ImmutableList.<Object> of(selectionConfig),
     ImmutableList.<Object> of(selectionConfig, ConfigUtils.configToProperties(jobConfig)),
     ImmutableList.<Object> of(ConfigUtils.configToProperties(jobConfig)));
  } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException
    | ClassNotFoundException e) {
   throw new IllegalArgumentException(e);
  }
 }
}

代码示例来源:origin: org.apache.commons/commons-lang3

@Test
public void testSubstringAfter_StringString() {
  assertEquals("barXXbaz", StringUtils.substringAfter("fooXXbarXXbaz", "XX"));
  assertNull(StringUtils.substringAfter(null, null));
  assertNull(StringUtils.substringAfter(null, ""));
  assertNull(StringUtils.substringAfter(null, "XX"));
  assertEquals("", StringUtils.substringAfter("", null));
  assertEquals("", StringUtils.substringAfter("", ""));
  assertEquals("", StringUtils.substringAfter("", "XX"));
  assertEquals("", StringUtils.substringAfter("foo", null));
  assertEquals("ot", StringUtils.substringAfter("foot", "o"));
  assertEquals("bc", StringUtils.substringAfter("abc", "a"));
  assertEquals("cba", StringUtils.substringAfter("abcba", "b"));
  assertEquals("", StringUtils.substringAfter("abc", "c"));
  assertEquals("abc", StringUtils.substringAfter("abc", ""));
  assertEquals("", StringUtils.substringAfter("abc", "d"));
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

String fragment = substringAfter(path, "#");
URI fragmentURI;
try {

代码示例来源:origin: apache/incubator-gobblin

private void initWithSelectionPolicy(Config config, Properties jobProps) {
 String selectionPolicyKey = StringUtils.substringAfter(SELECTION_POLICY_CLASS_KEY, CONFIGURATION_KEY_PREFIX);
 String versionFinderKey = StringUtils.substringAfter(VERSION_FINDER_CLASS_KEY, CONFIGURATION_KEY_PREFIX);
 Preconditions.checkArgument(
   config.hasPath(versionFinderKey),
   String.format("Version finder class is required at %s in config %s", versionFinderKey,
     config.root().render(ConfigRenderOptions.concise())));
 VersionFinderAndPolicyBuilder<T> builder = VersionFinderAndPolicy.builder();
 builder.versionFinder(createVersionFinder(config.getString(versionFinderKey), config, jobProps));
 if (config.hasPath(selectionPolicyKey)) {
  builder.versionSelectionPolicy(createSelectionPolicy(
    ConfigUtils.getString(config, selectionPolicyKey, SelectNothingPolicy.class.getName()), config, jobProps));
 }
 for (Class<? extends RetentionActionFactory> factoryClass : RETENTION_ACTION_TYPES) {
  try {
   RetentionActionFactory factory = factoryClass.newInstance();
   if (factory.canCreateWithConfig(config)) {
    builder.retentionAction((RetentionAction) factory.createRetentionAction(config, this.fs,
      ConfigUtils.propertiesToConfig(jobProps)));
   }
  } catch (InstantiationException | IllegalAccessException e) {
   Throwables.propagate(e);
  }
 }
 this.versionFindersAndPolicies.add(builder.build());
}

代码示例来源:origin: alipay/sofa-rpc

private ConsulURL buildURL(ConsulService service) {
  try {
    for (String tag : service.getTags()) {
      if (org.apache.commons.lang3.StringUtils.indexOf(tag, ConsulConstants.PROVIDERS_CATEGORY) != -1) {
        String toUrlPath = org.apache.commons.lang3.StringUtils.substringAfter(tag,
          ConsulConstants.PROVIDERS_CATEGORY);
        ConsulURL consulUrl = ConsulURL.valueOf(ConsulURL.decode(toUrlPath));
        return consulUrl;
      }
    }
  } catch (Exception e) {
    LOGGER.error("convert consul service to url fail! service:" + service, e);
  }
  return null;
}

代码示例来源:origin: alipay/sofa-rpc

private ConsulURL buildURL(ConsulService service) {
  try {
    for (String tag : service.getTags()) {
      if (org.apache.commons.lang3.StringUtils.indexOf(tag, ConsulConstants.PROVIDERS_CATEGORY) != -1) {
        String toUrlPath = org.apache.commons.lang3.StringUtils.substringAfter(tag,
          ConsulConstants.PROVIDERS_CATEGORY);
        ConsulURL consulUrl = ConsulURL.valueOf(ConsulURL.decode(toUrlPath));
        return consulUrl;
      }
    }
  } catch (Exception e) {
    LOGGER.error("convert consul service to url fail! service:" + service, e);
  }
  return null;
}

代码示例来源:origin: ben-manes/caffeine

private void status() {
 int drainStatus;
 int pendingWrites;
 local.evictionLock.lock();
 try {
  pendingWrites = local.writeBuffer().size();
  drainStatus = local.drainStatus();
 } finally {
  local.evictionLock.unlock();
 }
 LocalTime elapsedTime = LocalTime.ofSecondOfDay(stopwatch.elapsed(TimeUnit.SECONDS));
 System.out.printf("---------- %s ----------%n", elapsedTime);
 System.out.printf("Pending reads: %,d; writes: %,d%n", local.readBuffer.size(), pendingWrites);
 System.out.printf("Drain status = %s (%s)%n", STATUS[drainStatus], drainStatus);
 System.out.printf("Evictions = %,d%n", cache.stats().evictionCount());
 System.out.printf("Size = %,d (max: %,d)%n", local.data.mappingCount(), operation.maxEntries);
 System.out.printf("Lock = [%s%n", StringUtils.substringAfter(
   local.evictionLock.toString(), "["));
 System.out.printf("Pending tasks = %,d%n",
   ForkJoinPool.commonPool().getQueuedSubmissionCount());
 long maxMemory = Runtime.getRuntime().maxMemory();
 long freeMemory = Runtime.getRuntime().freeMemory();
 long allocatedMemory = Runtime.getRuntime().totalMemory();
 System.out.printf("Max Memory = %,d bytes%n", maxMemory);
 System.out.printf("Free Memory = %,d bytes%n", freeMemory);
 System.out.printf("Allocated Memory = %,d bytes%n", allocatedMemory);
 System.out.println();
}

代码示例来源:origin: joelittlejohn/jsonschema2pojo

JClass existingClass = resolveType(_package, fqn + (node.get("existingJavaType").asText().contains("<") ? "<" + substringAfter(node.get("existingJavaType").asText(), "<") : ""));
throw new ClassAlreadyExistsException(existingClass);

代码示例来源:origin: apache/geode

@Test
public void testToStringForEmpty() {
 final PdxWriterImpl writer =
   new PdxWriterImpl(emptyPdxType, pdxRegistry, new PdxOutputStream());
 writer.completeByteStreamGeneration();
 final PdxInstance instance = writer.makePdxInstance();
 assertEquals(emptyPdxType.getClassName() + "]{}", substringAfter(instance.toString(), ","));
}

代码示例来源:origin: apache/nifi

final String baseResource = StringUtils.substringAfter(resource, resourceType.getValue());
final ResourceType baseResourceType = ResourceType.fromRawValue(baseResource);
final String slashRequiredPermission = StringUtils.substringAfter(resource, resourceType.getValue());

代码示例来源:origin: apache/geode

stringField.getFieldName() + "=MOOF!" +
  "}",
substringAfter(instance.toString(), ","));

相关文章

微信公众号

最新文章

更多

StringUtils类方法