use of java.nio.InvalidMarkException in project dempsy-commons by Dempsy.
the class MegaByteBufferRelativeMetadata method reset.
/**
* Resets this buffer's position to the previously-marked position.
*
* <p>
* Invoking this method neither changes nor discards the mark's
* value.
* </p>
*
* @return This buffer
*
* @throws InvalidMarkException
* If the mark has not been set
*/
public MegaByteBufferRelativeMetadata reset() {
final long m = mark;
if (m < 0)
throw new InvalidMarkException();
position = m;
return this;
}
use of java.nio.InvalidMarkException in project openhab-core by openhab.
the class ValueBufferTest method testMarkHigherThanPosition.
@Test
public void testMarkHigherThanPosition() {
ValueBuffer wrap = ValueBuffer.wrap(new byte[] { (byte) 0xFF, (byte) 0xFF, (byte) 0xFC, 0x14, 3, -1, -2 });
assertEquals(-1004, wrap.getSInt32());
wrap.position(4);
wrap.mark();
assertEquals(4, wrap.position());
// mark = position
wrap.position(4);
assertEquals(4, wrap.position());
wrap.reset();
assertEquals(4, wrap.position());
// position < mark
// Mark is removed here
wrap.position(3);
assertEquals(3, wrap.position());
boolean caughtException = false;
try {
wrap.reset();
} catch (InvalidMarkException e) {
// OK, expected
caughtException = true;
}
assertTrue(caughtException);
assertEquals(3, wrap.position());
// Mark is removed. Reset unaccessible even with original position of 4
wrap.position(4);
assertEquals(4, wrap.position());
caughtException = false;
try {
wrap.reset();
} catch (InvalidMarkException e) {
// OK, expected
caughtException = true;
}
assertTrue(caughtException);
}
use of java.nio.InvalidMarkException in project eec by wangguanquan.
the class SharedStringTable method reset.
/**
* Resets this buffer's position to the previously-marked position.
*
* Invoking this method neither changes nor discards the mark's
* value.
*
* @return This SharedStringTable
*
* @throws InvalidMarkException If the mark has not been set
* @throws IOException if I/O error occur
*/
protected SharedStringTable reset() throws IOException {
if (mark == -1)
throw new InvalidMarkException();
channel.position(mark);
mark = -1;
buffer.clear();
return this;
}
use of java.nio.InvalidMarkException in project AtlasMC by Segurad.
the class CharSequenceReader method reset.
@Override
public void reset() throws IOException {
if (mark == -1)
throw new InvalidMarkException();
readerIndex = mark;
mark = -1;
}
use of java.nio.InvalidMarkException in project j2objc by google.
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);
}
}
Aggregations