@TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "", method = "clear", args = {} ) public void testClear() { // save state int oldPosition = baseBuf.position(); int oldLimit = baseBuf.limit(); Buffer ret = baseBuf.clear(); assertSame(ret, baseBuf); assertEquals(0, baseBuf.position()); assertEquals(baseBuf.limit(), baseBuf.capacity()); try { baseBuf.reset(); fail("Should throw Exception"); } catch (InvalidMarkException e) { // expected } // restore state baseBuf.limit(oldLimit); baseBuf.position(oldPosition); }
@TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "", method = "rewind", args = {} ) public void testRewind() { // save state int oldPosition = baseBuf.position(); int oldLimit = baseBuf.limit(); Buffer ret = baseBuf.rewind(); assertEquals(0, baseBuf.position()); assertSame(ret, baseBuf); try { baseBuf.reset(); fail("Should throw Exception"); } catch (InvalidMarkException e) { // expected } // restore state baseBuf.limit(oldLimit); baseBuf.position(oldPosition); }
/** * Similar to {@link ByteBuffer}.reset(), ensures that this MBB * is reset back to last marked position. * @return This MBB */ @Override public MultiByteBuff reset() { // when the buffer is moved to the next one.. the reset should happen on the previous marked // item and the new one should be taken as the base if (this.markedItemIndex < 0) throw new InvalidMarkException(); ByteBuffer markedItem = this.items[this.markedItemIndex]; markedItem.reset(); this.curItem = markedItem; // All items after the marked position upto the current item should be reset to 0 for (int i = this.curItemIndex; i > this.markedItemIndex; i--) { this.items[i].position(0); } this.curItemIndex = this.markedItemIndex; return this; }
public void testClear() { // save state int oldPosition = baseBuf.position(); int oldLimit = baseBuf.limit(); Buffer ret = baseBuf.clear(); assertSame(ret, baseBuf); assertEquals(baseBuf.position(), 0); assertEquals(baseBuf.limit(), baseBuf.capacity()); try { baseBuf.reset(); fail("Should throw Exception"); //$NON-NLS-1$S } catch (InvalidMarkException e) { // expected } // restore state baseBuf.limit(oldLimit); baseBuf.position(oldPosition); }
public void testFlip() { // save state int oldPosition = baseBuf.position(); int oldLimit = baseBuf.limit(); Buffer ret = baseBuf.flip(); assertSame(ret, baseBuf); assertEquals(baseBuf.position(), 0); assertEquals(baseBuf.limit(), oldPosition); try { baseBuf.reset(); fail("Should throw Exception"); //$NON-NLS-1$ } catch (InvalidMarkException e) { // expected } // restore state baseBuf.limit(oldLimit); baseBuf.position(oldPosition); }
public void testRewind() { // save state int oldPosition = baseBuf.position(); int oldLimit = baseBuf.limit(); Buffer ret = baseBuf.rewind(); assertEquals(baseBuf.position(), 0); assertSame(ret, baseBuf); try { baseBuf.reset(); fail("Should throw Exception"); //$NON-NLS-1$ } catch (InvalidMarkException e) { // expected } // restore state baseBuf.limit(oldLimit); baseBuf.position(oldPosition); }
public static void testClear(Buffer buf) { // save state int oldPosition = buf.position(); int oldLimit = buf.limit(); Buffer ret = buf.clear(); assertSame(ret, buf); assertEquals(buf.position(), 0); assertEquals(buf.limit(), buf.capacity()); try { buf.reset(); fail("Should throw Exception"); //$NON-NLS-1$ } catch (InvalidMarkException e) { // expected } // restore state buf.limit(oldLimit); buf.position(oldPosition); }
public static void testFlip(Buffer buf) { // save state int oldPosition = buf.position(); int oldLimit = buf.limit(); Buffer ret = buf.flip(); assertSame(ret, buf); assertEquals(buf.position(), 0); assertEquals(buf.limit(), oldPosition); try { buf.reset(); fail("Should throw Exception"); //$NON-NLS-1$ } catch (InvalidMarkException e) { // expected } // restore state buf.limit(oldLimit); buf.position(oldPosition); }
public static void testRewind(Buffer buf) { // save state int oldPosition = buf.position(); int oldLimit = buf.limit(); Buffer ret = buf.rewind(); assertEquals(buf.position(), 0); assertSame(ret, buf); try { buf.reset(); fail("Should throw Exception"); //$NON-NLS-1$ } catch (InvalidMarkException e) { // expected } // restore state buf.limit(oldLimit); buf.position(oldPosition); }
@Test public void allocatesSimple() { LongBuffer buffer = LongBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }
@Test public void wrapsArray() { long[] array = new long[100]; LongBuffer buffer = LongBuffer.wrap(array, 10, 70); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.array(), is(array)); assertThat(buffer.arrayOffset(), is(0)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(10)); assertThat(buffer.limit(), is(80)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } array[0] = 23; assertThat(buffer.get(0), is((long) 23)); buffer.put(1, 24); assertThat(array[1], is((long) 24)); }
@Test public void compacts() { long[] array = { 2, 3, 5, 7 }; LongBuffer buffer = LongBuffer.wrap(array); buffer.get(); buffer.mark(); buffer.compact(); assertThat(array, is(new long[] { 3, 5, 7, 7 })); assertThat(buffer.position(), is(3)); assertThat(buffer.limit(), is(4)); assertThat(buffer.capacity(), is(4)); try { buffer.reset(); fail("Exception expected"); } catch (InvalidMarkException e) { // ok } }
@Test public void allocatesSimple() { ShortBuffer buffer = ShortBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }
@Test public void wrapsArray() { short[] array = new short[100]; ShortBuffer buffer = ShortBuffer.wrap(array, 10, 70); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.array(), is(array)); assertThat(buffer.arrayOffset(), is(0)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(10)); assertThat(buffer.limit(), is(80)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } array[0] = 23; assertThat(buffer.get(0), is((short) 23)); buffer.put(1, (short) 24); assertThat(array[1], is((short) 24)); }
@Test public void compacts() { short[] array = { 2, 3, 5, 7 }; ShortBuffer buffer = ShortBuffer.wrap(array); buffer.get(); buffer.mark(); buffer.compact(); assertThat(array, is(new short[] { 3, 5, 7, 7 })); assertThat(buffer.position(), is(3)); assertThat(buffer.limit(), is(4)); assertThat(buffer.capacity(), is(4)); try { buffer.reset(); fail("Exception expected"); } catch (InvalidMarkException e) { // ok } }
@Test public void allocatesSimple() { IntBuffer buffer = IntBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }
@Test public void wrapsArray() { int[] array = new int[100]; IntBuffer buffer = IntBuffer.wrap(array, 10, 70); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.array(), is(array)); assertThat(buffer.arrayOffset(), is(0)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(10)); assertThat(buffer.limit(), is(80)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } array[0] = 23; assertThat(buffer.get(0), is(23)); buffer.put(1, 24); assertThat(array[1], is(24)); }
@Test public void compacts() { int[] array = { 2, 3, 5, 7 }; IntBuffer buffer = IntBuffer.wrap(array); buffer.get(); buffer.mark(); buffer.compact(); assertThat(array, is(new int[] { 3, 5, 7, 7 })); assertThat(buffer.position(), is(3)); assertThat(buffer.limit(), is(4)); assertThat(buffer.capacity(), is(4)); try { buffer.reset(); fail("Exception expected"); } catch (InvalidMarkException e) { // ok } }
@Test public void allocatesSimple() { FloatBuffer buffer = FloatBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }
@Test public void wrapsArray() { float[] array = new float[100]; FloatBuffer buffer = FloatBuffer.wrap(array, 10, 70); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.array(), is(array)); assertThat(buffer.arrayOffset(), is(0)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(10)); assertThat(buffer.limit(), is(80)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } array[0] = 23; assertThat(buffer.get(0), is((float) 23)); buffer.put(1, 24); assertThat(array[1], is((float) 24)); }
@Test public void compacts() { float[] array = { 2, 3, 5, 7 }; FloatBuffer buffer = FloatBuffer.wrap(array); buffer.get(); buffer.mark(); buffer.compact(); assertThat(array, is(new float[] { 3, 5, 7, 7 })); assertThat(buffer.position(), is(3)); assertThat(buffer.limit(), is(4)); assertThat(buffer.capacity(), is(4)); try { buffer.reset(); fail("Exception expected"); } catch (InvalidMarkException e) { // ok } }
@Test public void allocatesSimple() { DoubleBuffer buffer = DoubleBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }
@Test public void wrapsArray() { double[] array = new double[100]; DoubleBuffer buffer = DoubleBuffer.wrap(array, 10, 70); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.array(), is(array)); assertThat(buffer.arrayOffset(), is(0)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(10)); assertThat(buffer.limit(), is(80)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } array[0] = 23; assertThat(buffer.get(0), is((double) 23)); buffer.put(1, 24); assertThat(array[1], is((double) 24)); }
@Test public void compacts() { double[] array = { 2, 3, 5, 7 }; DoubleBuffer buffer = DoubleBuffer.wrap(array); buffer.get(); buffer.mark(); buffer.compact(); assertThat(array, is(new double[] { 3, 5, 7, 7 })); assertThat(buffer.position(), is(3)); assertThat(buffer.limit(), is(4)); assertThat(buffer.capacity(), is(4)); try { buffer.reset(); fail("Exception expected"); } catch (InvalidMarkException e) { // ok } }
@Test public void allocatesSimple() { ByteBuffer buffer = ByteBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }
@Test public void wrapsArray() { byte[] array = new byte[100]; ByteBuffer buffer = ByteBuffer.wrap(array, 10, 70); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.array(), is(array)); assertThat(buffer.arrayOffset(), is(0)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(10)); assertThat(buffer.limit(), is(80)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } array[0] = 23; assertThat(buffer.get(0), is((byte) 23)); buffer.put(1, (byte) 24); assertThat(array[1], is((byte) 24)); }
@Test public void compacts() { byte[] array = {2, 3, 5, 7}; ByteBuffer buffer = ByteBuffer.wrap(array); buffer.get(); buffer.mark(); buffer.compact(); assertThat(array, is(new byte[]{3, 5, 7, 7})); assertThat(buffer.position(), is(3)); assertThat(buffer.limit(), is(4)); assertThat(buffer.capacity(), is(4)); try { buffer.reset(); fail("Exception expected"); } catch (InvalidMarkException e) { // ok } }
@Test public void allocates() { CharBuffer buffer = CharBuffer.allocate(100); assertThat(buffer.isDirect(), is(false)); assertThat(buffer.isReadOnly(), is(false)); assertThat(buffer.hasArray(), is(true)); assertThat(buffer.capacity(), is(100)); assertThat(buffer.position(), is(0)); assertThat(buffer.limit(), is(100)); try { buffer.reset(); fail("Mark is expected to be undefined"); } catch (InvalidMarkException e) { // ok } }