use of java.nio.BufferUnderflowException in project geode by apache.
the class ByteSourceJUnitTest method testGetByteArrayIntInt.
@Test
public void testGetByteArrayIntInt() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
byte[] bytes = new byte[10];
bs.get(bytes, 0, 2);
assertEquals(2, bs.position());
bs.get(bytes, 2, 0);
assertEquals(2, bs.position());
bs.get(bytes, 2, 3);
assertEquals(5, bs.position());
try {
bs.get(bytes, 4, 6);
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
bs.get(bytes, 5, 5);
assertEquals(10, bs.position());
bs.get(bytes, 10, 0);
assertEquals(10, bs.position());
assertArrayEquals(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }, bytes);
try {
bs.get(bytes, 9, 1);
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
try {
bs.get(bytes, 10, 1);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
try {
bs.get(bytes, 3, -1);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
try {
bs.get(bytes, -1, 2);
fail("expected IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException expected) {
}
}
use of java.nio.BufferUnderflowException in project geode by apache.
the class ByteSourceJUnitTest method testGetByteArray.
@Test
public void testGetByteArray() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
byte[] bytes = new byte[2];
bs.get(bytes);
assertArrayEquals(new byte[] { 1, 2 }, bytes);
assertEquals(2, bs.position());
bytes = new byte[0];
bs.get(bytes);
assertEquals(2, bs.position());
bytes = new byte[3];
bs.get(bytes);
assertArrayEquals(new byte[] { 3, 4, 5 }, bytes);
assertEquals(5, bs.position());
try {
bytes = new byte[6];
bs.get(bytes);
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
bytes = new byte[5];
bs.get(bytes);
assertArrayEquals(new byte[] { 6, 7, 8, 9, 0 }, bytes);
assertEquals(10, bs.position());
bytes = new byte[0];
bs.get(bytes);
assertEquals(10, bs.position());
try {
bytes = new byte[1];
bs.get(bytes);
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of java.nio.BufferUnderflowException in project geode by apache.
the class ByteSourceJUnitTest method testGetInt1.
@Test
public void testGetInt1() {
ByteBuffer bb = ByteBuffer.allocate(20);
IntBuffer ib = bb.asIntBuffer();
ib.put(0x11102233);
ib.put(0x22203344);
ib.put(0x33304455);
ib.put(0x44405566);
ib.put(0x55506677);
byte[] bytes = bb.array();
ByteSource bs = createByteSource(bytes);
int i = bs.getInt();
assertEquals(0x11102233, i);
assertEquals(4, bs.position());
i = bs.getInt();
assertEquals(0x22203344, i);
assertEquals(8, bs.position());
bs.position(4 * 4);
i = bs.getInt();
assertEquals(0x55506677, i);
assertEquals(20, bs.position());
try {
bs.getInt();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of java.nio.BufferUnderflowException in project geode by apache.
the class ByteSourceJUnitTest method testGet.
@Test
public void testGet() {
ByteSource bs = createByteSource(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 });
byte b = bs.get();
assertEquals(1, b);
assertEquals(1, bs.position());
b = bs.get();
assertEquals(2, b);
assertEquals(2, bs.position());
bs.position(bs.limit() - 1);
b = bs.get();
assertEquals(0, b);
assertEquals(10, bs.position());
try {
bs.get();
fail("expected BufferUnderflowException");
} catch (BufferUnderflowException expected) {
}
}
use of java.nio.BufferUnderflowException in project intellij-community by JetBrains.
the class Native2AsciiCharsetDecoder method decodeLoop.
@Override
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
try {
CoderResult coderResult = doFlush(out);
if (coderResult == CoderResult.OVERFLOW)
return CoderResult.OVERFLOW;
int start = in.position();
byte[] buf = new byte[4];
while (in.position() < in.limit()) {
in.mark();
final byte b = in.get();
if (b == '\\') {
decodeArray(in.array(), start, in.position() - 1);
byte next = in.get();
if (next == 'u') {
buf[0] = in.get();
buf[1] = in.get();
buf[2] = in.get();
buf[3] = in.get();
char decoded = unicode(buf);
if (decoded == INVALID_CHAR) {
myOutBuffer.append("\\u");
myOutBuffer.append((char) buf[0]);
myOutBuffer.append((char) buf[1]);
myOutBuffer.append((char) buf[2]);
myOutBuffer.append((char) buf[3]);
} else {
myOutBuffer.append(decoded);
}
} else {
myOutBuffer.append("\\");
myOutBuffer.append((char) next);
}
start = in.position();
}
}
decodeArray(in.array(), start, in.position());
} catch (BufferUnderflowException e) {
in.reset();
}
return doFlush(out);
}
Aggregations