List of usage examples for java.lang CharSequence length
int length();
From source file:com.taobao.android.object.DexDiffInfo.java
private static String getParamsType(List<? extends CharSequence> parameterTypes) { StringBuilder params = new StringBuilder(); for (CharSequence charSequence : parameterTypes) { boolean isArray = false; String s = null;//from ww w . j a va 2 s .co m if (charSequence.toString().startsWith("[")) { s = charSequence.subSequence(1, charSequence.length()).toString(); isArray = true; } else { s = charSequence.toString(); } if (!APatchTool.mappingMap.containsValue(s)) { params.append(isArray ? "[" + s + "|" : s + "|"); continue; } else { for (Map.Entry<String, String> entry : APatchTool.mappingMap.entrySet()) { if (entry.getValue().equals(charSequence.toString())) { params.append(isArray ? "[" + entry.getKey() + "|" : entry.getKey() + "|"); } } } } if (params.length() > 1) { return "[" + params.substring(0, params.length() - 1).toString() + "]"; } else { return "[" + params.toString() + "]"; } }
From source file:com.fuseim.webapp.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the URI class for the * spec./*from w ww . j av a 2 s .c o m*/ * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) { //not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c); //TODO } } return outBuf != null ? outBuf : in; }
From source file:io.hops.hopsworks.api.kibana.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * <p>/*from w w w . j a v a 2 s . c o m*/ * <p> * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses * Java's {@link URI}. * To be more forgiving, we must escape the problematic characters. See the * URI class for the * spec. * * @param in example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape //pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) { outBuf.append(c); } } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO } } return outBuf != null ? outBuf : in; }
From source file:com.liferay.events.global.mobile.Utils.java
/** * Gets a set of matching characters between two strings. * <p/>//from ww w . j a va 2s. com * <p><Two characters from the first string and the second string are considered matching if the character's * respective positions are no farther than the limit value.</p> * * @param first The first string. * @param second The second string. * @param limit The maximum distance to consider. * @return A string contain the set of common characters. */ private static String getSetOfMatchingCharacterWithin(final CharSequence first, final CharSequence second, final int limit) { final StringBuilder common = new StringBuilder(); final StringBuilder copy = new StringBuilder(second); for (int i = 0; i < first.length(); i++) { final char ch = first.charAt(i); boolean found = false; // See if the character is within the limit positions away from the original position of that character. for (int j = Math.max(0, i - limit); !found && j < Math.min(i + limit, second.length()); j++) { if (copy.charAt(j) == ch) { found = true; common.append(ch); copy.setCharAt(j, '*'); } } } return common.toString(); }
From source file:com.google.gwt.jolokia.server.servlet.ProxyServlet.java
/** * Encodes characters in the query or fragment part of the URI. * * <p>/*from ww w . ja v a 2s.co m*/ * Unfortunately, an incoming URI sometimes has characters disallowed by the * spec. HttpClient insists that the outgoing proxied request has a valid * URI because it uses Java's {@link URI}. To be more forgiving, we must * escape the problematic characters. See the URI class for the spec. * * @param in * example: name=value&foo=bar#fragment */ protected static CharSequence encodeUriQuery(CharSequence in) { // Note that I can't simply use URI.java to encode because it will // escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {// not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { // escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } // leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);// TODO } } return outBuf != null ? outBuf : in; }
From source file:org.opengeoportal.proxy.controllers.DynamicOgcController.java
/** * <p>Encodes characters in the query or fragment part of the URI. * * <p>Unfortunately, an incoming URI sometimes has characters disallowed by the spec. HttpClient * insists that the outgoing proxied request has a valid URI because it uses Java's {@link URI}. To be more * forgiving, we must escape the problematic characters. See the URI class for the spec. * * @param in example: name=value&foo=bar#fragment *//* w w w .j av a 2 s . c om*/ static CharSequence encodeUriQuery(CharSequence in) { //Note that I can't simply use URI.java to encode because it will escape pre-existing escaped things. StringBuilder outBuf = null; Formatter formatter = null; for (int i = 0; i < in.length(); i++) { char c = in.charAt(i); boolean escape = true; if (c < 128) { if (asciiQueryChars.get((int) c)) { escape = false; } } else if (!Character.isISOControl(c) && !Character.isSpaceChar(c)) {//not-ascii escape = false; } if (!escape) { if (outBuf != null) outBuf.append(c); } else { //escape if (outBuf == null) { outBuf = new StringBuilder(in.length() + 5 * 3); outBuf.append(in, 0, i); formatter = new Formatter(outBuf); } //leading %, 0 padded, width 2, capital hex formatter.format("%%%02X", (int) c);//TODO formatter.close(); } } return outBuf != null ? outBuf : in; }
From source file:jetx.ext.common.StringMethods.java
public static boolean isEmpty2(CharSequence cs) { return cs == null || cs.length() == 0; }
From source file:eu.stratosphere.types.StringValue.java
public static final void writeString(CharSequence cs, DataOutput out) throws IOException { if (cs != null) { // the length we write is offset by one, because a length of zero indicates a null value int lenToWrite = cs.length() + 1; if (lenToWrite < 0) { throw new IllegalArgumentException("CharSequence is too long."); }/*from w ww.j ava2s . co m*/ // write the length, variable-length encoded while (lenToWrite >= HIGH_BIT) { out.write(lenToWrite | HIGH_BIT); lenToWrite >>>= 7; } out.write(lenToWrite); // write the char data, variable length encoded for (int i = 0; i < cs.length(); i++) { int c = cs.charAt(i); while (c >= HIGH_BIT) { out.write(c | HIGH_BIT); c >>>= 7; } out.write(c); } } else { out.write(0); } }
From source file:com.beto.test.securityinterceptor.security.PasswordEncoder.java
@Override public String encode(CharSequence rawPassword) { logger.debug("RAW PASS :" + rawPassword.length()); return rawPassword.toString(); }
From source file:jetx.ext.common.StringMethods.java
/** * <p>Checks if the CharSequence contains only ASCII printable characters.</p> * * <p>{@code null} will return {@code false}. * An empty CharSequence (length()=0) will return {@code true}.</p> * * <pre>//from w ww. j av a 2 s . c o m * StringMethods.isAsciiPrintable(null) = false * StringMethods.isAsciiPrintable("") = true * StringMethods.isAsciiPrintable(" ") = true * StringMethods.isAsciiPrintable("Ceki") = true * StringMethods.isAsciiPrintable("ab2c") = true * StringMethods.isAsciiPrintable("!ab-c~") = true * StringMethods.isAsciiPrintable("\u0020") = true * StringMethods.isAsciiPrintable("\u0021") = true * StringMethods.isAsciiPrintable("\u007e") = true * StringMethods.isAsciiPrintable("\u007f") = false * StringMethods.isAsciiPrintable("Ceki G\u00fclc\u00fc") = false * </pre> * * @param cs the CharSequence to check, may be null * @return {@code true} if every character is in the range * 32 thru 126 */ public static boolean isAsciiPrintable(CharSequence cs) { if (cs == null) { return false; } int sz = cs.length(); for (int i = 0; i < sz; i++) { if ((cs.charAt(i) >= 32 && cs.charAt(i) < 127) == false) { return false; } } return true; }