List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:com.normsstuff.maps4norm.Util.java
/** * Get the altitude data for a specific point * * @param p the point to get the altitude for * @param httpClient can be null if no network query should be performed * @param localContext can be null if no network query should be performed * @return the altitude at point p or -Float.MAX_VALUE if no valid data * could be fetched/* w w w. ja va 2 s .c o m*/ * @throws IOException */ static float getAltitude(final LatLng p, final HttpClient httpClient, final HttpContext localContext) throws IOException { if (elevationCache == null) { elevationCache = new HashMap<LatLng, Float>(30); } if (elevationCache.containsKey(p)) { return elevationCache.get(p); } else if (httpClient != null && localContext != null) { float altitude = -Float.MAX_VALUE; String url = "http://maps.googleapis.com/maps/api/elevation/xml?locations=" + String.valueOf(p.latitude) + "," + String.valueOf(p.longitude) + "&sensor=true"; HttpGet httpGet = new HttpGet(url); HttpResponse response = httpClient.execute(httpGet, localContext); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); int r; StringBuilder respStr = new StringBuilder(); while ((r = instream.read()) != -1) respStr.append((char) r); String tagOpen = "<elevation>"; String tagClose = "</elevation>"; if (respStr.indexOf(tagOpen) != -1) { int start = respStr.indexOf(tagOpen) + tagOpen.length(); int end = respStr.indexOf(tagClose); altitude = Float.parseFloat(respStr.substring(start, end)); elevationCache.put(p, altitude); } instream.close(); } return altitude; } else { return elevationCache.get(p); } }
From source file:wptools.cmds.FragToHtml.java
private static void emitBody(String body) { // Get a buffer to play with. StringBuilder buf = new StringBuilder(body); // Normalize newlines. gsub(buf, "\r\n", "\n"); gsub(buf, "\r", "\n"); int len = buf.length(); if (len > 0 && buf.charAt(len - 1) != '\n') buf.append('\n'); // If we don't start with a tag or a double newline, we need // to force a leading paragraph tag. if (buf.length() > 0 && buf.charAt(0) != '<' && buf.indexOf("\n\n") != 0) buf.insert(0, "<p>"); // Add paragraph tags at double line breaks. gsub(buf, "\n\n", "\n<p>"); // Localize newlines, if needed. String localNl = System.lineSeparator(); if (!"\n".equals(localNl)) gsub(buf, "\n", localNl); // Emit the output. out.print(buf.toString());// w w w . j av a2 s . c o m }
From source file:org.dcache.xrootd.plugins.authn.gsi.CertUtil.java
/** * Decodes PEM by removing the given header and footer, and decodes * the inner content with base64./* w ww.ja va 2s.com*/ * @param pem the full PEM-encoded data including header + footer * @param header the header to be striped off * @param footer the footer to be striped off * @return the content in DER format */ public static byte[] fromPEM(String pem, String header, String footer) { if (!pem.startsWith(header)) { throw new IllegalArgumentException("The provided PEM string doesn't start with '" + header + "'"); } // strip header StringBuilder sb = new StringBuilder(pem); sb.delete(0, header.length()); removeChar(sb, '\n'); // remove footer if (!sb.subSequence(sb.length() - footer.length(), sb.length()).equals(footer)) { throw new IllegalArgumentException("The provided PEM string doesn't end with '" + footer + "'"); } sb.delete(sb.indexOf(footer), sb.length()); // finally decode base64 return Base64.decodeBase64(sb.toString()); }
From source file:com.melani.utils.ProjectHelpers.java
public static String parsearCaracteresEspecialesXML1(String xmlaParsear) { String xml = "No paso Nada"; StringBuilder sb = null; try {//ww w . ja va 2 s . c o m sb = new StringBuilder(xmlaParsear); if (xmlaParsear.indexOf("<item>") != -1) { xml = StringEscapeUtils.escapeXml10( xmlaParsear.substring(xmlaParsear.indexOf("nes>") + 4, xmlaParsear.indexOf("</obse"))); sb.replace(sb.indexOf("nes>") + 4, sb.indexOf("</obse"), xml); } if (xmlaParsear.indexOf("<Domicilio>") != -1) { xml = StringEscapeUtils.escapeXml10( xmlaParsear.substring(xmlaParsear.indexOf("mes>") + 4, xmlaParsear.indexOf("</det1"))); sb.replace(sb.indexOf("mes>") + 4, sb.indexOf("</det1"), xml); } xml = sb.toString(); } catch (Exception e) { xml = "Error"; logger.error("Error en metodo parsearCaracteresEspecialesXML1 " + e.getLocalizedMessage()); } finally { return xml; } }
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static String refactorString(String str) { // Avoid error when content is "" if (str.compareTo("") == 0) { return " "; }/*from w w w .ja va 2 s . c o m*/ /* * If the font of "\n" is "" or "\n", insert " " in front of it. * * For example: * "\nabc" -> " \nabc" * "\nabc\n\n" -> " \nabc\n \n" */ StringBuilder strBuilder = new StringBuilder(str); int start = 0; int index = strBuilder.indexOf("\n"); while (index != -1) { if (index == 0 || strBuilder.charAt(index - 1) == '\n') { strBuilder.insert(start, " "); start = index + 2; } else { start = index + 1; } if (start > strBuilder.length() || index == strBuilder.length()) { break; } index = strBuilder.indexOf("\n", start); } return strBuilder.toString(); }
From source file:com.github.magicsky.sya.checkers.TestSourceReader.java
/** * Searches for the offset of the first occurrence of a string in a workspace file. * * @param lookfor string to be searched for * @param fullPath full path of the workspace file * @return the offset or -1/*from w ww .ja va 2s. c o m*/ * @throws Exception * @throws UnsupportedEncodingException * @since 4.0 */ public static int indexOfInFile(String lookfor, Path fullPath) throws Exception { IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fullPath); Reader reader = new BufferedReader(new InputStreamReader(file.getContents(), file.getCharset())); Assert.assertTrue(lookfor.indexOf('\n') == -1); try { int c = 0; int offset = 0; StringBuilder buf = new StringBuilder(); while ((c = reader.read()) >= 0) { buf.append((char) c); if (c == '\n') { int idx = buf.indexOf(lookfor); if (idx >= 0) { return idx + offset; } offset += buf.length(); buf.setLength(0); } } int idx = buf.indexOf(lookfor); if (idx >= 0) { return idx + offset; } return -1; } finally { reader.close(); } }
From source file:org.wso2.carbon.apimgt.rest.api.store.utils.mappings.APIMappingUtil.java
private static List<APIEndpointURLsDTO> extractEnpointURLs(API api, String tenantDomain) throws APIManagementException { List<APIEndpointURLsDTO> apiEndpointsList = new ArrayList<>(); APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() .getAPIManagerConfiguration(); Map<String, Environment> environments = config.getApiGatewayEnvironments(); Set<String> environmentsPublishedByAPI = new HashSet<String>(api.getEnvironments()); environmentsPublishedByAPI.remove("none"); Set<String> apiTransports = new HashSet<>(Arrays.asList(api.getTransports().split(","))); APIConsumer apiConsumer = RestApiUtil.getLoggedInUserConsumer(); for (String environmentName : environmentsPublishedByAPI) { Environment environment = environments.get(environmentName); if (environment != null) { APIEnvironmentURLsDTO environmentURLsDTO = new APIEnvironmentURLsDTO(); String[] gwEndpoints = environment.getApiGatewayEndpoint().split(","); Map<String, String> domains = new HashMap<String, String>(); if (tenantDomain != null) { domains = apiConsumer.getTenantDomainMappings(tenantDomain, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY); }/*from ww w . j a va2 s . c o m*/ String customGatewayUrl = null; if (domains != null) { customGatewayUrl = domains.get(APIConstants.CUSTOM_URL); } for (String gwEndpoint : gwEndpoints) { StringBuilder endpointBuilder = new StringBuilder(gwEndpoint); if (customGatewayUrl != null) { int index = endpointBuilder.indexOf("//"); endpointBuilder.replace(index + 2, endpointBuilder.length(), customGatewayUrl); endpointBuilder.append(api.getContext().replace("/t/" + tenantDomain, "")); } else { endpointBuilder.append(api.getContext()); } if (gwEndpoint.contains("http:") && apiTransports.contains("http")) { environmentURLsDTO.setHttp(endpointBuilder.toString()); } else if (gwEndpoint.contains("https:") && apiTransports.contains("https")) { environmentURLsDTO.setHttps(endpointBuilder.toString()); } } APIEndpointURLsDTO apiEndpointURLsDTO = new APIEndpointURLsDTO(); apiEndpointURLsDTO.setEnvironmentURLs(environmentURLsDTO); apiEndpointURLsDTO.setEnvironmentName(environment.getName()); apiEndpointURLsDTO.setEnvironmentType(environment.getType()); apiEndpointsList.add(apiEndpointURLsDTO); } } return apiEndpointsList; }
From source file:Main.java
/** * Appends the given set of parameters to the given query string * @param queryBuilder The query url string to append the parameters * @param parameters The parameters to append *///from w w w. ja v a 2 s . c o m public static void appendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String, Object> parameters) { //perform parameter validation if (null == queryBuilder) throw new IllegalArgumentException("Given value for parameter \"queryBuilder\" is invalid."); if (null == parameters) return; //does the query string already has parameters boolean hasParams = (queryBuilder.indexOf("?") > 0) || (queryBuilder.indexOf("http") != 0); if (!hasParams) queryBuilder.append('?'); encodeObjectAsQueryString("", parameters, queryBuilder); }
From source file:org.wso2.carbon.apimgt.rest.api.store.v1.mappings.APIMappingUtil.java
/** * Extracts the API environment details with access url for each endpoint * /* ww w .j a v a2 s .c o m*/ * @param api API object * @param tenantDomain Tenant domain of the API * @return the API environment details * @throws APIManagementException error while extracting the information */ private static List<APIEndpointURLsDTO> extractEnpointURLs(API api, String tenantDomain) throws APIManagementException { List<APIEndpointURLsDTO> apiEndpointsList = new ArrayList<>(); APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService() .getAPIManagerConfiguration(); Map<String, Environment> environments = config.getApiGatewayEnvironments(); Set<String> environmentsPublishedByAPI = new HashSet<>(api.getEnvironments()); environmentsPublishedByAPI.remove("none"); Set<String> apiTransports = new HashSet<>(Arrays.asList(api.getTransports().split(","))); APIConsumer apiConsumer = RestApiUtil.getLoggedInUserConsumer(); for (String environmentName : environmentsPublishedByAPI) { Environment environment = environments.get(environmentName); if (environment != null) { APIEnvironmentURLsDTO environmentURLsDTO = new APIEnvironmentURLsDTO(); String[] gwEndpoints = environment.getApiGatewayEndpoint().split(","); Map<String, String> domains = new HashMap<>(); if (tenantDomain != null) { domains = apiConsumer.getTenantDomainMappings(tenantDomain, APIConstants.API_DOMAIN_MAPPINGS_GATEWAY); } String customGatewayUrl = null; if (domains != null) { customGatewayUrl = domains.get(APIConstants.CUSTOM_URL); } for (String gwEndpoint : gwEndpoints) { StringBuilder endpointBuilder = new StringBuilder(gwEndpoint); if (customGatewayUrl != null) { int index = endpointBuilder.indexOf("//"); endpointBuilder.replace(index + 2, endpointBuilder.length(), customGatewayUrl); endpointBuilder.append(api.getContext().replace("/t/" + tenantDomain, "")); } else { endpointBuilder.append(api.getContext()); } if (gwEndpoint.contains("http:") && apiTransports.contains("http")) { environmentURLsDTO.setHttp(endpointBuilder.toString()); } else if (gwEndpoint.contains("https:") && apiTransports.contains("https")) { environmentURLsDTO.setHttps(endpointBuilder.toString()); } } APIEndpointURLsDTO apiEndpointURLsDTO = new APIEndpointURLsDTO(); apiEndpointURLsDTO.setEnvironmentURLs(environmentURLsDTO); apiEndpointURLsDTO.setEnvironmentName(environment.getName()); apiEndpointURLsDTO.setEnvironmentType(environment.getType()); apiEndpointsList.add(apiEndpointURLsDTO); } } return apiEndpointsList; }
From source file:org.jfrog.hudson.util.ExtractorUtils.java
private static String publicGitUrl(String gitUrl) { if (gitUrl != null && gitUrl.contains("https://") && gitUrl.contains("@")) { StringBuilder sb = new StringBuilder(gitUrl); int start = sb.indexOf("https://"); int end = sb.indexOf("@") + 1; sb = sb.replace(start, end, StringUtils.EMPTY); return "https://" + sb.toString(); }//from w w w . j a va 2 s .c om return gitUrl; }