本文整理了Java中java.lang.String.startsWith()
方法的一些代码示例,展示了String.startsWith()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。String.startsWith()
方法的具体详情如下:
包路径:java.lang.String
类名称:String
方法名:startsWith
[英]Tests if this string starts with the specified prefix.
[中]
代码示例来源:origin: square/okhttp
private static String secondaryName(String javaName) {
if (javaName.startsWith("TLS_")) {
return "SSL_" + javaName.substring(4);
} else if (javaName.startsWith("SSL_")) {
return "TLS_" + javaName.substring(4);
} else {
return javaName;
}
}
代码示例来源:origin: square/okhttp
public Builder path(String path) {
if (!path.startsWith("/")) throw new IllegalArgumentException("path must start with '/'");
this.path = path;
return this;
}
代码示例来源:origin: spring-projects/spring-framework
private int skipSeparator(String path, int pos, String separator) {
int skipped = 0;
while (path.startsWith(separator, pos + skipped)) {
skipped += separator.length();
}
return skipped;
}
代码示例来源:origin: google/guava
private static byte parseOctet(String ipPart) {
// Note: we already verified that this string contains only hex digits.
int octet = Integer.parseInt(ipPart);
// Disallow leading zeroes, because no clear standard exists on
// whether these should be interpreted as decimal or octal.
if (octet > 255 || (ipPart.startsWith("0") && ipPart.length() > 1)) {
throw new NumberFormatException();
}
return (byte) octet;
}
代码示例来源:origin: stackoverflow.com
String contentType = connection.getHeaderField("Content-Type");
String charset = null;
for (String param : contentType.replace(" ", "").split(";")) {
if (param.startsWith("charset=")) {
charset = param.split("=", 2)[1];
break;
}
}
if (charset != null) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(response, charset))) {
for (String line; (line = reader.readLine()) != null;) {
// ... System.out.println(line) ?
}
}
} else {
// It's likely binary content, use InputStream/OutputStream.
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Indicates whether or not a particular bean name is present in the excluded beans list.
*/
private boolean isExcluded(String beanName) {
return (this.excludedBeans.contains(beanName) ||
(beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX) &&
this.excludedBeans.contains(beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length()))));
}
代码示例来源:origin: square/okhttp
boolean matches(String hostname) {
if (pattern.startsWith(WILDCARD)) {
int firstDot = hostname.indexOf('.');
return (hostname.length() - firstDot - 1) == canonicalHostname.length()
&& hostname.regionMatches(false, firstDot + 1, canonicalHostname, 0,
canonicalHostname.length());
}
return hostname.equals(canonicalHostname);
}
代码示例来源:origin: square/okhttp
@Override public void deleteContents(File directory) throws IOException {
String prefix = directory.toString() + "/";
for (Iterator<File> i = files.keySet().iterator(); i.hasNext(); ) {
File file = i.next();
if (file.toString().startsWith(prefix)) i.remove();
}
}
}
代码示例来源:origin: stackoverflow.com
private static String getSubmittedFileName(Part part) {
for (String cd : part.getHeader("content-disposition").split(";")) {
if (cd.trim().startsWith("filename")) {
String fileName = cd.substring(cd.indexOf('=') + 1).trim().replace("\"", "");
return fileName.substring(fileName.lastIndexOf('/') + 1).substring(fileName.lastIndexOf('\\') + 1); // MSIE fix.
}
}
return null;
}
代码示例来源:origin: square/okhttp
@FromJson HttpUrl urlFromJson(String urlString) {
if (urlString.startsWith("wss:")) urlString = "https:" + urlString.substring(4);
if (urlString.startsWith("ws:")) urlString = "http:" + urlString.substring(3);
return HttpUrl.get(urlString);
}
}
代码示例来源:origin: square/okhttp
public Builder encodedPath(String encodedPath) {
if (encodedPath == null) throw new NullPointerException("encodedPath == null");
if (!encodedPath.startsWith("/")) {
throw new IllegalArgumentException("unexpected encodedPath: " + encodedPath);
}
resolvePath(encodedPath, 0, encodedPath.length());
return this;
}
代码示例来源:origin: square/okhttp
private static boolean pathMatch(HttpUrl url, String path) {
String urlPath = url.encodedPath();
if (urlPath.equals(path)) {
return true; // As in '/foo' matching '/foo'.
}
if (urlPath.startsWith(path)) {
if (path.endsWith("/")) return true; // As in '/' matching '/foo'.
if (urlPath.charAt(path.length()) == '/') return true; // As in '/foo' matching '/foo/bar'.
}
return false;
}
代码示例来源:origin: google/guava
/**
* Identifies just enterIfXxx methods (a subset of {@link #isAnyEnter}), which are mostly like the
* enterXxx methods but behave like tryEnterXxx in some scenarios.
*/
private static boolean isEnterIf(Method method) {
return method.getName().startsWith("enterIf");
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public String apply(Integer t) {
assertTrue(Thread.currentThread().getName().startsWith("RxCachedThreadScheduler"));
return "Value_" + t + "_Thread_" + Thread.currentThread().getName();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public String apply(Integer t) {
assertTrue(Thread.currentThread().getName().startsWith("RxComputationThreadPool"));
return "Value_" + t + "_Thread_" + Thread.currentThread().getName();
}
});
代码示例来源:origin: google/guava
/**
* These tests fail in JDK 9 and JDK 10 for an unknown reason. It might be the test; it might be
* the underlying functionality. Fixing this is not a high priority; if you need it to be fixed,
* please comment on <a href="https://github.com/google/guava/issues/3086">issue 3086</a>.
*/
private static boolean isJdk9OrHigher() {
return JAVA_SPECIFICATION_VERSION.value().startsWith("9")
|| JAVA_SPECIFICATION_VERSION.value().startsWith("10");
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public String apply(Integer t) {
assertFalse(Thread.currentThread().getName().equals(currentThreadName));
assertTrue(Thread.currentThread().getName().startsWith("RxComputationThreadPool"));
return "Value_" + t + "_Thread_" + Thread.currentThread().getName();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Before
public void before() {
stringSubscriber = TestHelper.mockSubscriber();
for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().startsWith("RxNewThread")) {
count++;
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@Before
public void before() {
stringObserver = TestHelper.mockObserver();
for (Thread t : Thread.getAllStackTraces().keySet()) {
if (t.getName().startsWith("RxNewThread")) {
count++;
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void subscribeOnNormal() {
final AtomicReference<String> name = new AtomicReference<String>();
Completable c = Completable.unsafeCreate(new CompletableSource() {
@Override
public void subscribe(CompletableObserver observer) {
name.set(Thread.currentThread().getName());
EmptyDisposable.complete(observer);
}
}).subscribeOn(Schedulers.computation());
c.blockingAwait();
Assert.assertTrue(name.get().startsWith("RxComputation"));
}
内容来源于网络,如有侵权,请联系作者删除!