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; }
private void receive(String msg, InetSocketAddress remoteAddress) throws RemotingException { if (msg.startsWith(JOIN)) { String url = msg.substring(JOIN.length()).trim(); connect(URL.valueOf(url)); } else if (msg.startsWith(LEAVE)) { String url = msg.substring(LEAVE.length()).trim(); disconnect(URL.valueOf(url)); } }
@Override public String toString() { return String.format("Oliphaunt id=%d", id); } }
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); }
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; } }
/** * Returns the next index in {@code input} at or after {@code pos} that contains a character from * {@code characters}. Returns the input length if none of the requested characters can be found. */ public static int skipUntil(String input, int pos, String characters) { for (; pos < input.length(); pos++) { if (characters.indexOf(input.charAt(pos)) != -1) { break; } } return pos; }
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; }
private String toServicePath(String categoryPath) { int i; if (categoryPath.startsWith(root)) { i = categoryPath.indexOf(Constants.PATH_SEPARATOR, root.length()); } else { i = categoryPath.indexOf(Constants.PATH_SEPARATOR); } return i > 0 ? categoryPath.substring(0, i) : categoryPath; }
private String getInputTag(String output) { int inputStart = output.indexOf("<", 1); int inputEnd = output.lastIndexOf(">", output.length() - 2); return output.substring(inputStart, inputEnd + 1); }
private int nextReferredCharacterId() throws IOException { String reference = nextWordToken(); if (reference != null && reference.startsWith("&#") && reference.endsWith(";")) { return Integer.parseInt(reference.substring(2, reference.length() - 1)); } return -1; }
private String extractSessionId(HttpHeaders headers) { List<String> headerValues = headers.get("Set-Cookie"); assertNotNull(headerValues); assertEquals(1, headerValues.size()); for (String s : headerValues.get(0).split(";")){ if (s.startsWith("SESSION=")) { return s.substring("SESSION=".length()); } } return null; }
private static void assertValidContextPath(String contextPath) { Assert.hasText(contextPath, "Context path must not be empty"); if (contextPath.equals("/")) { return; } Assert.isTrue(contextPath.startsWith("/"), "Context path must begin with '/'"); Assert.isTrue(!contextPath.endsWith("/"), "Context path must not end with '/'"); }
private boolean isQuotedString(String s) { if (s.length() < 2) { return false; } else { return ((s.startsWith("\"") && s.endsWith("\"")) || (s.startsWith("'") && s.endsWith("'"))); } }
public static Method findMethod(String desc, ClassLoader loader) { try { int lparen = desc.indexOf('('); int dot = desc.lastIndexOf('.', lparen); String className = desc.substring(0, dot).trim(); String methodName = desc.substring(dot + 1, lparen).trim(); return getClass(className, loader).getDeclaredMethod(methodName, parseTypes(desc, loader)); } catch (ClassNotFoundException | NoSuchMethodException ex) { throw new CodeGenerationException(ex); } }
/** Add an header line containing a field name, a literal colon, and a value. */ public Builder add(String line) { int index = line.indexOf(":"); if (index == -1) { throw new IllegalArgumentException("Unexpected header: " + line); } return add(line.substring(0, index).trim(), line.substring(index + 1)); }
/** * Return the actual property name for the given property path. * @param propertyPath the property path to determine the property name * for (can include property keys, for example for specifying a map entry) * @return the actual property name, without any key elements */ public static String getPropertyName(String propertyPath) { int separatorIndex = (propertyPath.endsWith(PropertyAccessor.PROPERTY_KEY_SUFFIX) ? propertyPath.indexOf(PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR) : -1); return (separatorIndex != -1 ? propertyPath.substring(0, separatorIndex) : propertyPath); }
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. }