Search in sources :

Example 26 with InvalidMarkException

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;
}
Also used : InvalidMarkException(java.nio.InvalidMarkException)

Example 27 with InvalidMarkException

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);
}
Also used : ValueBuffer(org.openhab.core.io.transport.modbus.ValueBuffer) InvalidMarkException(java.nio.InvalidMarkException) Test(org.junit.jupiter.api.Test)

Example 28 with InvalidMarkException

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;
}
Also used : InvalidMarkException(java.nio.InvalidMarkException)

Example 29 with InvalidMarkException

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;
}
Also used : InvalidMarkException(java.nio.InvalidMarkException)

Example 30 with InvalidMarkException

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);
    }
}
Also used : CharBuffer(java.nio.CharBuffer) InvalidMarkException(java.nio.InvalidMarkException)

Aggregations

InvalidMarkException (java.nio.InvalidMarkException)50 ByteBuffer (java.nio.ByteBuffer)20 Buffer (java.nio.Buffer)12 CharBuffer (java.nio.CharBuffer)4 DoubleBuffer (java.nio.DoubleBuffer)4 FloatBuffer (java.nio.FloatBuffer)4 IntBuffer (java.nio.IntBuffer)4 LongBuffer (java.nio.LongBuffer)4 ShortBuffer (java.nio.ShortBuffer)4 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 Test (org.junit.jupiter.api.Test)1 ValueBuffer (org.openhab.core.io.transport.modbus.ValueBuffer)1