java.lang.StringBuffer.length()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(245)

本文整理了Java中java.lang.StringBuffer.length()方法的一些代码示例,展示了StringBuffer.length()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringBuffer.length()方法的具体详情如下:
包路径:java.lang.StringBuffer
类名称:StringBuffer
方法名:length

StringBuffer.length介绍

[英]Returns the length (character count) of this string buffer.
[中]返回此字符串缓冲区的长度(字符计数)。

代码示例

代码示例来源:origin: alibaba/arthas

public static void print(int number, List<Integer> primeFactors) {
  StringBuffer sb = new StringBuffer(number + "=");
  for (int factor : primeFactors) {
    sb.append(factor).append('*');
  }
  if (sb.charAt(sb.length() - 1) == '*') {
    sb.deleteCharAt(sb.length() - 1);
  }
  System.out.println(sb);
}

代码示例来源:origin: alibaba/druid

@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();
}

代码示例来源:origin: stackoverflow.com

StringBuffer sb = new StringBuffer();
for (int n = 0; n < 10; n++) {
  sb.append("a");

  // This will clear the buffer
  sb.delete(0, sb.length());
}

代码示例来源:origin: jenkinsci/jenkins

private void reset() {
  StringBuffer buf = getStringBuffer();
  if (buf.length()>4096)
    out = new StringWriter(256);
  else
    buf.setLength(0);
}

代码示例来源:origin: apache/zookeeper

/**
 * 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);
  }
}

代码示例来源:origin: apache/zookeeper

/**
 * 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);
  }
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * 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());
}

代码示例来源:origin: neo4j/neo4j

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 ) );
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * 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());
}

代码示例来源:origin: redisson/redisson

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();
  }
}

代码示例来源:origin: log4j/log4j

/**
  * {@inheritDoc}
  */
 public void format(final LoggingEvent event, final StringBuffer toAppendTo) {
  final int initialLength = toAppendTo.length();
  toAppendTo.append(event.getLoggerName());
  abbreviate(initialLength, toAppendTo);
 }
}

代码示例来源:origin: redisson/redisson

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();
}

代码示例来源:origin: log4j/log4j

/**
  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);
 }
}

代码示例来源:origin: redisson/redisson

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();
}

代码示例来源:origin: gocd/gocd

@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);
}

代码示例来源:origin: log4j/log4j

/**
  * 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);
 }
}

代码示例来源:origin: alibaba/druid

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;
    }
  }
}

代码示例来源:origin: checkstyle/checkstyle

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;
}

代码示例来源:origin: org.apache.commons/commons-lang3

/**
 * 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();
}

代码示例来源:origin: commons-io/commons-io

@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();
}

相关文章