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

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

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

StringBuffer.insert介绍

暂无

代码示例

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

/**
 * Inserts the string representation of the specified boolean into this
 * buffer at the specified offset.
 *
 * @param index
 *            the index at which to insert.
 * @param b
 *            the boolean to insert.
 * @return this buffer.
 * @throws StringIndexOutOfBoundsException
 *             if {@code index < 0} or {@code index > length()}.
 */
public StringBuffer insert(int index, boolean b) {
  return insert(index, b ? "true" : "false");
}

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

@Override
public StringBuffer format(final Date date, final StringBuffer toAppendTo, final FieldPosition fieldPosition) {
  final StringBuffer formatted = this.dateFormat.format(date, toAppendTo, fieldPosition);
  formatted.insert(26, ':');
  return formatted;
}

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

String str = Integer.toString(j);
str = new StringBuffer(str).insert(str.length()-2, ".").toString();

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

/**
  * Abbreviate element of name.
  * @param buf buffer to receive element.
  * @param startPos starting index of name element.
  * @return starting index of next element.
  */
 public int abbreviate(final StringBuffer buf, final int startPos) {
  int nextDot = buf.toString().indexOf(".", startPos);
  if (nextDot != -1) {
   if ((nextDot - startPos) > charCount) {
    buf.delete(startPos + charCount, nextDot);
    nextDot = startPos + charCount;
    if (ellipsis != '\0') {
     buf.insert(nextDot, ellipsis);
     nextDot++;
    }
   }
   nextDot++;
  }
  return nextDot;
 }
}

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

private CtClass toCtClass(Class rtclass) throws NotFoundException {
  String name;
  if (!rtclass.isArray())
    name = rtclass.getName();
  else {
    StringBuffer sbuf = new StringBuffer();
    do {
      sbuf.append("[]");
      rtclass = rtclass.getComponentType();
    } while(rtclass.isArray());
    sbuf.insert(0, rtclass.getName());
    name = sbuf.toString();
  }
    
  return classPool.get(name);
}

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

/**
 * Inserts a backslash before every comma and backslash. 
 */
private static String escape(String s) {
  StringBuffer buf = new StringBuffer(s);
  for (int i = 0; i < buf.length(); i++) {
    char c = buf.charAt(i);
    if (c == ',' || c == '\\') {
      buf.insert(i, '\\');
      i++;
    }
  }
  return buf.toString();
}

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

buffer.insert(fieldStart, SPACES);
buffer.insert(fieldStart, SPACES, 0, padLength);

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

private static String convertFromArray(String classname)
{
  int index = classname.indexOf("[]"); 
  if (index != -1) {
    String rawType = classname.substring(0, index);
    StringBuffer sb = new StringBuffer(Descriptor.of(rawType));
    while (index != -1) {
      sb.insert(0, "[");
      index = classname.indexOf("[]", index + 1);
    }
    return sb.toString().replace('/', '.');
  }
  return classname;
}

代码示例来源:origin: twosigma/beakerx

private String createClassName(File root, File file) {
 StringBuffer sb = new StringBuffer();
 String fileName = file.getName();
 sb.append(fileName.substring(0, fileName.lastIndexOf(".class")));
 file = file.getParentFile();
 while (file != null && !file.equals(root)) {
  sb.insert(0, '.').insert(0, file.getName());
  file = file.getParentFile();
 }
 return sb.toString();
}

代码示例来源:origin: twosigma/beakerx

private String createGroovyClassName(File root, File file) {
 StringBuffer sb = new StringBuffer();
 String fileName = file.getName();
 sb.append(fileName.substring(0, fileName.lastIndexOf(".groovy")));
 file = file.getParentFile();
 while (file != null && !file.equals(root)) {
  sb.insert(0, '.').insert(0, file.getName());
  file = file.getParentFile();
 }
 return sb.toString();
}

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

/**
 * Inserts a backslash before every comma and backslash. 
 */
private static String escape(String s) {
  StringBuffer buf = new StringBuffer(s);
  for (int i = 0; i < buf.length(); i++) {
    char c = buf.charAt(i);
    if (c == ',' || c == '\\') {
      buf.insert(i, '\\');
      i++;
    }
  }
  return buf.toString();
}

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

/**
 * escape any occurrence of "/", "." and "\"
 */
private static String escape(String s) {
  StringBuffer sb = new StringBuffer(s);
  for (int i = 0; i < sb.length(); i++) {
    if (sb.charAt(i) == '/' || sb.charAt(i) == '\\' || sb.charAt(i) == '.') {
      sb.insert(i, '\\');
      i++;
    }
  }
  return sb.toString();
}

代码示例来源:origin: org.javassist/javassist

private CtClass toCtClass(Class<?> rtclass) throws NotFoundException {
  String name;
  if (!rtclass.isArray())
    name = rtclass.getName();
  else {
    StringBuffer sbuf = new StringBuffer();
    do {
      sbuf.append("[]");
      rtclass = rtclass.getComponentType();
    } while(rtclass.isArray());
    sbuf.insert(0, rtclass.getName());
    name = sbuf.toString();
  }
  return classPool.get(name);
}

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

public void insertData(int offset, String arg) throws DOMException {
  try {
    buffer.insert(offset, arg);
  } catch (ArrayIndexOutOfBoundsException ex) {
    throw new DOMException(DOMException.INDEX_SIZE_ERR, null);
  }
}

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

public static void main(String[] args) {
  SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") {
    public StringBuffer format(Date date, StringBuffer toAppendTo, java.text.FieldPosition pos) {
      StringBuffer toFix = super.format(date, toAppendTo, pos);
      return toFix.insert(toFix.length()-2, ':');
    };
  };
  // Usage:
  System.out.println(dateFormat.format(new Date()));
}

代码示例来源:origin: org.osgi/org.osgi.compendium

static String mangle(String nodeName, int limit) {
  if (nodeName == null)
    throw new NullPointerException("The 'nodeName' parameter must not be null.");
  if (nodeName.equals(""))
    throw new IllegalArgumentException("The 'nodeName' parameter must not be empty.");
  if (nodeName.length() > limit)
    // create node name hash
    return getHash(nodeName);
  // escape any '/' and '\' characters in the node name
  StringBuffer nameBuffer = new StringBuffer(nodeName);
  for (int i = 0; i < nameBuffer.length(); i++)
    // 'i' can increase in loop
    if (nameBuffer.charAt(i) == '\\' || nameBuffer.charAt(i) == '/')
      nameBuffer.insert(i++, '\\');
  return nameBuffer.toString();
}

代码示例来源:origin: org.javassist/javassist

private static String convertFromArray(String classname)
{
  int index = classname.indexOf("[]");
  if (index != -1) {
    String rawType = classname.substring(0, index);
    StringBuffer sb = new StringBuffer(Descriptor.of(rawType));
    while (index != -1) {
      sb.insert(0, "[");
      index = classname.indexOf("[]", index + 1);
    }
    return sb.toString().replace('/', '.');
  }
  return classname;
}

代码示例来源:origin: prestodb/presto

/**
 * Gets the value as a String in the ISO8601 duration format including
 * only seconds and milliseconds.
 * <p>
 * For example, "PT72.345S" represents 1 minute, 12 seconds and 345 milliseconds.
 * <p>
 * For more control over the output, see
 * {@link com.facebook.presto.jdbc.internal.joda.time.format.PeriodFormatterBuilder PeriodFormatterBuilder}.
 *
 * @return the value as an ISO8601 string
 */
@ToString
public String toString() {
  long millis = getMillis();
  StringBuffer buf = new StringBuffer();
  buf.append("PT");
  boolean negative = (millis < 0);
  FormatUtils.appendUnpaddedInteger(buf, millis);
  while (buf.length() < (negative ? 7 : 6)) {
    buf.insert(negative ? 3 : 2, "0");
  }
  if ((millis / 1000) * 1000 == millis) {
    buf.setLength(buf.length() - 3);
  } else {
    buf.insert(buf.length() - 3, ".");
  }
  buf.append('S');
  return buf.toString();
}

代码示例来源:origin: internetarchive/heritrix3

/**
  Prepends one character, as a lump, to this string.
  @param ch the character to prepend
*/
void prepend(char ch) {
  assert checkInvariants();
  int oldLen = string.length();
  ensureCapacity(1 + oldLen);
  string.insert(0, ch);
  System.arraycopy(aux, 0, aux, 1, oldLen);
  aux[0] = LUMP_BEGIN | LUMP_END;
  assert checkInvariants();
}

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

private void init() {
    StringBuffer buf = new StringBuffer(200);
    for (Node temp = node; temp != null; temp = temp.jjtGetParent()) {
      buf.insert(0, "/" + temp.toString());
    }
    add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ABSOLUTE_PATH"), model, buf.toString()));
    add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ALLDESCENDANTS"), model, "//" + node.toString()));
  }
}

相关文章