本文整理了Java中java.lang.StringBuffer.capacity()
方法的一些代码示例,展示了StringBuffer.capacity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StringBuffer.capacity()
方法的具体详情如下:
包路径:java.lang.StringBuffer
类名称:StringBuffer
方法名:capacity
[英]Returns the current capacity of the String buffer. The capacity is the amount of storage available for newly inserted characters; beyond which an allocation will occur.
[中]返回字符串缓冲区的当前容量。容量是可用于新插入字符的存储量;超出此范围将进行分配。
代码示例来源:origin: log4j/log4j
/**
Produces a formatted string as specified by the conversion pattern.
*/
public String format(LoggingEvent event) {
// Reset working stringbuffer
if(sbuf.capacity() > MAX_CAPACITY) {
sbuf = new StringBuffer(BUF_SIZE);
} else {
sbuf.setLength(0);
}
PatternConverter c = head;
while(c != null) {
c.format(sbuf, event);
c = c.next;
}
return sbuf.toString();
}
}
代码示例来源:origin: log4j/log4j
public
String format(LoggingEvent event) {
if(sbuf.capacity() > MAX_CAPACITY) {
sbuf = new StringBuffer(BUF_SIZE);
} else {
代码示例来源:origin: pentaho/pentaho-kettle
public String format( LoggingEvent event ) {
if ( sbuf.capacity() > MAX_CAPACITY ) {
sbuf = new StringBuffer( BUF_SIZE );
} else {
代码示例来源:origin: log4j/log4j
if(buf.capacity() > UPPER_LIMIT) {
buf = new StringBuffer(DEFAULT_SIZE);
} else {
代码示例来源:origin: pentaho/pentaho-kettle
public String format( LoggingEvent event ) {
if ( sbuf.capacity() > MAX_CAPACITY ) {
sbuf = new StringBuffer( BUF_SIZE );
} else {
代码示例来源:origin: camunda/camunda-bpm-platform
/**
Produces a formatted string as specified by the conversion pattern.
*/
public String format(LoggingEvent event) {
// Reset working stringbuffer
if(sbuf.capacity() > MAX_CAPACITY) {
sbuf = new StringBuffer(BUF_SIZE);
} else {
sbuf.setLength(0);
}
PatternConverter c = head;
while(c != null) {
c.format(sbuf, event);
c = c.next;
}
return sbuf.toString();
}
}
代码示例来源:origin: apache/log4j
/**
Produces a formatted string as specified by the conversion pattern.
*/
public String format(LoggingEvent event) {
// Reset working stringbuffer
if(sbuf.capacity() > MAX_CAPACITY) {
sbuf = new StringBuffer(BUF_SIZE);
} else {
sbuf.setLength(0);
}
PatternConverter c = head;
while(c != null) {
c.format(sbuf, event);
c = c.next;
}
return sbuf.toString();
}
}
代码示例来源:origin: camunda/camunda-bpm-platform
public
String format(LoggingEvent event) {
if(sbuf.capacity() > MAX_CAPACITY) {
sbuf = new StringBuffer(BUF_SIZE);
} else {
代码示例来源:origin: apache/log4j
public
String format(LoggingEvent event) {
if(sbuf.capacity() > MAX_CAPACITY) {
sbuf = new StringBuffer(BUF_SIZE);
} else {
代码示例来源:origin: apache/log4j
if(buf.capacity() > UPPER_LIMIT) {
buf = new StringBuffer(DEFAULT_SIZE);
} else {
代码示例来源:origin: org.clapper/javautil
/**
* Return the current capacity of the buffer (i.e., the number of
* characters left before truncation will occur).
*
* @return The capacity. A 0 means no more room is left, and all further
* inserted or appended characters will cause truncation.
*
* @see #length
*/
public int capacity()
{
return buf.capacity();
}
代码示例来源:origin: stackoverflow.com
%pragma(java) modulecode = %{
public static int foo(String in, StringBuffer out) {
int sz[] = {out.capacity()};
byte ret[] = new byte[out.capacity()];
final int v = test.foo(in, ret, sz);
// Or whatever your preferred semantics are:
out.replace(0, sz[0], new String(ret, 0, sz[0]));
return v;
}
%}
代码示例来源:origin: stackoverflow.com
class Demo2
{
public static void main(String[] args)
{
StringBuffer s = new StringBuffer();
System.out.println(s.capacity());
s.append("sachin");
System.out.println(s.capacity());
s.append(" is a great batsman");
System.out.println(s.capacity());
}
}
代码示例来源:origin: stackoverflow.com
public class StringBufferTest {
public static void main(String[] args) {
StringBuffer buf = new StringBuffer('a');
System.out.println(buf.capacity());
System.out.println((int) 'a');
StringBuffer buf2 = new StringBuffer('b');
System.out.println(buf2.capacity());
System.out.println((int) 'b');
}
}
代码示例来源:origin: stackoverflow.com
StringBuffer buf3 = new StringBuffer("a");
System.out.println(buf3.capacity());
代码示例来源:origin: stackoverflow.com
// initial capacity (of the array behind the scenes) will be 16.
StringBuffer buff1 = new StringBuffer("tuts point");
// The above constructor increases the capacity by 16 + stringArgument.length = 16 + 10 = 26 ( hence the output)
System.out.println("Old Capacity of buff1 = " + buff1.capacity()); // 26 ->check
buff1.ensureCapacity(28); // here 28 is minimumcapacity.
// the above line of code calls expandCapacity() of AbstractStringBuilder which does this:
//`(value.length + 1) * 2` i.e, 26+1 * 2 = 54 . Hence the output.
System.out.println("New Capacity of buff1 = " + buff1.capacity()); //54 --> check
代码示例来源:origin: com.alibaba.citrus.tool/antx-autoexpand
public String convert(E event) {
if (buf.capacity() > MAX_CAPACITY) {
buf = new StringBuffer(INITIAL_BUF_SIZE);
} else {
buf.setLength(0);
}
for (Converter<E> c = childConverter; c != null; c = c.next) {
c.write(buf, event);
}
return buf.toString();
}
代码示例来源:origin: com.cloudbees.util/jnr-unixsocket-nodep
public ByteBuffer toNative(StringBuffer parameter, ToNativeContext context) {
if (parameter == null) {
return null;
} else {
ByteBuffer buf = ParameterFlags.isIn(parameterFlags)
? charset.encode(CharBuffer.wrap(parameter))
: ByteBuffer.allocate(parameter.capacity() + 1);
if ((ParameterFlags.isOut(parameterFlags) && buf.capacity() < parameter.capacity() + 1) || !buf.hasArray()) {
byte[] array = new byte[parameter.capacity() + 1];
buf.get(array, 0, buf.remaining());
return ByteBuffer.wrap(array);
} else {
return buf;
}
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
public ByteBuffer toNative(StringBuffer parameter, ToNativeContext context) {
if (parameter == null) {
return null;
} else {
ByteBuffer buf = ParameterFlags.isIn(parameterFlags)
? charset.encode(CharBuffer.wrap(parameter))
: ByteBuffer.allocate(parameter.capacity() + 1);
if ((ParameterFlags.isOut(parameterFlags) && buf.capacity() < parameter.capacity() + 1) || !buf.hasArray()) {
byte[] array = new byte[parameter.capacity() + 1];
buf.get(array, 0, buf.remaining());
return ByteBuffer.wrap(array);
} else {
return buf;
}
}
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
public ByteBuffer toNative(StringBuffer parameter, ToNativeContext context) {
if (parameter == null) {
return null;
} else {
ByteBuffer buf = ParameterFlags.isIn(parameterFlags)
? charset.encode(CharBuffer.wrap(parameter))
: ByteBuffer.allocate(parameter.capacity() + 1);
if ((ParameterFlags.isOut(parameterFlags) && buf.capacity() < parameter.capacity() + 1) || !buf.hasArray()) {
byte[] array = new byte[parameter.capacity() + 1];
buf.get(array, 0, buf.remaining());
return ByteBuffer.wrap(array);
} else {
return buf;
}
}
}
内容来源于网络,如有侵权,请联系作者删除!