Search in sources :

Example 6 with ActiveMQBufferInputStream

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();
}
Also used : ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 7 with ActiveMQBufferInputStream

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();
}
Also used : LargeMessageControllerImpl(org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl) DataInputStream(java.io.DataInputStream) ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) Test(org.junit.Test)

Example 8 with ActiveMQBufferInputStream

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);
}
Also used : ActiveMQBufferInputStream(org.apache.activemq.artemis.utils.ActiveMQBufferInputStream) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Aggregations

ActiveMQBufferInputStream (org.apache.activemq.artemis.utils.ActiveMQBufferInputStream)8 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)4 Test (org.junit.Test)4 DataInputStream (java.io.DataInputStream)3 LargeMessageControllerImpl (org.apache.activemq.artemis.core.client.impl.LargeMessageControllerImpl)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 InflaterReader (org.apache.activemq.artemis.utils.InflaterReader)1