本文整理了Java中java.nio.Buffer.capacity()
方法的一些代码示例,展示了Buffer.capacity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.capacity()
方法的具体详情如下:
包路径:java.nio.Buffer
类名称:Buffer
方法名:capacity
[英]The capacity of this buffer, which never change.
[中]此缓冲区的容量永远不会改变。
代码示例来源:origin: google/guava
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
代码示例来源:origin: prestodb/presto
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
代码示例来源:origin: google/j2objc
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
代码示例来源:origin: wildfly/wildfly
/** Returns the number of elements between the limit and capacity. */
private static int availableCapacity(Buffer buffer) {
return buffer.capacity() - buffer.limit();
}
代码示例来源:origin: Rajawali/Rajawali
/**
* Change a specific subset of the buffer's data at the given offset to the given length.
*
* @param bufferInfo
* @param newData
* @param index
* @param resizeBuffer
*/
public void changeBufferData(BufferInfo bufferInfo, Buffer newData, int index, boolean resizeBuffer) {
changeBufferData(bufferInfo, newData, index, newData.capacity(), resizeBuffer);
}
代码示例来源:origin: stackoverflow.com
// Create an empty ByteBuffer with a 10 byte capacity
ByteBuffer bbuf = ByteBuffer.allocate(10);
// Get the buffer's capacity
int capacity = bbuf.capacity(); // 10
// Use the absolute put(int, byte).
// This method does not affect the position.
bbuf.put(0, (byte)0xFF); // position=0
// Set the position
bbuf.position(5);
// Use the relative put(byte)
bbuf.put((byte)0xFF);
// Get the new position
int pos = bbuf.position(); // 6
// Get remaining byte count
int rem = bbuf.remaining(); // 4
// Set the limit
bbuf.limit(7); // remaining=1
// This convenience method sets the position to 0
bbuf.rewind(); // remaining=7
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
&& buffer.limit() == buffer.capacity()) {
sb.append(buffer.capacity());
} else {
sb.append("pos=").append(buffer.position());
sb.append(" lim=").append(buffer.limit());
sb.append(" cap=").append(buffer.capacity());
代码示例来源:origin: stackoverflow.com
public static void main(String... args) {
ByteBuffer bb1 = ByteBuffer.allocateDirect(256 * 1024).order(ByteOrder.nativeOrder());
ByteBuffer bb2 = ByteBuffer.allocateDirect(256 * 1024).order(ByteOrder.nativeOrder());
for (int i = 0; i < 10; i++)
runTest(bb1, bb2);
}
private static void runTest(ByteBuffer bb1, ByteBuffer bb2) {
Unsafe unsafe = getTheUnsafe();
long start = System.nanoTime();
long addr1 = ((DirectBuffer) bb1).address();
long addr2 = ((DirectBuffer) bb2).address();
for (int i = 0, len = Math.min(bb1.capacity(), bb2.capacity()); i < len; i += 4)
unsafe.putInt(addr1 + i, unsafe.getInt(addr2 + i));
long time = System.nanoTime() - start;
int operations = bb1.capacity() / 4 * 2;
System.out.printf("Each putInt/getInt took an average of %.1f ns%n", (double) time / operations);
}
public static Unsafe getTheUnsafe() {
try {
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafe.setAccessible(true);
return (Unsafe) theUnsafe.get(null);
} catch (Exception e) {
throw new AssertionError(e);
}
}
代码示例来源:origin: Rajawali/Rajawali
public String toString() {
final StringBuilder buff = new StringBuilder();
if (mBuffers.get(INDEX_BUFFER_KEY).buffer != null) {
buff.append("Geometry3D indices: ").append(mBuffers.get(INDEX_BUFFER_KEY).buffer.capacity());
buff.append(", vertices: ").append(mBuffers.get(VERTEX_BUFFER_KEY).buffer.capacity());
buff.append(", normals: ").append(mBuffers.get(NORMAL_BUFFER_KEY).buffer.capacity());
buff.append(", uvs: ").append(mBuffers.get(TEXTURE_BUFFER_KEY).buffer.capacity()).append("\n");
buff.append(", colors: ").append(mBuffers.get(COLOR_BUFFER_KEY).buffer.capacity()).append("\n");
代码示例来源:origin: stackoverflow.com
public static ByteBuffer clone(ByteBuffer original) {
ByteBuffer clone = ByteBuffer.allocate(original.capacity());
original.rewind();//copy from the beginning
clone.put(original);
original.rewind();
clone.flip();
return clone;
}
代码示例来源:origin: stackoverflow.com
public static void main(String... args) {
ByteBuffer bb1 = ByteBuffer.allocateDirect(256 * 1024).order(ByteOrder.nativeOrder());
ByteBuffer bb2 = ByteBuffer.allocateDirect(256 * 1024).order(ByteOrder.nativeOrder());
for (int i = 0; i < 10; i++)
runTest(bb1, bb2);
}
private static void runTest(ByteBuffer bb1, ByteBuffer bb2) {
bb1.clear();
bb2.clear();
long start = System.nanoTime();
int count = 0;
while (bb2.remaining() > 0)
bb2.putInt(bb1.getInt());
long time = System.nanoTime() - start;
int operations = bb1.capacity() / 4 * 2;
System.out.printf("Each putInt/getInt took an average of %.1f ns%n", (double) time / operations);
}
代码示例来源:origin: bytedeco/javacpp
/**
* Copies the address, position, limit, and capacity of a direct NIO {@link Buffer}.
* Also keeps a reference to it to prevent its memory from getting deallocated.
*
* @param b the Buffer object to reference
*/
public Pointer(final Buffer b) {
if (b != null) {
allocate(b);
}
if (!isNull()) {
address -= b.position() * sizeof();
position = b.position();
limit = b.limit();
capacity = b.capacity();
deallocator = new Deallocator() { Buffer bb = b; public void deallocate() { bb = null; } };
}
}
private native void allocate(Buffer b);
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static void onBufferAllocated(Buffer buffer) {
if (BufferUtils.trackDirectMemory) {
if (BufferUtils.cleanupthread == null) {
BufferUtils.cleanupthread = new ClearReferences();
BufferUtils.cleanupthread.start();
}
if (buffer instanceof ByteBuffer) {
BufferInfo info = new BufferInfo(ByteBuffer.class, buffer.capacity(), buffer,
BufferUtils.removeCollected);
BufferUtils.trackedBuffers.put(info, info);
} else if (buffer instanceof FloatBuffer) {
BufferInfo info = new BufferInfo(FloatBuffer.class, buffer.capacity() * 4, buffer,
BufferUtils.removeCollected);
BufferUtils.trackedBuffers.put(info, info);
} else if (buffer instanceof IntBuffer) {
BufferInfo info = new BufferInfo(IntBuffer.class, buffer.capacity() * 4, buffer,
BufferUtils.removeCollected);
BufferUtils.trackedBuffers.put(info, info);
} else if (buffer instanceof ShortBuffer) {
BufferInfo info = new BufferInfo(ShortBuffer.class, buffer.capacity() * 2, buffer,
BufferUtils.removeCollected);
BufferUtils.trackedBuffers.put(info, info);
} else if (buffer instanceof DoubleBuffer) {
BufferInfo info = new BufferInfo(DoubleBuffer.class, buffer.capacity() * 8, buffer,
BufferUtils.removeCollected);
BufferUtils.trackedBuffers.put(info, info);
}
}
}
代码示例来源:origin: robovm/robovm
public AudioValueTranslation setInputData(Buffer data) {
setInputDataSize(data.capacity());
setInputData0(BufferMarshaler.toNative(data, 0));
return this;
}
private AudioValueTranslation setInputArrayData(Object array, int length) {
代码示例来源:origin: robovm/robovm
public AudioBuffer setData(Buffer data) {
setDataByteSize(data.capacity());
setData0(BufferMarshalers.BufferMarshaler.toNative(data, 0));
return this;
}
private AudioBuffer setArrayData(Object array, int length) {
代码示例来源:origin: robovm/robovm
public AudioQueueBuffer setAudioData(Buffer data) {
setAudioDataByteSize(data.capacity());
setData0(BufferMarshalers.BufferMarshaler.toNative(data, 0));
return this;
}
private AudioQueueBuffer setArrayAudioData(Object array, int length) {
代码示例来源:origin: Rajawali/Rajawali
public static int[] getIntArrayFromBuffer(Buffer buffer) {
int[] array = new int[0];
if (buffer != null) {
if (buffer.hasArray()) {
array = (int[]) buffer.array();
} else {
buffer.rewind();
array = new int[buffer.capacity()];
if (buffer instanceof IntBuffer) {
((IntBuffer) buffer).get(array);
} else if (buffer instanceof ShortBuffer) {
int count = 0;
while (buffer.hasRemaining()) {
array[count] = (int) (((ShortBuffer) buffer).get());
++count;
}
}
}
}
return array;
}
代码示例来源:origin: Rajawali/Rajawali
/**
* Creates an int array from the provided {@link IntBuffer} or {@link ShortBuffer}.
*
* @param buffer {@link Buffer} the data source. Should be either a {@link IntBuffer}
* or {@link ShortBuffer}.
* @return int array containing the data of the buffer.
*/
public static int[] getIntArrayFromBuffer(Buffer buffer) {
int[] array = null;
if (buffer.hasArray()) {
array = (int[]) buffer.array();
} else {
buffer.rewind();
array = new int[buffer.capacity()];
if (buffer instanceof IntBuffer) {
((IntBuffer) buffer).get(array);
} else if (buffer instanceof ShortBuffer) {
int count = 0;
while (buffer.hasRemaining()) {
array[count] = (int) (((ShortBuffer) buffer).get());
++count;
}
}
}
return array;
}
}
代码示例来源:origin: Rajawali/Rajawali
buffer.rewind();
GLES20.glBindBuffer(target, handle);
GLES20.glBufferData(target, buffer.capacity() * byteSize, buffer, usage);
GLES20.glBindBuffer(target, 0);
代码示例来源:origin: google/guava
public void testGet_io() throws IOException {
assertEquals(-1, ArbitraryInstances.get(InputStream.class).read());
assertEquals(-1, ArbitraryInstances.get(ByteArrayInputStream.class).read());
assertEquals(-1, ArbitraryInstances.get(Readable.class).read(CharBuffer.allocate(1)));
assertEquals(-1, ArbitraryInstances.get(Reader.class).read());
assertEquals(-1, ArbitraryInstances.get(StringReader.class).read());
assertEquals(0, ArbitraryInstances.get(Buffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(CharBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(ByteBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(ShortBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(IntBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(LongBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(FloatBuffer.class).capacity());
assertEquals(0, ArbitraryInstances.get(DoubleBuffer.class).capacity());
ArbitraryInstances.get(PrintStream.class).println("test");
ArbitraryInstances.get(PrintWriter.class).println("test");
assertNotNull(ArbitraryInstances.get(File.class));
assertFreshInstanceReturned(
ByteArrayOutputStream.class, OutputStream.class,
Writer.class, StringWriter.class,
PrintStream.class, PrintWriter.class);
assertEquals(ByteSource.empty(), ArbitraryInstances.get(ByteSource.class));
assertEquals(CharSource.empty(), ArbitraryInstances.get(CharSource.class));
assertNotNull(ArbitraryInstances.get(ByteSink.class));
assertNotNull(ArbitraryInstances.get(CharSink.class));
}
内容来源于网络,如有侵权,请联系作者删除!