Here you can find the source of createShortBuffer(int capacity)
Parameter | Description |
---|---|
capacity | buffer capacity |
public static ShortBuffer createShortBuffer(int capacity)
//package com.java2s; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; public class Main { /**/* w w w. j a va2s . com*/ * Creates a ShortBuffer with the specified capacity. * * @param capacity * buffer capacity * @return ShortBuffer with the specified capacity */ public static ShortBuffer createShortBuffer(int capacity) { return createByteBuffer(capacity * 2).asShortBuffer(); } /** * Creates a ShortBuffer from the specified short array. * * @param data * short array to convert to a ShortBuffer * @return ShortBuffer with the same content as data */ public static ShortBuffer createShortBuffer(short[] data) { ShortBuffer b = createShortBuffer(data.length); b.put(data); b.rewind(); return b; } /** * Creates a ByteBuffer with the specified capacity. * * @param capacity * buffer capacity * @return ByteBuffer with the specified capacity */ public static ByteBuffer createByteBuffer(int capacity) { ByteBuffer b = ByteBuffer.allocateDirect(capacity); b.order(ByteOrder.nativeOrder()); return b; } /** * Creates a ByteBuffer from the specified byte array. * * @param data * byte array to convert to a ByteBuffer * @return ByteBuffer with the same content as data */ public static ByteBuffer createByteBuffer(byte[] data) { ByteBuffer b = createByteBuffer(data.length); b.put(data); b.rewind(); return b; } }