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

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

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

StringUtils.substringAfterLast介绍

[英]Gets the substring after the last 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. An empty or null separator will return the empty string if the input string is not null.

If nothing is found, the empty string is returned.

StringUtils.substringAfterLast(null, *)      = null 
StringUtils.substringAfterLast("", *)        = "" 
StringUtils.substringAfterLast(*, "")        = "" 
StringUtils.substringAfterLast(*, null)      = "" 
StringUtils.substringAfterLast("abc", "a")   = "bc" 
StringUtils.substringAfterLast("abcba", "b") = "a" 
StringUtils.substringAfterLast("abc", "c")   = "" 
StringUtils.substringAfterLast("a", "a")     = "" 
StringUtils.substringAfterLast("a", "z")     = ""

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

StringUtils.substringAfterLast(null, *)      = null 
StringUtils.substringAfterLast("", *)        = "" 
StringUtils.substringAfterLast(*, "")        = "" 
StringUtils.substringAfterLast(*, null)      = "" 
StringUtils.substringAfterLast("abc", "a")   = "bc" 
StringUtils.substringAfterLast("abcba", "b") = "a" 
StringUtils.substringAfterLast("abc", "c")   = "" 
StringUtils.substringAfterLast("a", "a")     = "" 
StringUtils.substringAfterLast("a", "z")     = ""

代码示例

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

@Override
public void report(SortedMap<String, Gauge> gauges,
          SortedMap<String, Counter> counters,
          SortedMap<String, Histogram> histograms,
          SortedMap<String, Meter> meters,
          SortedMap<String, Timer> timers) {
 // we know we only have histograms
 if (!histograms.isEmpty()) {
  for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
   output.print("   " + StringUtils.substringAfterLast(entry.getKey(), "."));
   output.println(':');
   printHistogram(entry.getValue());
  }
  output.println();
 }
 output.println();
 output.flush();
}

代码示例来源:origin: simpligility/android-maven-plugin

/**
 * This method extracts a port number from the serial number of a device.
 * It assumes that the device name is of format [xxxx-nnnn] where nnnn is the
 * port number.
 *
 * @param device The device to extract the port number from.
 * @return Returns the port number of the device
 */
private int extractPortFromDevice( IDevice device )
{
  String portStr = StringUtils.substringAfterLast( device.getSerialNumber(), "-" );
  if ( StringUtils.isNotBlank( portStr ) && StringUtils.isNumeric( portStr ) )
  {
    return Integer.parseInt( portStr );
  }
  //If the port is not available then return -1
  return -1;
}

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

@Override
  public Authentication attemptAuthentication(final HttpServletRequest request) {
    // only support jwt login when running securely
    if (!request.isSecure()) {
      return null;
    }

    // TODO: Refactor request header extraction logic to shared utility as it is duplicated in AccessResource

    // get the principal out of the user token
    final String authorization = request.getHeader(AUTHORIZATION);

    // if there is no authorization header, we don't know the user
    if (authorization == null || !StringUtils.startsWith(authorization, BEARER)) {
      return null;
    } else {
      // Extract the Base64 encoded token from the Authorization header
      final String token = StringUtils.substringAfterLast(authorization, " ");
      return new JwtAuthenticationRequestToken(token, request.getRemoteAddr());
    }
  }
}

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

public void saveFile(Response response){
    try {
      String fileName = StringUtils.substringAfterLast(response.getUrl(),"/");
      String path = "d:/temp/cnblogs/"+fileName;
      response.saveTo(new File(path));
      logger.info("file done = {}",fileName);
    }catch (Exception e){
      //
    }
  }
}

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

private String getStatus( String resourceName, long complete, long total )
{
  FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH );
  StringBuilder status = new StringBuilder();
  if ( printResourceNames )
  {
    status.append( StringUtils.substringAfterLast( resourceName,  "/" ) );
    status.append( " (" );
  }
  status.append( format.formatProgress( complete, total ) );
  if ( printResourceNames )
  {
    status.append( ")" );
  }
  return status.toString();
}

代码示例来源:origin: knightliao/disconf

String node = StringUtils.substringAfterLast(groupName, "/");
sb.append("|----" + node);
Stat stat = new Stat();

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

public static Charset getCharsetFromContentTypeHeader(String contentType) {
    Charset charset = DEFAULT_HTTP_CHARACTER_SET;
    if (contentType != null) {
      String charsetName = StringUtils.substringAfterLast(contentType, CHARSET.toString() + (char) HttpConstants.EQUALS).replaceAll("\"", "");
      if (!Strings.isNullOrEmpty(charsetName)) {
        try {
          charset = Charset.forName(charsetName);
        } catch (UnsupportedCharsetException uce) {
          MOCK_SERVER_LOGGER.warn("Unsupported character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType);
        } catch (IllegalCharsetNameException icne) {
          MOCK_SERVER_LOGGER.warn("Illegal character set {} in Content-Type header: {}.", StringUtils.substringAfterLast(contentType, CHARSET.toString() + HttpConstants.EQUALS), contentType);
        }
      } else if (UTF_8_CONTENT_TYPES.contains(contentType)) {
        charset = CharsetUtil.UTF_8;
      }
    }
    return charset;
  }
}

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

fileName = StringUtils.substringAfterLast(fileName, "/");
File imageFile = new File(imageDir, fileName);
InputStream in = closer.register(new URL(imgUrl).openStream());

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

@Test
public void testSubstringAfterLast_StringString() {
  assertEquals("baz", StringUtils.substringAfterLast("fooXXbarXXbaz", "XX"));
  assertNull(StringUtils.substringAfterLast(null, null));
  assertNull(StringUtils.substringAfterLast(null, ""));
  assertNull(StringUtils.substringAfterLast(null, "XX"));
  assertEquals("", StringUtils.substringAfterLast("", null));
  assertEquals("", StringUtils.substringAfterLast("", ""));
  assertEquals("", StringUtils.substringAfterLast("", "a"));
  assertEquals("", StringUtils.substringAfterLast("foo", null));
  assertEquals("", StringUtils.substringAfterLast("foo", "b"));
  assertEquals("t", StringUtils.substringAfterLast("foot", "o"));
  assertEquals("bc", StringUtils.substringAfterLast("abc", "a"));
  assertEquals("a", StringUtils.substringAfterLast("abcba", "b"));
  assertEquals("", StringUtils.substringAfterLast("abc", "c"));
  assertEquals("", StringUtils.substringAfterLast("", "d"));
  assertEquals("", StringUtils.substringAfterLast("abc", ""));
}

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

private long parseDateForLocation(String location) throws UpdateNotFoundException {
 for (Patterns pattern : Patterns.values()) {
  String dateString = StringUtils.substringAfterLast(location, pattern.prefix);
  if (StringUtils.isNotBlank(dateString)) {
   try {
    return pattern.dateFormat.parseMillis(dateString);
   } catch (IllegalArgumentException | UnsupportedOperationException e) {
    throw new UpdateNotFoundException(String.format("Failed parsing date string %s", dateString));
   }
  }
 }
 throw new UpdateNotFoundException(String.format("Path %s does not match any date pattern %s", location,
   Arrays.toString(Patterns.values())));
}

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

/**
 * Returns true if the provided address is an IPv6 address (or could be interpreted as one). This method is more
 * lenient than {@link InetAddressUtils#isIPv6Address(String)} because of different interpretations of IPv4-mapped
 * IPv6 addresses.
 *
 * See RFC 5952 Section 4 for more information on textual representation of the IPv6 addresses.
 *
 * @param address the address in text form
 * @return true if the address is or could be parsed as an IPv6 address
 */
static boolean isIPv6Address(String address) {
  // Note: InetAddressUtils#isIPv4MappedIPv64Address() fails on addresses that do not compress the leading 0:0:0... to ::
  // Expanded for debugging purposes
  boolean isNormalIPv6 = InetAddressUtils.isIPv6Address(address);
  // If the last two hextets are written in IPv4 form, treat it as an IPv6 address as well
  String everythingAfterLastColon = StringUtils.substringAfterLast(address, ":");
  boolean isIPv4 = InetAddressUtils.isIPv4Address(everythingAfterLastColon);
  boolean isIPv4Mapped = InetAddressUtils.isIPv4MappedIPv64Address(everythingAfterLastColon);
  boolean isCompressable = address.contains("0:0") && !address.contains("::");
  return isNormalIPv6 || isIPv4;
}

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

String before =  StringUtils.substringBefore(imgUrl, "?");
String last =  StringUtils.substringAfter(imgUrl, "?");
String fileName = StringUtils.substringAfterLast(before, "/");
if(StringUtils.isNotEmpty(last)) {
  last = URLEncoder.encode(last, "UTF-8");

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

private ReportingTaskNode createReportingTaskNode(final LoggableComponent<ReportingTask> reportingTask, final boolean creationSuccessful) {
  final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
  final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, componentVarRegistry);
  final ReportingTaskNode taskNode;
  if (creationSuccessful) {
    taskNode = new StandardReportingTaskNode(reportingTask, identifier, flowController, processScheduler,
      validationContextFactory, componentVarRegistry, reloadComponent, extensionManager, validationTrigger);
    taskNode.setName(taskNode.getReportingTask().getClass().getSimpleName());
  } else {
    final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
    final String componentType = "(Missing) " + simpleClassName;
    taskNode = new StandardReportingTaskNode(reportingTask, identifier, flowController, processScheduler, validationContextFactory,
      componentType, type, componentVarRegistry, reloadComponent, extensionManager, validationTrigger, true);
    taskNode.setName(componentType);
  }
  return taskNode;
}

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

private ControllerServiceNode createGhostControllerServiceNode() {
  final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
  final String componentType = "(Missing) " + simpleClassName;
  final GhostControllerService ghostService = new GhostControllerService(identifier, type);
  final LoggableComponent<ControllerService> proxiedLoggableComponent = new LoggableComponent<>(ghostService, bundleCoordinate, null);
  final ControllerServiceInvocationHandler invocationHandler = new StandardControllerServiceInvocationHandler(extensionManager, ghostService);
  final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
  final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, variableRegistry);
  final ControllerServiceNode serviceNode = new StandardControllerServiceNode(proxiedLoggableComponent, proxiedLoggableComponent, invocationHandler, identifier,
    validationContextFactory, serviceProvider, componentType, type, componentVarRegistry, reloadComponent, extensionManager, validationTrigger, true);
  return serviceNode;
}

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

private ProcessorNode createProcessorNode(final LoggableComponent<Processor> processor, final boolean creationSuccessful) {
  final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
  final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(serviceProvider, componentVarRegistry);
  final ProcessorNode procNode;
  if (creationSuccessful) {
    procNode = new StandardProcessorNode(processor, identifier, validationContextFactory, processScheduler, serviceProvider,
      componentVarRegistry, reloadComponent, extensionManager, validationTrigger);
  } else {
    final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
    final String componentType = "(Missing) " + simpleClassName;
    procNode = new StandardProcessorNode(processor, identifier, validationContextFactory, processScheduler, serviceProvider,
      componentType, type, componentVarRegistry, reloadComponent, extensionManager, validationTrigger, true);
  }
  applyDefaultSettings(procNode);
  return procNode;
}

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

final String extension = StringUtils.substringAfterLast(path, ".");
if (IS_TEST.contains(extension)) {
  final String content = IOUtils.toString(contentStream, UTF_8.name());

代码示例来源:origin: oldmanpushcart/greys-anatomy

public TTimeFragmentTable add(TimeFragment timeFragment) {
  final Advice advice = timeFragment.advice;
  tTable.addRow(
      timeFragment.id,
      timeFragment.processId,
      SimpleDateFormatHolder.getInstance().format(timeFragment.gmtCreate),
      timeFragment.cost,
      advice.isReturn,
      advice.isThrow,
      hashCodeToHexString(advice.target),
      substringAfterLast("." + advice.getClazz().getName(), "."),
      advice.getMethod().getName()
  );
  return this;
}

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

@Override
public FlowSnippetDTO instantiateTemplate(String groupId, Double originX, Double originY, String encodingVersion,
                     FlowSnippetDTO requestSnippet, String idGenerationSeed) {
  ProcessGroup group = locateProcessGroup(flowController, groupId);
  try {
    // copy the template which pre-processes all ids
    FlowSnippetDTO snippet = snippetUtils.copy(requestSnippet, group, idGenerationSeed, false);
    // calculate scaling factors based on the template encoding version attempt to parse the encoding version.
    // get the major version, or 0 if no version could be parsed
    final FlowEncodingVersion templateEncodingVersion = FlowEncodingVersion.parse(encodingVersion);
    int templateEncodingMajorVersion = templateEncodingVersion != null ? templateEncodingVersion.getMajorVersion() : 0;
    // based on the major version < 1, use the default scaling factors.  Otherwise, don't scale (use factor of 1.0)
    double factorX = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_X : 1.0;
    double factorY = templateEncodingMajorVersion < 1 ? FlowController.DEFAULT_POSITION_SCALE_FACTOR_Y : 1.0;
    // reposition and scale the template contents
    org.apache.nifi.util.SnippetUtils.moveAndScaleSnippet(snippet, originX, originY, factorX, factorY);
    // find all the child process groups in each process group in the top level of this snippet
    final List<ProcessGroupDTO> childProcessGroups  = org.apache.nifi.util.SnippetUtils.findAllProcessGroups(snippet);
    // scale (but don't reposition) child process groups
    childProcessGroups.stream().forEach(processGroup -> org.apache.nifi.util.SnippetUtils.scaleSnippet(processGroup.getContents(), factorX, factorY));
    // instantiate the template into this group
    flowController.getFlowManager().instantiateSnippet(group, snippet);
    return snippet;
  } catch (ProcessorInstantiationException pie) {
    throw new NiFiCoreException(String.format("Unable to instantiate template because processor type '%s' is unknown to this NiFi.",
        StringUtils.substringAfterLast(pie.getMessage(), ".")));
  }
}

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

/** Returns the name of the executed test. */
private static String getTestName(IInvokedMethod method) {
 return StringUtils.substringAfterLast(method.getTestMethod().getTestClass().getName(), ".")
   + "#" + method.getTestMethod().getConstructorOrMethod().getName();
}

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

StringUtils.substringAfterLast(pie.getMessage(), ".")));

相关文章

微信公众号

最新文章

更多

StringUtils类方法