/** * @see ByteBuffer#getInt() */ public int getInt() { return getInt(position); }
private float getFloat(Pointer pos) { return Float.intBitsToFloat(getInt(pos)); }
/** * @see ByteBuffer#getInt(int) */ public int getInt(int index) { return getInt(getPointerByPosition(index)); }
/** * Test the getInt() method, on a buffer containing 1 incomplet int spread * in two ByteBuffers */ @Test(expected = BufferUnderflowException.class) public void testGetIntIncompletInt2BBs() { ByteBuffer bb1 = ByteBuffer.allocate(1); bb1.put((byte) 0x01); bb1.flip(); ByteBuffer bb2 = ByteBuffer.allocate(2); bb2.put(new byte[] { 0x02, 0x03 }); bb2.flip(); IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2); ioBuffer.getInt(); }
/** * Test the getInt() method, on a buffer containing 2 ints in one ByteBuffer */ @Test public void testGetInt2IntsOneBB() { ByteBuffer bb = ByteBuffer.allocate(8); bb.putInt(12345); bb.putInt(67890); bb.flip(); IoBuffer ioBuffer = IoBuffer.wrap(bb); assertEquals(12345, ioBuffer.getInt()); assertEquals(67890, ioBuffer.getInt()); }
/** * Test the getInt() method, on a buffer containing 2 ints in two * ByteBuffers */ @Test public void testGetInt2Ints2BBs() { ByteBuffer bb1 = ByteBuffer.allocate(4); bb1.putInt(12345); bb1.flip(); ByteBuffer bb2 = ByteBuffer.allocate(4); bb2.putInt(67890); bb2.flip(); IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2); assertEquals(12345, ioBuffer.getInt()); assertEquals(67890, ioBuffer.getInt()); }
/** * Test the getInt() method, on a buffer containing 1 int spread in two * ByteBuffers */ @Test public void testGetInt1Int2BBs() { ByteBuffer bb1 = ByteBuffer.allocate(1); bb1.put((byte) 0x01); bb1.flip(); ByteBuffer bb2 = ByteBuffer.allocate(3); bb2.put(new byte[] { 0x02, 0x03, 0x04 }); bb2.flip(); IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2); assertEquals(0x01020304, ioBuffer.getInt()); }
/** * Test the getInt() method, on a buffer containing 2 ints in two * ByteBuffers with LittleInidan order */ @Test public void testGetInt2Ints2BBsLittleIndian() { ByteBuffer bb1 = ByteBuffer.allocate(4); bb1.order(ByteOrder.LITTLE_ENDIAN); bb1.putInt(12345); bb1.flip(); ByteBuffer bb2 = ByteBuffer.allocate(4); bb2.order(ByteOrder.LITTLE_ENDIAN); bb2.putInt(67890); bb2.flip(); IoBuffer ioBuffer = IoBuffer.wrap(bb1, bb2); ioBuffer.order(ByteOrder.LITTLE_ENDIAN); assertEquals(12345, ioBuffer.getInt()); assertEquals(67890, ioBuffer.getInt()); }
@Test public void testInt() { for (ByteOrder bo : new ByteOrder[] { ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN }) { ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(5).order(bo).putInt(123456).rewind(); IoBuffer ioBuffer = IoBuffer.wrap(bb).order(bo); assertEquals(5, ioBuffer.capacity()); ioBuffer.extend(3); ioBuffer.position(4); assertEquals(8, ioBuffer.capacity()); ioBuffer.putInt(-23456789); ioBuffer.rewind(); assertEquals(123456, ioBuffer.getInt()); assertEquals(-23456789, ioBuffer.getInt()); ioBuffer.rewind(); ioBuffer.putInt(2, 1234567890); assertEquals(1234567890, ioBuffer.getInt(2)); try { ioBuffer.putInt(5, 1); fail("Not enough place on the buffer"); } catch (BufferUnderflowException e) { // Should come here } try { ioBuffer.getInt(5); fail("Not enough place on the buffer"); } catch (BufferUnderflowException e) { // Should come here } } }