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; } }
public Builder path(String path) { if (!path.startsWith("/")) throw new IllegalArgumentException("path must start with '/'"); this.path = path; return this; }
private int skipSeparator(String path, int pos, String separator) { int skipped = 0; while (path.startsWith(separator, pos + skipped)) { skipped += separator.length(); } return skipped; }
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; }
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. }
/** * 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())))); }
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); }
@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(); } } }
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; }
@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); } }
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; }
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; }
/** * 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"); }
@Override public String apply(Integer t) { assertTrue(Thread.currentThread().getName().startsWith("RxCachedThreadScheduler")); return "Value_" + t + "_Thread_" + Thread.currentThread().getName(); } });
@Override public String apply(Integer t) { assertTrue(Thread.currentThread().getName().startsWith("RxComputationThreadPool")); return "Value_" + t + "_Thread_" + Thread.currentThread().getName(); } });
/** * 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"); } }
@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(); } });
@Before public void before() { stringSubscriber = TestHelper.mockSubscriber(); for (Thread t : Thread.getAllStackTraces().keySet()) { if (t.getName().startsWith("RxNewThread")) { count++; } } }
@Before public void before() { stringObserver = TestHelper.mockObserver(); for (Thread t : Thread.getAllStackTraces().keySet()) { if (t.getName().startsWith("RxNewThread")) { count++; } } }
@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")); }