本文整理了Java中org.apache.commons.lang3.StringUtils.removeStart()
方法的一些代码示例,展示了StringUtils.removeStart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringUtils.removeStart()
方法的具体详情如下:
包路径:org.apache.commons.lang3.StringUtils
类名称:StringUtils
方法名:removeStart
[英]Removes a substring only if it is at the beginning of a source string, otherwise returns the source string.
A null source string will return null. An empty ("") source string will return the empty string. A null search string will return the source string.
StringUtils.removeStart(null, *) = null
StringUtils.removeStart("", *) = ""
StringUtils.removeStart(*, null) =
StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
StringUtils.removeStart("domain.com", "www.") = "domain.com"
StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStart("abc", "") = "abc"
[中]仅当子字符串位于源字符串的开头时才删除该子字符串,否则返回源字符串。
空源字符串将返回空值。空(“”)源字符串将返回空字符串。空搜索字符串将返回源字符串。
StringUtils.removeStart(null, *) = null
StringUtils.removeStart("", *) = ""
StringUtils.removeStart(*, null) =
StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
StringUtils.removeStart("domain.com", "www.") = "domain.com"
StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
StringUtils.removeStart("abc", "") = "abc"
代码示例来源:origin: apache/incubator-gobblin
/**
* {@link SlaEventKeys} have a prefix of {@link SlaEventKeys#EVENT_GOBBLIN_STATE_PREFIX} to keep properties organized
* in state. This method removes the prefix before submitting an Sla event.
*/
private String withoutPropertiesPrefix(String key) {
return StringUtils.removeStart(key, SlaEventKeys.EVENT_GOBBLIN_STATE_PREFIX);
}
代码示例来源:origin: joelittlejohn/jsonschema2pojo
private JsonNode resolveFromClasspath(URI uri) {
String path = removeStart(removeStart(uri.toString(), uri.getScheme() + ":"), "/");
InputStream contentAsStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
if (contentAsStream == null) {
throw new IllegalArgumentException("Couldn't read content from the classpath, file not found: " + uri);
}
try {
return objectMapper.readTree(contentAsStream);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Error parsing document: " + uri, e);
} catch (IOException e) {
throw new IllegalArgumentException("Unrecognised URI, can't resolve this: " + uri, e);
}
}
代码示例来源:origin: gocd/gocd
public static String subtractPath(File rootPath, File file) {
String fullPath = FilenameUtils.separatorsToUnix(file.getParentFile().getPath());
String basePath = FilenameUtils.separatorsToUnix(rootPath.getPath());
return StringUtils.removeStart(StringUtils.removeStart(fullPath, basePath), "/");
}
代码示例来源:origin: gocd/gocd
private String removeLeadingSlash(File artifactDest) {
return removeStart(FilenameUtils.separatorsToUnix(artifactDest.getPath()), "/");
}
}
代码示例来源:origin: gocd/gocd
private String removeLeadingSlash(File artifactDest) {
return removeStart(FilenameUtils.separatorsToUnix(artifactDest.getPath()), "/");
}
代码示例来源:origin: gocd/gocd
private Properties computeChecksumForContentsOfDirectory(File directory, String destPath) throws IOException {
Collection<File> fileStructure = FileUtils.listFiles(directory, null, true);
Properties checksumProperties = new Properties();
for (File file : fileStructure) {
String filePath = removeStart(file.getAbsolutePath(), directory.getParentFile().getAbsolutePath());
try (FileInputStream inputStream = new FileInputStream(file)) {
checksumProperties.setProperty(getEffectiveFileName(destPath, FilenameUtils.separatorsToUnix(filePath)), md5Hex(inputStream));
}
}
return checksumProperties;
}
代码示例来源:origin: gocd/gocd
private Properties computeChecksumForContentsOfDirectory(File directory, String destPath) throws IOException {
Collection<File> fileStructure = FileUtils.listFiles(directory, null, true);
Properties checksumProperties = new Properties();
for (File file : fileStructure) {
String filePath = removeStart(file.getAbsolutePath(), directory.getParentFile().getAbsolutePath());
try (FileInputStream inputStream = new FileInputStream(file)) {
checksumProperties.setProperty(getEffectiveFileName(destPath, FilenameUtils.separatorsToUnix(filePath)), md5Hex(inputStream));
}
}
return checksumProperties;
}
代码示例来源:origin: alibaba/nacos
@Override
public void onDelete(String key, String value) throws Exception {
String domKey = StringUtils.removeStart(key, UtilsAndCommons.DOMAINS_DATA_ID_PRE);
String namespace = domKey.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[0];
String name = domKey.split(UtilsAndCommons.SERVICE_GROUP_CONNECTOR)[1];
Domain dom = chooseDomMap(namespace).remove(name);
Loggers.RAFT.info("[RAFT-NOTIFIER] datum is deleted, key: {}, value: {}", key, value);
if (dom != null) {
dom.destroy();
Loggers.SRV_LOG.info("[DEAD-DOM] {}", dom.toJSON());
}
}
};
代码示例来源:origin: apache/incubator-gobblin
/***
* Extract token value from source entity, where token value is represented by a token in the source entity.
*
* Eg.
* Source Entity : prod_tableName_avro
* Source Template: prod_$LOGICAL_TABLE_avro
* Token : $LOGICAL_TABLE
* Extracted Value: tableName
*
* @param sourceEntity Source entity (typically a table or database name).
* @param sourceTemplate Source template representing the source entity.
* @param token Token representing the value to extract from the source entity using the template.
* @return Extracted token value from the source entity.
*/
@VisibleForTesting
protected static String extractTokenValueFromEntity(String sourceEntity, String sourceTemplate, String token) {
Preconditions.checkArgument(StringUtils.isNotBlank(sourceEntity), "Source entity should not be blank");
Preconditions.checkArgument(StringUtils.isNotBlank(sourceTemplate), "Source template should not be blank");
Preconditions.checkArgument(sourceTemplate.contains(token), String.format("Source template: %s should contain token: %s", sourceTemplate, token));
String extractedValue = sourceEntity;
List<String> preAndPostFix = Lists.newArrayList(Splitter.on(token).trimResults().split(sourceTemplate));
extractedValue = StringUtils.removeStart(extractedValue, preAndPostFix.get(0));
extractedValue = StringUtils.removeEnd(extractedValue, preAndPostFix.get(1));
return extractedValue;
}
代码示例来源:origin: pmd/pmd
private static String stripIndentation(String description) {
if (description == null || description.isEmpty()) {
return "";
}
String stripped = StringUtils.stripStart(description, "\n\r");
stripped = StringUtils.stripEnd(stripped, "\n\r ");
int indentation = 0;
int strLen = stripped.length();
while (Character.isWhitespace(stripped.charAt(indentation)) && indentation < strLen) {
indentation++;
}
String[] lines = stripped.split("\\n");
String prefix = StringUtils.repeat(' ', indentation);
StringBuilder result = new StringBuilder(stripped.length());
if (StringUtils.isNotEmpty(prefix)) {
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (i > 0) {
result.append(StringUtils.LF);
}
result.append(StringUtils.removeStart(line, prefix));
}
} else {
result.append(stripped);
}
return result.toString();
}
代码示例来源:origin: gocd/gocd
protected String destURL(File rootPath, File file, String src, String dest) {
String trimmedPattern = rtrimStandardrizedWildcardTokens(src);
if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) {
return dest;
}
String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern));
if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) {
trimmedPath = "/" + trimmedPath;
}
return dest + trimmedPath;
}
代码示例来源:origin: gocd/gocd
protected String destinationURL(File rootPath, File file, String src, String dest) {
String trimmedPattern = rtrimStandardrizedWildcardTokens(src);
if (StringUtils.equals(FilenameUtils.separatorsToUnix(trimmedPattern), FilenameUtils.separatorsToUnix(src))) {
return dest;
}
String trimmedPath = removeStart(subtractPath(rootPath, file), FilenameUtils.separatorsToUnix(trimmedPattern));
if (!StringUtils.startsWith(trimmedPath, "/") && StringUtils.isNotEmpty(trimmedPath)) {
trimmedPath = "/" + trimmedPath;
}
return dest + trimmedPath;
}
代码示例来源:origin: apache/incubator-gobblin
for (Entry<Object, Object> entry : props.entrySet()) {
if (StringUtils.startsWith(entry.getKey().toString(), SlaEventKeys.EVENT_ADDITIONAL_METADATA_PREFIX)) {
this.additionalMetadata.put(StringUtils.removeStart(entry.getKey().toString(),
SlaEventKeys.EVENT_ADDITIONAL_METADATA_PREFIX), entry.getValue().toString());
代码示例来源:origin: ming1016/study
JarEntry entry = em.nextElement();
if (entry.getName().startsWith(jarConnection.getEntryName())) {
String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName());
if (!fileName.equals("/")) { // exclude the directory
InputStream entryInputStream = null;
代码示例来源:origin: ming1016/study
JarEntry entry = em.nextElement();
if (entry.getName().startsWith(jarConnection.getEntryName())) {
String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName());
if (!fileName.equals("/")) { // exclude the directory
InputStream entryInputStream = null;
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testRemoveStart() {
// StringUtils.removeStart("", *) = ""
assertNull(StringUtils.removeStart(null, null));
assertNull(StringUtils.removeStart(null, ""));
assertNull(StringUtils.removeStart(null, "a"));
// StringUtils.removeStart(*, null) = *
assertEquals(StringUtils.removeStart("", null), "");
assertEquals(StringUtils.removeStart("", ""), "");
assertEquals(StringUtils.removeStart("", "a"), "");
// All others:
assertEquals(StringUtils.removeStart("www.domain.com", "www."), "domain.com");
assertEquals(StringUtils.removeStart("domain.com", "www."), "domain.com");
assertEquals(StringUtils.removeStart("domain.com", ""), "domain.com");
assertEquals(StringUtils.removeStart("domain.com", null), "domain.com");
}
代码示例来源:origin: geoserver/geoserver
if ((ss = StringUtils.removeStart(url, "resource:")) != url) {
return baseDirectory.get(ss);
代码示例来源:origin: apache/hbase
@Before
public void setUp() throws Exception {
Configuration c = TEST_UTIL.getConfiguration();
c.setBoolean("dfs.support.append", true);
TEST_UTIL.startMiniCluster(1);
table = TEST_UTIL.createMultiRegionTable(TABLE_NAME, FAMILY);
TEST_UTIL.loadTable(table, FAMILY);
// setup the hdfssnapshots
client = new DFSClient(TEST_UTIL.getDFSCluster().getURI(), TEST_UTIL.getConfiguration());
String fullUrIPath = TEST_UTIL.getDefaultRootDirPath().toString();
String uriString = TEST_UTIL.getTestFileSystem().getUri().toString();
baseDir = StringUtils.removeStart(fullUrIPath, uriString);
client.allowSnapshot(baseDir);
}
代码示例来源:origin: Teradata/kylo
public String decrypt(String str) {
if (StringUtils.isNotBlank(str)) {
if (StringUtils.startsWith(str, CIPHER_PREFIX)) {
str = StringUtils.removeStart(str, CIPHER_PREFIX);
}
return encryptor.decrypt(str);
} else {
return str;
}
}
代码示例来源:origin: spring-projects/spring-roo
private String getModuleName(final String pomDirectory) {
final String normalisedRootPath = FileUtils.ensureTrailingSeparator(projectRootDirectory);
final String normalisedPomDirectory = FileUtils.ensureTrailingSeparator(pomDirectory);
final String moduleDirectory =
StringUtils.removeStart(normalisedPomDirectory, normalisedRootPath);
return FilenameUtils.getBaseName(StringUtils.stripEnd(moduleDirectory, SEPARATOR));
}
内容来源于网络,如有侵权,请联系作者删除!