use of org.apache.activemq.artemis.utils.ActiveMQBufferInputStream in project activemq-artemis by apache.
the class ActiveMQBufferInputStreamTest method testReadBytes.
@Test
public void testReadBytes() throws Exception {
byte[] bytes = new byte[10 * 1024];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = getSamplebyte(i);
}
ActiveMQBuffer buffer = ActiveMQBuffers.wrappedBuffer(bytes);
ActiveMQBufferInputStream is = new ActiveMQBufferInputStream(buffer);
// First read byte per byte
for (int i = 0; i < 1024; i++) {
assertEquals(getSamplebyte(i), is.read());
}
// Second, read in chunks
for (int i = 1; i < 10; i++) {
bytes = new byte[1024];
is.read(bytes);
for (int j = 0; j < bytes.length; j++) {
assertEquals(getSamplebyte(i * 1024 + j), bytes[j]);
}
}
assertEquals(-1, is.read());
bytes = new byte[1024];
int sizeRead = is.read(bytes);
assertEquals(-1, sizeRead);
is.close();
}
use of org.apache.activemq.artemis.utils.ActiveMQBufferInputStream in project activemq-artemis by apache.
the class LargeMessageBufferTest method testReadIntegersOverStream.
@Test
public void testReadIntegersOverStream() throws Exception {
LargeMessageControllerImpl buffer = createBufferWithIntegers(3, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
ActiveMQBufferInputStream is = new ActiveMQBufferInputStream(buffer);
DataInputStream dataInput = new DataInputStream(is);
for (int i = 1; i <= 15; i++) {
Assert.assertEquals(i, dataInput.readInt());
}
assertEquals(-1, dataInput.read());
dataInput.close();
}
use of org.apache.activemq.artemis.utils.ActiveMQBufferInputStream in project activemq-artemis by apache.
the class JDBCJournalRecord method setRecord.
public void setRecord(Persister persister, Object record) {
this.variableSize = persister.getEncodeSize(record);
ActiveMQBuffer encodedBuffer = ActiveMQBuffers.fixedBuffer(variableSize);
persister.encode(encodedBuffer, record);
this.record = new ActiveMQBufferInputStream(encodedBuffer);
}
Aggregations