use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method testAmqpValueWithList.
public void testAmqpValueWithList() throws Exception {
final List<Object> originalList = new ArrayList<>();
originalList.add(new Binary(new byte[] { 0x00, (byte) 0xFF }));
originalList.add(42);
originalList.add(null);
final AmqpValue amqpValue = new AmqpValue(originalList);
Message_1_0 sourceMessage = createTestMessage(amqpValue.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
assertEquals("Unexpected mime type", "jms/stream-message", convertedMessage.getMessageHeader().getMimeType());
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
List<Object> convertedList = new JmsStreamMessageToList().toObject(getBytes(content));
assertEquals("Unexpected size", originalList.size(), convertedList.size());
assertArrayEquals("Unexpected binary item", ((Binary) originalList.get(0)).getArray(), (byte[]) convertedList.get(0));
assertEquals("Unexpected int item", originalList.get(1), convertedList.get(1));
assertEquals("Unexpected null item", originalList.get(2), convertedList.get(2));
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageConverter_1_0_to_v0_8Test method doTestConvertOfDataSectionForTextualType.
private void doTestConvertOfDataSectionForTextualType(final String contentType) throws Exception {
final String expected = "testContent";
final Data value = new Data(new Binary(expected.getBytes(UTF_8)));
final Properties properties = new Properties();
properties.setContentType(Symbol.valueOf(contentType));
Message_1_0 sourceMessage = createTestMessage(properties, value.createEncodingRetainingSection());
final AMQMessage convertedMessage = _converter.convert(sourceMessage, mock(NamedAddressSpace.class));
final QpidByteBuffer content = convertedMessage.getContent(0, (int) convertedMessage.getSize());
assertEquals("Unexpected content", expected, new String(getBytes(content), UTF_8));
assertEquals("Unexpected mime type", "text/plain", convertedMessage.getMessageHeader().getMimeType());
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class Deserializer method readUUID.
UUID readUUID() throws IOException {
byte[] data = readBytes(16);
try (QpidByteBuffer buf = QpidByteBuffer.wrap(data)) {
long msb = buf.getLong();
long lsb = buf.getLong();
return new UUID(msb, lsb);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageStoreSerializer_v1 method deserializeMessages.
private Record deserializeMessages(final Map<Long, StoredMessage<?>> messageNumberMap, final MessageStore store, final Deserializer deserializer, Record record) throws IOException {
while (record.getType() == RecordType.MESSAGE) {
MessageRecord messageRecord = (MessageRecord) record;
long originalMessageNumber = messageRecord.getMessageNumber();
byte[] metaData = messageRecord.getMetaData();
final MessageMetaDataType metaDataType = MessageMetaDataTypeRegistry.fromOrdinal(metaData[0] & 0xff);
final MessageHandle<StorableMessageMetaData> handle;
try (QpidByteBuffer buf = QpidByteBuffer.wrap(metaData, 1, metaData.length - 1)) {
try {
StorableMessageMetaData storableMessageMetaData = metaDataType.createMetaData(buf);
handle = store.addMessage(storableMessageMetaData);
} catch (ConnectionScopedRuntimeException e) {
throw new IllegalArgumentException("Could not deserialize message metadata", e);
}
}
try (QpidByteBuffer buf = QpidByteBuffer.wrap(messageRecord.getContent())) {
handle.addContent(buf);
}
final StoredMessage<StorableMessageMetaData> storedMessage = handle.allContentAdded();
messageNumberMap.put(originalMessageNumber, storedMessage);
storedMessage.flowToDisk();
record = deserializer.readRecord();
}
return record;
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class NonBlockingConnection method readFromNetwork.
protected long readFromNetwork() throws IOException {
QpidByteBuffer buffer = _delegate.getNetInputBuffer();
long read = buffer.read(_socketChannel);
if (read == -1) {
_closed.set(true);
}
_partialRead = read != 0;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Read " + read + " byte(s)");
}
return read;
}
Aggregations