List of usage examples for java.lang StringBuilder indexOf
@Override public int indexOf(String str)
From source file:com.huawei.datasight.molap.partition.reader.CSVParser.java
/** * Parses an incoming String and returns an array of elements. * * @param nextLine the string to parse/* ww w. j a va 2 s . c om*/ * @param multi Does it take multiple lines to form a single record. * @return the comma-tokenized list of elements, or null if nextLine is null * @throws IOException if bad things happen during the read */ private String[] parseLine(String nextLine, boolean multi) throws IOException { if (!multi && pending != null) { pending = null; } if (nextLine == null) { if (pending != null) { String s = pending; pending = null; return new String[] { s }; } else { return null; } } List<String> tokensOnThisLine = new ArrayList<>(MolapCommonConstants.DEFAULT_COLLECTION_SIZE); //CHECKSTYLE:OFF Approval No:Approval-V1R2C10_010 StringBuilder sb = new StringBuilder(INITIAL_READ_SIZE); boolean inQuotes = false; // CHECKSTYLE:ON if (pending != null) { sb.append(pending); pending = null; inQuotes = !this.ignoreQuotations;//true; } inQuotes = checkForQuotes(nextLine, tokensOnThisLine, sb, inQuotes); // line is done - check status if ((inQuotes && !ignoreQuotations)) { if (multi) { // continuing a quoted section, re-append newline sb.append('\n'); charCountInsideQuote = sb.length() - (sb.indexOf("\"") + 1); if (charCountInsideQuote >= 10000) //max char count to wait till the quote terminates { // System.out.println("Unterminated quoted field after 10000 characters in CSV Multi Line : " + sb.toString()); throw new IOException("Un-terminated quoted field after 10000 characters"); } pending = sb.toString(); sb = null; // this partial content is not to be added to field list yet } else { throw new IOException("Un-terminated quoted field at end of CSV line"); } } else { inField = false; charCountInsideQuote = 0; } if (sb != null) { tokensOnThisLine.add(sb.toString()); } return tokensOnThisLine.toArray(new String[tokensOnThisLine.size()]); }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ??Get??/* ww w.j a v a 2s.co m*/ * @param context * @param request * @param extraRequestParams ???GETDELETE??? * @return ?nullrequestClassnullUrlHost */ public static String parseCompleteUrl(Context context, Request request, RequestParams extraRequestParams) { StringBuilder stringBuilder = new StringBuilder(); /* ?Url */ String url = parseURLAnnotation(context, request.getClass()); if (url != null && !"".equals(url)) { stringBuilder.append(url); } else { /* ?Host */ String host = parseHostAnnotation(context, request.getClass()); if (host != null && !"".equals(host)) { stringBuilder.append(host); } /* ??Path */ if (stringBuilder.length() > 0) { String path = parsePathAnnotation(context, request.getClass()); if (path != null && !"".equals(path)) { stringBuilder.append("/"); stringBuilder.append(path); } } } if (stringBuilder.length() > 0) { Method method = request.getClass().getAnnotation(Method.class); if (method == null || method.value() == MethodType.GET || method.value() == MethodType.DELETE) { RequestParams newParams = parseRequestParams(context, request, extraRequestParams); String paramString = newParams.getParamString(); if (paramString != null && !"".equals(paramString)) { stringBuilder.append(stringBuilder.indexOf("?") == -1 ? "?" : "&"); stringBuilder.append(paramString); } } return stringBuilder.toString(); } else { return null; } }
From source file:org.apache.carbondata.spark.partition.reader.CSVParser.java
/** * Parses an incoming String and returns an array of elements. * * @param nextLine the string to parse// ww w . ja v a 2 s . co m * @param multi Does it take multiple lines to form a single record. * @return the comma-tokenized list of elements, or null if nextLine is null * @throws IOException if bad things happen during the read */ private String[] parseLine(String nextLine, boolean multi) throws IOException { if (!multi && pending != null) { pending = null; } if (nextLine == null) { if (pending != null) { String s = pending; pending = null; return new String[] { s }; } else { return null; } } List<String> tokensOnThisLine = new ArrayList<>(CarbonCommonConstants.DEFAULT_COLLECTION_SIZE); //CHECKSTYLE:OFF Approval No:Approval-V1R2C10_010 StringBuilder sb = new StringBuilder(INITIAL_READ_SIZE); boolean inQuotes = false; // CHECKSTYLE:ON if (pending != null) { sb.append(pending); pending = null; inQuotes = !this.ignoreQuotations;//true; } inQuotes = checkForQuotes(nextLine, tokensOnThisLine, sb, inQuotes); // line is done - check status if ((inQuotes && !ignoreQuotations)) { if (multi) { // continuing a quoted section, re-append newline sb.append('\n'); charCountInsideQuote = sb.length() - (sb.indexOf("\"") + 1); if (charCountInsideQuote >= 10000) //max char count to wait till the quote terminates { throw new IOException("Un-terminated quoted field after 10000 characters"); } pending = sb.toString(); sb = null; // this partial content is not to be added to field list yet } else { throw new IOException("Un-terminated quoted field at end of CSV line"); } } else { inField = false; charCountInsideQuote = 0; } if (sb != null) { tokensOnThisLine.add(sb.toString()); } return tokensOnThisLine.toArray(new String[tokensOnThisLine.size()]); }
From source file:no.kantega.publishing.api.taglibs.util.GetUrlTag.java
public int doStartTag() throws JspException { JspWriter out;//from w w w. j av a 2s . co m try { out = pageContext.getOut(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (isNotBlank(url)) { initUrlPlaceholderResolverIfNull(); StringBuilder urlBuilder = new StringBuilder(); if (isAbsoluteUrl(url)) { urlBuilder.append(url); } else { if (absoluteUrl) { addSchemeServerAndContextPath(urlBuilder, request); } if (addcontextpath && !absoluteUrl) { urlBuilder.append(request.getContextPath()); } if (url.charAt(0) == '/' || url.charAt(0) == '$') { urlBuilder.append(url); } else { urlBuilder.append('/'); urlBuilder.append(url); } } addSiteIdIfInAdminMode(urlBuilder, request); if (queryParams != null) { if ((!queryParams.startsWith("&")) && (!queryParams.startsWith("?")) && (!queryParams.startsWith("#"))) { if (urlBuilder.indexOf("?") == -1) { urlBuilder.append("?"); } else { urlBuilder.append("&"); } } urlBuilder.append(queryParams.replaceAll("&", "&")); } String buildUrl = urlPlaceholderResolver.replaceMacros(urlBuilder.toString(), pageContext); if (!escapeurl) { out.write(buildUrl.replaceAll("&", "&")); } else { out.write(buildUrl); } } else { out.write(request.getContextPath()); } } catch (Exception e) { log.error("", e); throw new JspException(e); } resetVars(); return SKIP_BODY; }
From source file:org.intermine.install.swing.CreateDatabaseWorker.java
/** * Create a database using the Postgres <code>createdb</code> program. * /* ww w. j a va2 s .c om*/ * @param server The database server. * @param databaseName The database name. * @param userName The database user name. * @param password The user password. * @param encoding The encoding for the database. * * @throws IOException if there is a problem running <code>createdb</code>. * * @throws InterruptedException if the thread is interrupted while running * the <code>createdb</code>. * * @throws DatabaseCreationException if the process completes but failed * to create the database. */ protected void createDatabaseWithCreatedb(String server, String databaseName, String userName, String password, String encoding) throws IOException, InterruptedException, DatabaseCreationException { String[] commands = { "/usr/bin/createdb", "-h", server, "-E", encoding, "-O", userName, "-W", "-T", "template0", databaseName }; if (logger.isDebugEnabled()) { StringBuilder command = new StringBuilder(); for (int i = 0; i < commands.length; i++) { if (i > 0) { command.append(' '); } command.append(commands[i]); } logger.debug(command); } StringBuilder output = new StringBuilder(); StringBuilder errorOutput = new StringBuilder(); Integer exitCode = null; Process p = Runtime.getRuntime().exec(commands); try { BufferedReader stdin = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getErrorStream())); boolean passwordSet = false; while (true) { try { while (stdin.ready()) { char c = (char) stdin.read(); output.append(c); } while (stderr.ready()) { char c = (char) stderr.read(); errorOutput.append(c); } if (!passwordSet && errorOutput.indexOf("Password:") >= 0) { PrintStream out = new PrintStream(p.getOutputStream(), true); out.println(password); passwordSet = true; } exitCode = p.exitValue(); // If this succeeds, we're done. break; } catch (IllegalThreadStateException e) { // Process not done, so wait and continue. Thread.sleep(250); } } } finally { try { p.exitValue(); } catch (IllegalThreadStateException e) { // Not finished, but something has failed. p.destroy(); } } if (errorOutput.length() > 0) { throw new DatabaseCreationException(exitCode, output.toString(), errorOutput.toString()); } if (exitCode != 0) { throw new DatabaseCreationException("Return code from createdb = " + exitCode, exitCode, output.toString(), errorOutput.toString()); } }
From source file:me.xiaopan.android.gohttp.requestobject.RequestParser.java
/** * ??Get??//ww w .j a v a 2 s. c o m * @param context * @param requestClass class * @param extraRequestParams ???GETDELETE??? * @return ?nullrequestClassnullUrlHost */ public static String parseCompleteUrl(Context context, Class<? extends Request> requestClass, RequestParams extraRequestParams) { StringBuilder stringBuilder = new StringBuilder(); /* ?Url */ String url = parseURLAnnotation(context, requestClass); if (url != null && !"".equals(url)) { stringBuilder.append(url); } else { /* ?Host */ if (stringBuilder.length() == 0) { String host = parseHostAnnotation(context, requestClass); if (host != null && !"".equals(host)) { stringBuilder.append(host); } } /* ??Path */ if (stringBuilder.length() > 0) { String path = parsePathAnnotation(context, requestClass); if (path != null && !"".equals(path)) { stringBuilder.append("/"); stringBuilder.append(path); } } } if (stringBuilder.length() > 0) { Method method = requestClass.getAnnotation(Method.class); if (method == null || method.value() == MethodType.GET || method.value() == MethodType.DELETE) { RequestParams newParams = parseRequestParams(context, requestClass, extraRequestParams); String paramString = newParams.getParamString(); if (paramString != null && !"".equals(paramString)) { stringBuilder.append(stringBuilder.indexOf("?") == -1 ? "?" : "&"); stringBuilder.append(paramString); } } return stringBuilder.toString(); } else { return null; } }
From source file:org.pentaho.platform.plugin.action.chartbeans.DefaultChartBeansGenerator.java
/** * Executes an action sequence from an <code>ActionSequenceDocument</code>. * // ww w . ja va2s . co m * @param pentahoSession * current <code>IPentahoSession</code> * @param parameterProviders * map of parameter providers; there should a single entry with "request" as the key * @param outputHandler * output handler * @param doc * action sequence document * @throws RuntimeException * if anything goes wrong */ protected void runActionSequence(final IPentahoSession pentahoSession, final Map<String, IParameterProvider> parameterProviders, final IOutputHandler outputHandler, final ActionSequenceDocument doc) throws RuntimeException { // Get the solution engine ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, pentahoSession); if (solutionEngine == null) { throw new RuntimeException("solutionEngine is null"); //$NON-NLS-1$ } solutionEngine.setLoggingLevel(ILogger.DEBUG); solutionEngine.init(pentahoSession); IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext(); String contextPath = requestContext.getContextPath(); IPentahoUrlFactory urlFactory = new SimpleUrlFactory(contextPath); //$NON-NLS-1$ IRuntimeContext runtime; IParameterProvider requestParmProvider = parameterProviders.get("request"); if (requestParmProvider.hasParameter("obj_id")) { final String obj_id = (String) requestParmProvider.getParameter("obj_id"); final String msg_name = (String) requestParmProvider.getParameter("message_name"); final String job_id = (String) requestParmProvider.getParameter("job_id"); runtime = solutionEngine.execute(doc.toString(), obj_id, job_id, false, true, //$NON-NLS-1$ //$NON-NLS-2$ msg_name, true, parameterProviders, outputHandler, null, urlFactory, new ArrayList()); //$NON-NLS-1$ } else { runtime = solutionEngine.execute(doc.toString(), "chartbeans_mql", "myprocessid", false, true, //$NON-NLS-1$ //$NON-NLS-2$ "myinstanceid", true, parameterProviders, outputHandler, null, urlFactory, new ArrayList()); //$NON-NLS-1$ } if ((runtime != null) && (runtime.getStatus() != IRuntimeContext.RUNTIME_STATUS_SUCCESS)) { StringBuilder buf = new StringBuilder(); boolean firstIteration = true; for (Object /* String */ message : runtime.getMessages()) { if (message instanceof Exception) { Exception ex = (Exception) message; if (ex.getCause() instanceof RuntimeException) { throw (RuntimeException) ex.getCause(); } } if (!firstIteration) { buf.append(" \\\\ "); //$NON-NLS-1$ } buf.append(message); } String errorStr; if (buf.indexOf("action_sequence_failed") > -1 && buf.indexOf("MQLRelationalDataComponent") > -1) { errorStr = Messages.getInstance().getString("DefaultChartBeansGenerator.ERROR_0001_SECURITY_ERROR"); } else { errorStr = Messages.getInstance().getString("DefaultChartBeansGenerator.ERROR_0002_UNKNOWN_ERROR"); } throw new RuntimeException(errorStr); } }
From source file:jenkins.scm.impl.subversion.SubversionSCMSource.java
/** * {@inheritDoc}//from w w w . j a va 2 s . c o m */ @NonNull @Override public SubversionSCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) { if (revision != null && !head.equals(revision.getHead())) { revision = null; } if (revision != null && !(revision instanceof SCMRevisionImpl)) { revision = null; } StringBuilder remote = new StringBuilder(remoteBase); if (!remoteBase.endsWith("/")) { remote.append('/'); } remote.append(head.getName()); if (revision != null) { remote.append('@').append(((SCMRevisionImpl) revision).getRevision()); } else if (remote.indexOf("@") != -1) { // name contains an @ so need to ensure there is an @ at the end of the name remote.append('@'); } return new SubversionSCM(remote.toString(), credentialsId, "."); }
From source file:org.apache.olio.workload.driver.UIDriver.java
public void doAddAttendee() throws Exception { //can only add yourself (one attendee) to party // Need to add header that will request js instead of // html. This will prevent the redirect. HashMap<String, String> header = new HashMap<String, String>(1); header.put("Accept", "text/javascript"); // Need to send only post request, get doesn't work. So send null post. StringBuilder response = http.fetchURL(addAttendeeURL + selectedEvent + "/attend", "", header); int status = http.getResponseCode(); if (status != HttpStatus.SC_OK) { throw new Exception("Add attendee returned: " + status); }/*from w w w. j a v a 2 s.c o m*/ if (response.indexOf("You are attending") == -1) { logger.warning("Add attendee failed, possible race condition"); // throw new Exception("Add attendee failed, could not find: You are attending"); } }
From source file:org.jivesoftware.community.util.StringUtils.java
public static StringBuilder removeTag(String s, StringBuilder html) { String tagBegin = (new StringBuilder()).append("<").append(s).append(" ").toString(); String tagEnd = (new StringBuilder()).append("</").append(s).append(">").toString(); int start = html.indexOf(tagBegin); do {/*from www . j a v a 2 s .c o m*/ if (start == -1) break; int end = html.indexOf(tagEnd, start + 1); if (end != -1) { html.replace(start, end, ""); start = html.indexOf(tagBegin); } } while (true); return html; }