use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class NonBlockingConnectionUndecidedDelegate method processData.
@Override
public boolean processData() throws IOException {
try (QpidByteBuffer buffer = _netInputBuffer.duplicate()) {
buffer.flip();
final boolean hasSufficientData = buffer.remaining() >= NUMBER_OF_BYTES_FOR_TLS_CHECK;
if (hasSufficientData) {
final byte[] headerBytes = new byte[NUMBER_OF_BYTES_FOR_TLS_CHECK];
buffer.get(headerBytes);
if (looksLikeSSL(headerBytes)) {
_parent.setTransportEncryption(TransportEncryption.TLS);
} else {
_parent.setTransportEncryption(TransportEncryption.NONE);
}
}
return hasSufficientData;
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class InternalMessage method createMessage.
public static InternalMessage createMessage(final MessageStore store, final AMQMessageHeader header, final Serializable bodyObject, final boolean persistent, final String destinationName) {
InternalMessageHeader internalHeader;
if (header instanceof InternalMessageHeader) {
internalHeader = (InternalMessageHeader) header;
} else {
internalHeader = new InternalMessageHeader(header);
}
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
try (ObjectOutputStream os = new ObjectOutputStream(bytesOut)) {
os.writeObject(bodyObject);
os.close();
byte[] bytes = bytesOut.toByteArray();
final InternalMessageMetaData metaData = InternalMessageMetaData.create(persistent, internalHeader, bytes.length);
MessageHandle<InternalMessageMetaData> handle = store.addMessage(metaData);
final StoredMessage<InternalMessageMetaData> storedMessage;
try (QpidByteBuffer wrap = QpidByteBuffer.wrap(bytes)) {
handle.addContent(wrap);
}
storedMessage = handle.allContentAdded();
return new InternalMessage(storedMessage, internalHeader, bodyObject, destinationName);
} catch (IOException e) {
throw new ConnectionScopedRuntimeException("Unexpected IO Exception on operation in memory", e);
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class FieldTable method getDataAsBytes.
public synchronized byte[] getDataAsBytes() {
if (_encodedForm == null) {
byte[] data = new byte[(int) getEncodedSize()];
QpidByteBuffer buf = QpidByteBuffer.wrap(data);
putDataInBuffer(buf);
return data;
} else {
byte[] encodedCopy = new byte[_encodedForm.remaining()];
_encodedForm.copyTo(encodedCopy);
return encodedCopy;
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class ByteBufferBinding method objectToEntry.
@Override
public void objectToEntry(QpidByteBuffer data, final TupleOutput output) {
try (QpidByteBuffer dup = data.duplicate()) {
byte[] copyBuf = COPY_BUFFER.get();
while (dup.hasRemaining()) {
int length = Math.min(COPY_BUFFER_SIZE, dup.remaining());
dup.get(copyBuf, 0, length);
output.write(copyBuf, 0, length);
}
}
}
use of org.apache.qpid.server.bytebuffer.QpidByteBuffer in project qpid-broker-j by apache.
the class MessageMetaDataBinding method entryToObject.
@Override
public StorableMessageMetaData entryToObject(DatabaseEntry entry) {
try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(entry.getData(), entry.getOffset(), entry.getSize()))) {
final int bodySize = stream.readInt() ^ 0x80000000;
final int metaDataType = stream.readByte() & 0xff;
MessageMetaDataType type = MessageMetaDataTypeRegistry.fromOrdinal(metaDataType);
try (QpidByteBuffer buf = QpidByteBuffer.asQpidByteBuffer(stream)) {
return type.createMetaData(buf);
}
} catch (IOException | RuntimeException e) {
throw new StoreException(String.format("Unable to convert entry %s to metadata", entry));
}
}
Aggregations