Tabnine Logo
StringBuilder.ensureCapacity
Code IndexAdd Tabnine to your IDE (free)

How to use
ensureCapacity
method
in
java.lang.StringBuilder

Best Java code snippets using java.lang.StringBuilder.ensureCapacity (Showing top 20 results out of 1,134)

origin: alibaba/Sentinel

public static StringBuilder appendLog(String str, StringBuilder appender, char delimiter) {
  if (str != null) {
    int len = str.length();
    appender.ensureCapacity(appender.length() + len);
    for (int i = 0; i < len; i++) {
      char c = str.charAt(i);
      if (c == '\n' || c == '\r' || c == delimiter) {
        c = ' ';
      }
      appender.append(c);
    }
  }
  return appender;
}
origin: square/picasso

static void updateThreadName(Request data) {
 String name = data.getName();
 StringBuilder builder = NAME_BUILDER.get();
 builder.ensureCapacity(Utils.THREAD_PREFIX.length() + name.length());
 builder.replace(Utils.THREAD_PREFIX.length(), builder.length(), name);
 Thread.currentThread().setName(builder.toString());
}
origin: org.apache.commons/commons-lang3

/**
 * <p>Appends the toString that would be produced by {@code Object}
 * if a class did not override toString itself. {@code null}
 * will throw a NullPointerException for either of the two parameters. </p>
 *
 * <pre>
 * ObjectUtils.identityToString(builder, "")            = builder.append("java.lang.String@1e23"
 * ObjectUtils.identityToString(builder, Boolean.TRUE)  = builder.append("java.lang.Boolean@7fa"
 * ObjectUtils.identityToString(builder, Boolean.TRUE)  = builder.append("java.lang.Boolean@7fa")
 * </pre>
 *
 * @param builder  the builder to append to
 * @param object  the object to create a toString for
 * @since 3.2
 */
public static void identityToString(final StringBuilder builder, final Object object) {
  Validate.notNull(object, "Cannot get the toString of a null object");
  final String name = object.getClass().getName();
  final String hexString = Integer.toHexString(System.identityHashCode(object));
  builder.ensureCapacity(builder.length() +  name.length() + 1 + hexString.length());
  builder.append(name)
     .append(AT_SIGN)
     .append(hexString);
}
origin: org.postgresql/postgresql

private static boolean appendSingleIntervalCast(StringBuilder buf, String cmp, String type, String value, String pgType) {
 if (!areSameTsi(type, cmp)) {
  return false;
 }
 buf.ensureCapacity(buf.length() + 5 + 4 + 14 + value.length() + pgType.length());
 buf.append("CAST(").append(value).append("||' ").append(pgType).append("' as interval)");
 return true;
}
origin: org.postgresql/postgresql

private static void singleArgumentFunctionCall(StringBuilder buf, String call, String functionName,
  List<? extends CharSequence> parsedArgs) throws PSQLException {
 if (parsedArgs.size() != 1) {
  throw new PSQLException(GT.tr("{0} function takes one and only one argument.", functionName),
    PSQLState.SYNTAX_ERROR);
 }
 CharSequence arg0 = parsedArgs.get(0);
 buf.ensureCapacity(buf.length() + call.length() + arg0.length() + 1);
 buf.append(call).append(arg0).append(')');
}
origin: square/picasso

private String createKey(StringBuilder builder) {
 Request data = this;
 if (data.stableKey != null) {
  builder.ensureCapacity(data.stableKey.length() + KEY_PADDING);
  builder.append(data.stableKey);
 } else if (data.uri != null) {
  String path = data.uri.toString();
  builder.ensureCapacity(path.length() + KEY_PADDING);
  builder.append(path);
 } else {
  builder.ensureCapacity(KEY_PADDING);
  builder.append(data.resourceId);
origin: pentaho/pentaho-kettle

/**
 * Turn a byte array into a version four UUID string. Adapted from org.apache.commons.id.uuid.UUID.java
 *
 * @param raw
 * @return
 */
private String getUUIDString( byte[] raw ) {
 StringBuilder buf = new StringBuilder( new String( encodeHex( raw ) ) );
 while ( buf.length() != 32 ) {
  buf.insert( 0, "0" );
 }
 buf.ensureCapacity( 32 );
 buf.insert( 8, '-' );
 buf.insert( 13, '-' );
 buf.insert( 18, '-' );
 buf.insert( 23, '-' );
 return buf.toString();
}
origin: qiujuer/Genius-Android

private String convertValueToMessage(int value) {
  String format = mIndicatorFormatter != null ? mIndicatorFormatter : DEFAULT_FORMATTER;
  //We're trying to re-use the Formatter here to avoid too much memory allocations
  //But I'm not completey sure if it's doing anything good... :(
  //Previously, this condition was wrong so the Formatter was always re-created
  //But as I fixed the condition, the formatter started outputting trash characters from previous
  //calls, so I mark the StringBuilder as empty before calling format again.
  //Anyways, I see the memory usage still go up on every call to this method
  //and I have no clue on how to fix that... damn Strings...
  if (mFormatter == null || !mFormatter.locale().equals(Locale.getDefault())) {
    int bufferSize = format.length() + String.valueOf(mMax).length();
    if (mFormatBuilder == null) {
      mFormatBuilder = new StringBuilder(bufferSize);
    } else {
      mFormatBuilder.ensureCapacity(bufferSize);
    }
    mFormatter = new Formatter(mFormatBuilder, Locale.getDefault());
  } else {
    mFormatBuilder.setLength(0);
  }
  return mFormatter.format(format, value).toString();
}
origin: apache/flink

public static String createRandomString(Random rnd, int length) {
  final StringBuilder sb = new StringBuilder();
  sb.ensureCapacity(length);
  
  for (int i = 0; i < length; i++) {
    sb.append((char) (rnd.nextInt(26) + 65));
  }
  return sb.toString();
}

origin: looly/hutool

char j;
StringBuilder tmp = new StringBuilder();
tmp.ensureCapacity(content.length() * 6);
origin: looly/hutool

char j;
StringBuilder tmp = new StringBuilder();
tmp.ensureCapacity(content.length() * 6);
origin: org.postgresql/postgresql

sb.ensureCapacity(sb.length() + size + 1);
sb.append(begin);
for (int i = 0; i < numberOfArguments; i++) {
origin: org.freemarker/freemarker

static private void mergeAdjacentText(Node parent, StringBuilder collectorBuf) {
  Node child = parent.getFirstChild();
  while (child != null) {
    Node next = child.getNextSibling();
    if (child instanceof Text) {
      boolean atFirstText = true;
      while (next instanceof Text) { //
        if (atFirstText) {
          collectorBuf.setLength(0);
          collectorBuf.ensureCapacity(child.getNodeValue().length() + next.getNodeValue().length());
          collectorBuf.append(child.getNodeValue());
          atFirstText = false;
        }
        collectorBuf.append(next.getNodeValue());
        
        parent.removeChild(next);
        
        next = child.getNextSibling();
      }
      if (!atFirstText && collectorBuf.length() != 0) {
        ((CharacterData) child).setData(collectorBuf.toString());
      }
    } else {
      mergeAdjacentText(child, collectorBuf);
    }
    child = next;
  }
}
 
origin: org.freemarker/freemarker

if (collectorTextChild != null) {
  if (collectorTextChildBuff.length() == 0) {
    collectorTextChildBuff.ensureCapacity(
        collectorTextChild.getNodeValue().length() + child.getNodeValue().length());
    collectorTextChildBuff.append(collectorTextChild.getNodeValue());
origin: PipelineAI/pipeline

builder.ensureCapacity(estimatedLength);
for (String displayString : aggregatedCommandsExecuted.keySet()) {
  if (builder.length() > 0) {
origin: haraldk/TwelveMonkeys

private static String maybeEscapeAttributeValue(final String pValue) {
  int startEscape = needsEscapeAttribute(pValue);
  if (startEscape < 0) {
    return pValue;
  }
  else {
    StringBuilder builder = new StringBuilder(pValue.substring(0, startEscape));
    builder.ensureCapacity(pValue.length() + 16);
    int pos = startEscape;
    for (int i = pos; i < pValue.length(); i++) {
      switch (pValue.charAt(i)) {
        case '&':
          pos = appendAndEscape(pValue, pos, i, builder, "&amp;");
          break;
        case '"':
          pos = appendAndEscape(pValue, pos, i, builder, "&quot;");
          break;
        default:
          break;
      }
    }
    builder.append(pValue.substring(pos));
    return builder.toString();
  }
}
origin: haraldk/TwelveMonkeys

builder.ensureCapacity(pValue.length() + 30);
origin: org.jruby/jruby-complete

private static StringBuilder padding(final StringBuilder out, CharSequence sequence,
                   final int width, final char padder) {
  final int len = sequence.length();
  if (len >= width) return out.append(sequence);
  if (width > SMALLBUF) throw new IndexOutOfBoundsException("padding width " + width + " too large");
  out.ensureCapacity(width + len);
  for (int i = len; i < width; i++) out.append(padder);
  return out.append(sequence);
}
origin: hypercube1024/firefly

public static final void bytesToHexAppend(byte[] bs, int off, int length,
                     StringBuilder sb) {
  if (bs.length <= off || bs.length < off + length)
    throw new IllegalArgumentException();
  sb.ensureCapacity(sb.length() + length * 2);
  for (int i = off; i < (off + length); i++) {
    sb.append(Character.forDigit((bs[i] >>> 4) & 0xf, 16));
    sb.append(Character.forDigit(bs[i] & 0xf, 16));
  }
}
origin: com.jtransc/jtransc-rt

@Override
@JTranscAsync
public synchronized void ensureCapacity(int minimumCapacity) {
  super.ensureCapacity(minimumCapacity);
}
java.langStringBuilderensureCapacity

Popular methods of StringBuilder

  • append
  • toString
  • <init>
    Constructs a string builder initialized to the contents of the specified string. The initial capacit
  • length
  • setLength
  • charAt
  • deleteCharAt
  • insert
  • substring
  • delete
  • replace
  • setCharAt
  • replace,
  • setCharAt,
  • indexOf,
  • lastIndexOf,
  • reverse,
  • appendCodePoint,
  • getChars,
  • subSequence,
  • trimToSize

Popular in Java

  • Running tasks concurrently on multiple threads
  • putExtra (Intent)
  • setRequestProperty (URLConnection)
  • requestLocationUpdates (LocationManager)
  • EOFException (java.io)
    Thrown when a program encounters the end of a file or stream during an input operation.
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now