@Override public String getBatchSql() { List<String> sqlList = getBatchSqlList(); StringBuffer buf = new StringBuffer(); for (String item : sqlList) { if (buf.length() > 0) { buf.append("\n;\n"); } buf.append(item); } return buf.toString(); }
StringBuffer sb = new StringBuffer(); for (int n = 0; n < 10; n++) { sb.append("a"); // This will clear the buffer sb.delete(0, sb.length()); }
private void reset() { StringBuffer buf = getStringBuffer(); if (buf.length()>4096) out = new StringWriter(256); else buf.setLength(0); }
/** * Check if we are ready to send another chunk. * @param force force sending, even if not a full chunk */ private void checkFlush(boolean force) { if ((force && sb.length() > 0) || sb.length() > 2048) { sendBufferSync(ByteBuffer.wrap(sb.toString().getBytes())); // clear our internal buffer sb.setLength(0); } }
/** * Check if we are ready to send another chunk. * @param force force sending, even if not a full chunk */ private void checkFlush(boolean force) { if ((force && sb.length() > 0) || sb.length() > 2048) { sendBuffer(ByteBuffer.wrap(sb.toString().getBytes())); // clear our internal buffer sb.setLength(0); } }
/** * Replaces all the occurrences of variables within the given source buffer * with their matching values from the resolver. * The buffer is updated with the result. * * @param source the buffer to replace in, updated, null returns zero * @return true if altered */ public boolean replaceIn(final StringBuffer source) { if (source == null) { return false; } return replaceIn(source, 0, source.length()); }
private String baseURL( HttpServletRequest request ) { StringBuffer url = request.getRequestURL(); String baseURL = url.substring( 0, url.length() - request.getRequestURI().length() ) + "/"; return XForwardUtil.externalUri( baseURL, request.getHeader( X_FORWARD_HOST_HEADER_KEY ), request.getHeader( X_FORWARD_PROTO_HEADER_KEY ) ); }
/** * Replaces all the occurrences of variables within the given source buffer * with their matching values from the resolver. * The buffer is updated with the result. * * @param source the buffer to replace in, updated, null returns zero * @return true if altered */ public boolean replaceIn(StringBuffer source) { if (source == null) { return false; } return replaceIn(source, 0, source.length()); }
public String toString() { if (resolved != null) return resolved.toString(); StringBuffer buffer = new StringBuffer("{"); Iterator iter = interfaces.keySet().iterator(); while (iter.hasNext()) { buffer.append(iter.next()); buffer.append(", "); } buffer.setLength(buffer.length() - 2); if (potentialClass != null) buffer.append(", *").append(potentialClass.toString()); buffer.append("}"); return buffer.toString(); } }
/** * {@inheritDoc} */ public void format(final LoggingEvent event, final StringBuffer toAppendTo) { final int initialLength = toAppendTo.length(); toAppendTo.append(event.getLoggerName()); abbreviate(initialLength, toAppendTo); } }
private static String lookupSwitch(CodeIterator iter, int pos) { StringBuffer buffer = new StringBuffer("lookupswitch {\n"); int index = (pos & ~3) + 4; // default buffer.append("\t\tdefault: ").append(pos + iter.s32bitAt(index)).append("\n"); int npairs = iter.s32bitAt(index += 4); int end = npairs * 8 + (index += 4); for (; index < end; index += 8) { int match = iter.s32bitAt(index); int target = iter.s32bitAt(index + 4) + pos; buffer.append("\t\t").append(match).append(": ").append(target).append("\n"); } buffer.setCharAt(buffer.length() - 1, '}'); return buffer.toString(); }
/** Format event to string buffer. @param sbuf string buffer to receive formatted event, may not be null. @param e event to format, may not be null. */ public void format(final StringBuffer sbuf, final LoggingEvent e) { for (int i = 0; i < patternConverters.length; i++) { int startField = sbuf.length(); patternConverters[i].format(e, sbuf); patternFields[i].format(startField, sbuf); } }
private static String tableSwitch(CodeIterator iter, int pos) { StringBuffer buffer = new StringBuffer("tableswitch {\n"); int index = (pos & ~3) + 4; // default buffer.append("\t\tdefault: ").append(pos + iter.s32bitAt(index)).append("\n"); int low = iter.s32bitAt(index += 4); int high = iter.s32bitAt(index += 4); int end = (high - low + 1) * 4 + (index += 4); // Offset table for (int key = low; index < end; index += 4, key++) { int target = iter.s32bitAt(index) + pos; buffer.append("\t\t").append(key).append(": ").append(target).append("\n"); } buffer.setCharAt(buffer.length() - 1, '}'); return buffer.toString(); }
@RequestMapping(value = "/plugin/{pluginId}/login", method = RequestMethod.GET) public RedirectView redirectToThirdPartyLoginPage(@PathVariable("pluginId") String pluginId, HttpServletRequest request) { if (securityIsDisabledOrAlreadyLoggedIn(request)) { return new RedirectView("/pipelines", true); } final StringBuffer requestURL = request.getRequestURL(); requestURL.setLength(requestURL.length() - request.getRequestURI().length()); return new RedirectView(webBasedPluginAuthenticationProvider.getAuthorizationServerUrl(pluginId, requestURL.toString()), false); }
/** * Format a logging event. * @param event event to format. * @param toAppendTo string buffer to which class name will be appended. */ public void format(final LoggingEvent event, final StringBuffer toAppendTo) { final int initialLength = toAppendTo.length(); LocationInfo li = event.getLocationInformation(); if (li == null) { toAppendTo.append(LocationInfo.NA); } else { toAppendTo.append(li.getClassName()); } abbreviate(initialLength, toAppendTo); } }
public String evaluate(String sql, String dbType) { try { List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType); SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType); for (SQLStatement stmt : statementList) { stmt.accept(visitor); } StringBuffer buf = new StringBuffer(); for (TableStat.Column column : visitor.getColumns()) { if (buf.length() != 0) { buf.append(','); } buf.append(column.toString()); } return buf.toString(); } catch (Throwable ex) { System.err.println("error sql : " + sql); ex.printStackTrace(); return null; } } }
private static boolean shouldAppendSpace(StringBuffer text, char firstCharToAppend) { final boolean result; if (text.length() == 0) { result = false; } else { final char last = text.charAt(text.length() - 1); result = (last == ':' || firstCharToAppend == '@' || Character.isAlphabetic(last) || Character.isAlphabetic(firstCharToAppend)) && !Character.isWhitespace(last); } return result; }
/** * Replaces all the occurrences of variables with their matching values * from the resolver using the given source buffer as a template. * The buffer is not altered by this method. * * @param source the buffer to use as a template, not changed, null returns null * @return the result of the replace operation */ public String replace(final StringBuffer source) { if (source == null) { return null; } final StrBuilder buf = new StrBuilder(source.length()).append(source); substitute(buf, 0, buf.length()); return buf.toString(); }
@Test public void testFlush() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, false); out.write("abc".getBytes("us-ascii")); assertEquals(0, writer.getBuffer().length()); out.flush(); assertEquals("abc", writer.toString()); out.close(); }