/** * Returns the package name of {@code classFullName} according to the Java Language Specification * (section 6.7). Unlike {@link Class#getPackage}, this method only parses the class name, without * attempting to define the {@link Package} and hence load files. */ public static String getPackageName(String classFullName) { int lastDot = classFullName.lastIndexOf('.'); return (lastDot < 0) ? "" : classFullName.substring(0, lastDot); }
/** * Unqualify a string qualified by a separator character. For example, * "this:name:is:qualified" returns "qualified" if using a ':' separator. * @param qualifiedName the qualified name * @param separator the separator */ public static String unqualify(String qualifiedName, char separator) { return qualifiedName.substring(qualifiedName.lastIndexOf(separator) + 1); }
/** * Determine the name of the package of the given fully-qualified class name, * e.g. "java.lang" for the {@code java.lang.String} class name. * @param fqClassName the fully-qualified class name * @return the package name, or the empty String if the class * is defined in the default package */ public static String getPackageName(String fqClassName) { Assert.notNull(fqClassName, "Class name must not be null"); int lastDotIndex = fqClassName.lastIndexOf(PACKAGE_SEPARATOR); return (lastDotIndex != -1 ? fqClassName.substring(0, lastDotIndex) : ""); }
/** * Extract the URL filename from the given request URI. * @param uri the request URI; for example {@code "/index.html"} * @return the extracted URI filename; for example {@code "index"} */ protected String extractViewNameFromUrlPath(String uri) { int start = (uri.charAt(0) == '/' ? 1 : 0); int lastIndex = uri.lastIndexOf('.'); int end = (lastIndex < 0 ? uri.length() : lastIndex); return uri.substring(start, end); }
/** * Determine the name of the class file, relative to the containing * package: e.g. "String.class" * @param clazz the class * @return the file name of the ".class" file */ public static String getClassFileName(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); String className = clazz.getName(); int lastDotIndex = className.lastIndexOf(PACKAGE_SEPARATOR); return className.substring(lastDotIndex + 1) + CLASS_FILE_SUFFIX; }
public static String simpleClassName(Class<?> clazz) { if (clazz == null) { throw new NullPointerException("clazz"); } String className = clazz.getName(); final int lastDotIdx = className.lastIndexOf(PACKAGE_SEPARATOR_CHAR); if (lastDotIdx > -1) { return className.substring(lastDotIdx + 1); } return className; }
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; }
@Override public String extractVersion(String requestPath) { Matcher matcher = pattern.matcher(requestPath); if (matcher.find()) { String match = matcher.group(1); return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match); } else { return null; } }
@Override @Nullable public String extractVersion(String requestPath) { Matcher matcher = pattern.matcher(requestPath); if (matcher.find()) { String match = matcher.group(1); return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match); } else { return null; } }
private String getEntityName(Class<?> entityClass) { String shortName = ClassUtils.getShortName(entityClass); int lastDot = shortName.lastIndexOf('.'); if (lastDot != -1) { return shortName.substring(lastDot + 1); } else { return shortName; } }
@Override public int lastIndexOf(@Nullable Object object) { return (object instanceof Character) ? string.lastIndexOf((Character) object) : -1; }
private static @Nullable String convertDottedQuadToHex(String ipString) { int lastColon = ipString.lastIndexOf(':'); String initialPart = ipString.substring(0, lastColon + 1); String dottedQuad = ipString.substring(lastColon + 1); byte[] quad = textToNumericFormatV4(dottedQuad); if (quad == null) { return null; } String penultimate = Integer.toHexString(((quad[0] & 0xff) << 8) | (quad[1] & 0xff)); String ultimate = Integer.toHexString(((quad[2] & 0xff) << 8) | (quad[3] & 0xff)); return initialPart + penultimate + ":" + ultimate; }
public URL setAddress(String address) { int i = address.lastIndexOf(':'); String host; int port = this.port; if (i >= 0) { host = address.substring(0, i); port = Integer.parseInt(address.substring(i + 1)); } else { host = address; } return new URL(protocol, username, password, host, port, path, getParameters()); }
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); } }
private void adaptForwardedHost(String hostToUse) { int portSeparatorIdx = hostToUse.lastIndexOf(':'); if (portSeparatorIdx > hostToUse.lastIndexOf(']')) { host(hostToUse.substring(0, portSeparatorIdx)); port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1))); } else { host(hostToUse); port(null); } }
private List<URL> toUrlsWithEmpty(URL consumer, String path, List<String> providers) { List<URL> urls = toUrlsWithoutEmpty(consumer, providers); if (urls == null || urls.isEmpty()) { int i = path.lastIndexOf(Constants.PATH_SEPARATOR); String category = i < 0 ? path : path.substring(i + 1); URL empty = consumer.setProtocol(Constants.EMPTY_PROTOCOL).addParameter(Constants.CATEGORY_KEY, category); urls.add(empty); } return urls; }
private String getInputTag(String output) { int inputStart = output.indexOf("<", 1); int inputEnd = output.lastIndexOf(">", output.length() - 2); return output.substring(inputStart, inputEnd + 1); }
private String getFormTag(String output) { int inputStart = output.indexOf("<", 1); int inputEnd = output.lastIndexOf(">", output.length() - 2); return output.substring(0, inputStart) + output.substring(inputEnd + 1); }
@Nullable private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) { if (path != null) { path = getUrlPathHelper().decodeRequestString(request, path); if (path.charAt(0) != '/') { String requestUri = getUrlPathHelper().getRequestUri(request); path = requestUri.substring(0, requestUri.lastIndexOf('/') + 1) + path; path = StringUtils.cleanPath(path); } } return path; }
protected final void assertBlockTagContains(String output, String desiredContents) { String contents = output.substring(output.indexOf(">") + 1, output.lastIndexOf("<")); assertTrue("Expected to find '" + desiredContents + "' in the contents of block tag '" + output + "'", contents.contains(desiredContents)); }