List of usage examples for java.lang CharSequence toString
public String toString();
From source file:com.sawyer.advadapters.app.adapters.jsonadapter.UnitTestMovieAdapter.java
@SuppressWarnings("UnusedDeclaration") private boolean isFilteredOut(JSONObject item, CharSequence constraint) { String title = item.optString(MovieItem.JSON_TITLE).toLowerCase(Locale.US); return !title.contains(constraint.toString().toLowerCase(Locale.US)); }
From source file:cn.org.once.cstack.utils.CustomPasswordEncoder.java
public String decode(CharSequence pass) { Cipher cipher;//from w w w .j a v a2 s . c o m String decryptString = null; try { byte[] encryptText = Base64.decodeBase64(pass.toString()); cipher = Cipher.getInstance(ALGO); cipher.init(Cipher.DECRYPT_MODE, generateKey()); decryptString = new String(cipher.doFinal(encryptText)); } catch (Exception e) { e.printStackTrace(); } return decryptString; }
From source file:org.cleverbus.common.Strings.java
/** * Replace all occurrences of one string replaceWith another string. * * @param s//w w w . j a v a2s. c o m * The string to process * @param searchFor * The value to search for * @param replaceWith * The value to searchFor replaceWith * @return The resulting string with searchFor replaced with replaceWith */ public static CharSequence replaceAll(CharSequence s, CharSequence searchFor, CharSequence replaceWith) { if (s == null) { return null; } // If searchFor is null or the empty string, then there is nothing to // replace, so returning s is the only option here. if ((searchFor == null) || EMPTY.equals(searchFor)) { return s; } // If replaceWith is null, then the searchFor should be replaced with // nothing, which can be seen as the empty string. if (replaceWith == null) { replaceWith = EMPTY; } String searchString = searchFor.toString(); // Look for first occurrence of searchFor int matchIndex = search(s, searchString, 0); if (matchIndex == -1) { // No replace operation needs to happen return s; } else { // Allocate a AppendingStringBuffer that will hold one replacement // with a // little extra room. int size = s.length(); final int replaceWithLength = replaceWith.length(); final int searchForLength = searchFor.length(); if (replaceWithLength > searchForLength) { size += (replaceWithLength - searchForLength); } final StringBuilder sb = new StringBuilder(size + 16); int pos = 0; do { // Append text up to the match` append(sb, s, pos, matchIndex); // Add replaceWith text sb.append(replaceWith); // Find next occurrence, if any pos = matchIndex + searchForLength; matchIndex = search(s, searchString, pos); } while (matchIndex != -1); // Add tail of s sb.append(s.subSequence(pos, s.length())); // Return processed buffer return sb; } }
From source file:com.google.visualization.datasource.DataSourceHelper.java
/** * Generates an error response string for the given <code>ResponseStatus</code>. * Render the <code>ResponseStatus</code> to an error response according to the * <code>OutputType</code> specified in the <code>DataSourceRequest</code>. * * @param responseStatus The response status. * @param dsRequest The DataSourceRequest. * * @return The error response string./*from w ww. j av a 2s. c om*/ * * @throws IOException In case if I/O errors. */ public static String generateErrorResponse(ResponseStatus responseStatus, DataSourceRequest dsRequest) throws IOException { DataSourceParameters dsParameters = dsRequest.getDataSourceParameters(); CharSequence response; switch (dsParameters.getOutputType()) { case CSV: case TSV_EXCEL: response = CsvRenderer.renderCsvError(responseStatus); break; case HTML: response = HtmlRenderer.renderHtmlError(responseStatus); break; case JSONP: response = JsonRenderer.renderJsonResponse(dsParameters, responseStatus, null); break; case JSON: response = JsonRenderer.renderJsonResponse(dsParameters, responseStatus, null); break; default: // This should never happen. throw new RuntimeException("Unhandled output type."); } return response.toString(); }
From source file:com.stephengream.simplecms.authentication.SimpleCmsPasswordEncoder.java
@Override public boolean matches(CharSequence submitted, String retrieved) { try {/*from w ww. ja v a 2 s . c o m*/ //String hash = PasswordHash.createHash(submitted.toString()); return PasswordHash.validatePassword(submitted.toString(), retrieved); } catch (NoSuchAlgorithmException | InvalidKeySpecException ex) { Logger.getLogger(SimpleCmsPasswordEncoder.class.getName()).log(Level.SEVERE, null, ex); } return false; }
From source file:com.wibidata.shopping.servlet.ProductServlet.java
/** * Parses an Avro DescriptionWords record into a regular list of strings so * it can be safely rendered in a JSP page. * * @param words The description_words avro record from the Wibi table. * @return A list of strings./*from ww w . jav a 2 s.co m*/ */ private List<String> getWords(DescriptionWords words) { List<String> wordList = new ArrayList<String>(); if (null != words.getWords()) { for (CharSequence word : words.getWords()) { wordList.add(word.toString()); } } return wordList; }
From source file:kz.supershiny.web.wicket.TiresApplication.java
protected WebResponse newWebResponse(final WebRequest webRequest, final HttpServletResponse httpServletResponse) { return new ServletWebResponse((ServletWebRequest) webRequest, httpServletResponse) { @Override/*from ww w . j a va 2 s . c o m*/ public String encodeURL(CharSequence url) { return isRobot(webRequest) ? url.toString() : super.encodeURL(url); } @Override public String encodeRedirectURL(CharSequence url) { return isRobot(webRequest) ? url.toString() : super.encodeRedirectURL(url); } private boolean isRobot(WebRequest request) { final String agent = webRequest.getHeader("User-Agent"); return isAgent(agent); } }; }
From source file:ch.unibe.cde.geonet.kernel.security.Md5PasswordEncoder.java
@Override public boolean matches(CharSequence rawSequence, String encodedPassword) { try {// w w w . j a v a 2 s . co m MessageDigest md = MessageDigest.getInstance("MD5"); md.reset(); md.update(rawSequence.toString().getBytes("UTF-8")); return ("md5:" + Md5PasswordEncoder.byteToHex(md.digest())).equals(encodedPassword); } catch (UnsupportedEncodingException | NoSuchAlgorithmException ex) { Log.error(Log.JEEVES, ex); } return false; }
From source file:com.cloudera.flume.handlers.avro.AvroEventAdaptor.java
@Override public Map<String, byte[]> getAttrs() { if (evt.fields == null) { return Collections.<String, byte[]>emptyMap(); }//from w w w . jav a 2 s . c om HashMap<String, byte[]> tempMap = new HashMap<String, byte[]>(); for (CharSequence u : evt.fields.keySet()) { tempMap.put(u.toString(), evt.fields.get(u).array()); } return tempMap; }
From source file:com.genericconf.bbbgateway.services.ApiCallExecution.java
@SuppressWarnings("unchecked") final Map<String, Object> getXmlFromApi(HttpClient httpClient, String url) throws Exception { CharSequence rawxml = makeHttpRequest(httpClient, url); Map<String, Object> xml = (Map<String, Object>) XSTREAM.fromXML(rawxml.toString()); if (!wasSuccess(xml)) { logger.error("Call was unsuccessful. Here is the XML:\n" + xml); }/*w w w. j a v a2 s .c o m*/ return xml; }