List of usage examples for java.nio Buffer rewind
public final Buffer rewind()
From source file:Main.java
/** * Creates an int array from the provided {@link IntBuffer} or {@link ShortBuffer}. * //from ww w . jav a2s . co m * @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; }