use of java.nio.InvalidMarkException in project robovm by robovm.
the class CharBufferTest method testSlice.
public void testSlice() {
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(buf.capacity() - 1);
CharBuffer slice = buf.slice();
assertEquals(buf.isReadOnly(), slice.isReadOnly());
assertEquals(buf.isDirect(), slice.isDirect());
assertEquals(buf.order(), slice.order());
assertEquals(slice.position(), 0);
assertEquals(slice.limit(), buf.remaining());
assertEquals(slice.capacity(), buf.remaining());
try {
slice.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// slice share the same content with buf
if (!slice.isReadOnly()) {
loadTestData1(slice);
assertContentLikeTestData1(buf, 1, (char) 0, slice.capacity());
buf.put(2, (char) 500);
assertEquals(slice.get(1), 500);
}
}
use of java.nio.InvalidMarkException in project robovm by robovm.
the class CharBufferTest method testCompact.
public void testCompact() {
// case: buffer is full
buf.clear();
buf.mark();
loadTestData1(buf);
CharBuffer ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), buf.capacity());
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (char) 0, buf.capacity());
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: buffer is empty
buf.position(0);
buf.limit(0);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 0);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (char) 0, buf.capacity());
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// case: normal
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(5);
buf.mark();
ret = buf.compact();
assertSame(ret, buf);
assertEquals(buf.position(), 4);
assertEquals(buf.limit(), buf.capacity());
assertContentLikeTestData1(buf, 0, (char) 1, 4);
try {
buf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
}
use of java.nio.InvalidMarkException in project robovm by robovm.
the class DoubleBufferTest method testSlice.
public void testSlice() {
assertTrue(buf.capacity() > 5);
buf.position(1);
buf.limit(buf.capacity() - 1);
DoubleBuffer slice = buf.slice();
assertEquals(buf.isReadOnly(), slice.isReadOnly());
assertEquals(buf.isDirect(), slice.isDirect());
assertEquals(buf.order(), slice.order());
assertEquals(slice.position(), 0);
assertEquals(slice.limit(), buf.remaining());
assertEquals(slice.capacity(), buf.remaining());
try {
slice.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
// FIXME:
if (!slice.isReadOnly()) {
loadTestData1(slice);
assertContentLikeTestData1(buf, 1, 0, slice.capacity());
buf.put(2, 500);
assertEquals(slice.get(1), 500, 0.0);
}
}
use of java.nio.InvalidMarkException in project robovm by robovm.
the class AbstractBufferTest method testLimitint.
/*
* Class under test for Buffer limit(int)
*/
public void testLimitint() {
// save state
int oldPosition = baseBuf.position();
int oldLimit = baseBuf.limit();
Buffer ret = baseBuf.limit(baseBuf.limit());
assertSame(ret, baseBuf);
baseBuf.mark();
baseBuf.limit(baseBuf.capacity());
assertEquals(baseBuf.limit(), baseBuf.capacity());
// position should not change
assertEquals(baseBuf.position(), oldPosition);
// mark should be valid
baseBuf.reset();
if (baseBuf.capacity() > 0) {
baseBuf.limit(baseBuf.capacity());
baseBuf.position(baseBuf.capacity());
baseBuf.mark();
baseBuf.limit(baseBuf.capacity() - 1);
// position should be the new limit
assertEquals(baseBuf.position(), baseBuf.limit());
// mark should be invalid
try {
baseBuf.reset();
//$NON-NLS-1$
fail("Should throw Exception");
} catch (InvalidMarkException e) {
// expected
}
}
try {
baseBuf.limit(-1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IllegalArgumentException e) {
// expected
}
try {
baseBuf.limit(baseBuf.capacity() + 1);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (IllegalArgumentException e) {
// expected
}
// restore state
baseBuf.limit(oldLimit);
baseBuf.position(oldPosition);
}
use of java.nio.InvalidMarkException in project hbase by apache.
the class MultiByteBuff method reset.
/**
* Similar to {@link ByteBuffer}.reset(), ensures that this MBB
* is reset back to last marked position.
* @return This MBB
*/
@Override
public MultiByteBuff reset() {
// 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;
}
Aggregations