本文整理汇总了Java中org.apache.qpid.proton.amqp.Binary类的典型用法代码示例。如果您正苦于以下问题:Java Binary类的具体用法?Java Binary怎么用?Java Binary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binary类属于org.apache.qpid.proton.amqp包,在下文中一共展示了Binary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendInternal
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
private void sendInternal(ProtonSender sender, String address, byte[] data, Handler<String> sendCompletionHandler) {
Message msg = ProtonHelper.message();
msg.setBody(new Data(new Binary(data)));
msg.setAddress(address);
if (sender.isOpen()) {
sender.send(msg, delivery -> {
if (sendCompletionHandler != null) {
sendCompletionHandler.handle(new String(delivery.getTag()));
}
});
}
}
示例2: givenAMessageHavingProperties
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
private Message givenAMessageHavingProperties(final String deviceId, final String tenantId, final String registrationAssertion,
final String contentType, final byte[] payload) {
final Message msg = ProtonHelper.message("Hello");
msg.setMessageId("test-msg");
MessageHelper.addDeviceId(msg, deviceId);
if (tenantId != null) {
MessageHelper.addTenantId(msg, tenantId);
}
if (registrationAssertion != null) {
MessageHelper.addRegistrationAssertion(msg, registrationAssertion);
}
if (contentType != null) {
msg.setContentType(contentType);
}
if (payload != null) {
msg.setBody(new Data(new Binary(payload)));
}
return msg;
}
示例3: testEncodeDecodeSymbolArrayUsingPutObject
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Test
public void testEncodeDecodeSymbolArrayUsingPutObject()
{
Symbol symbol1 = Symbol.valueOf("testRoundtripSymbolArray1");
Symbol symbol2 = Symbol.valueOf("testRoundtripSymbolArray2");
Symbol[] input = new Symbol[]{symbol1, symbol2};
Data data1 = new DataImpl();
data1.putObject(input);
Binary encoded = data1.encode();
encoded.asByteBuffer();
Data data2 = new DataImpl();
data2.decode(encoded.asByteBuffer());
assertEquals("unexpected array length", 2, data2.getArray());
assertEquals("unexpected array length", Data.DataType.SYMBOL, data2.getArrayType());
Object[] array = data2.getJavaArray();
assertArrayEquals("Array not as expected", input, array);
}
示例4: send
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Override
public final Future<ProtonDelivery> send(final String deviceId, final Map<String, ?> properties, final byte[] payload, final String contentType,
final String registrationAssertion) {
Objects.requireNonNull(deviceId);
Objects.requireNonNull(payload);
Objects.requireNonNull(contentType);
Objects.requireNonNull(registrationAssertion);
final Message msg = ProtonHelper.message();
msg.setAddress(getTo(deviceId));
msg.setBody(new Data(new Binary(payload)));
setApplicationProperties(msg, properties);
addProperties(msg, deviceId, contentType, registrationAssertion);
addEndpointSpecificProperties(msg, deviceId);
return send(msg);
}
示例5: testEncodeStringBinary32
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Test
public void testEncodeStringBinary32()
{
byte[] payload = createStringPayloadBytes(1372);
assertTrue("Length must be over 255 to ensure use of vbin32 encoding", payload.length > 255);
int encodedSize = 1 + 4 + payload.length; // 1b type + 4b length + content
ByteBuffer expectedEncoding = ByteBuffer.allocate(encodedSize);
expectedEncoding.put((byte) 0xB0);
expectedEncoding.putInt(payload.length);
expectedEncoding.put(payload);
Data data = new DataImpl();
data.putBinary(new Binary(payload));
Binary encoded = data.encode();
assertEquals("unexpected encoding", new Binary(expectedEncoding.array()), encoded);
}
示例6: encodeIdToJson
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
/**
* Encodes the given ID object to JSON representation. Supported types for AMQP 1.0 correlation/messageIds are
* String, UnsignedLong, UUID and Binary.
*
* @param id The identifier to encode to JSON
* @return A JsonObject containing the JSON representation of the identifier.
* @throws IllegalArgumentException if the type is not supported
*/
public static JsonObject encodeIdToJson(final Object id) {
final JsonObject json = new JsonObject();
if (id instanceof String) {
json.put("type", "string");
json.put("id", id);
} else if (id instanceof UnsignedLong) {
json.put("type", "ulong");
json.put("id", id.toString());
} else if (id instanceof UUID) {
json.put("type", "uuid");
json.put("id", id.toString());
} else if (id instanceof Binary) {
json.put("type", "binary");
final Binary binary = (Binary) id;
json.put("id", Base64.getEncoder().encodeToString(binary.getArray()));
} else {
throw new IllegalArgumentException("type " + id.getClass().getName() + " is not supported");
}
return json;
}
示例7: decodeIdFromJson
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
/**
* Decodes the given JsonObject to JSON representation.
* Supported types for AMQP 1.0 correlation/messageIds are String, UnsignedLong, UUID and Binary.
* @param json JSON representation of an ID
* @return an ID object of correct type
*/
public static Object decodeIdFromJson(final JsonObject json)
{
final String type = json.getString("type");
final String id = json.getString("id");
switch (type) {
case "string":
return id;
case "ulong":
return UnsignedLong.valueOf(id);
case "uuid":
return UUID.fromString(id);
case "binary":
return new Binary(Base64.getDecoder().decode(id));
default:
throw new IllegalArgumentException("type " + type + " is not supported");
}
}
示例8: toAmqp
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
/**
* Return a raw AMQP message
*
* @return
*/
public Message toAmqp() {
Message message = ProtonHelper.message();
message.setSubject(AMQP_SUBJECT);
Map<Symbol, Object> map = new HashMap<>();
map.put(Symbol.valueOf(AMQP_RETAIN_ANNOTATION), this.isRetain);
map.put(Symbol.valueOf(AMQP_QOS_ANNOTATION), this.qos.value());
MessageAnnotations messageAnnotations = new MessageAnnotations(map);
message.setMessageAnnotations(messageAnnotations);
message.setAddress(this.topic);
Header header = new Header();
header.setDurable(this.qos != MqttQoS.AT_MOST_ONCE);
message.setHeader(header);
// the payload could be null (or empty)
if (this.payload != null)
message.setBody(new Data(new Binary(this.payload.getBytes())));
return message;
}
示例9: setUserId
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Override
public void setUserId(byte[] userId)
{
if(userId == null)
{
if(_properties != null)
{
_properties.setUserId(null);
}
}
else
{
if(_properties == null)
{
_properties = new Properties();
}
byte[] id = new byte[userId.length];
System.arraycopy(userId, 0, id,0, userId.length);
_properties.setUserId(new Binary(id));
}
}
示例10: testPlainHelperEncodesExpectedResponse
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Test
public void testPlainHelperEncodesExpectedResponse() {
TransportImpl transport = new TransportImpl();
SaslImpl sasl = new SaslImpl(transport, 512);
// Use a username + password with a unicode char that encodes
// differently under changing charsets
String username = "username-with-unicode" + "\u1F570";
String password = "password-with-unicode" + "\u1F570";
byte[] usernameBytes = username.getBytes(StandardCharsets.UTF_8);
byte[] passwordBytes = password.getBytes(StandardCharsets.UTF_8);
byte[] expectedResponseBytes = new byte[usernameBytes.length + passwordBytes.length + 2];
System.arraycopy(usernameBytes, 0, expectedResponseBytes, 1, usernameBytes.length);
System.arraycopy(passwordBytes, 0, expectedResponseBytes, 2 + usernameBytes.length, passwordBytes.length);
sasl.plain(username, password);
assertEquals("Unexpected response data", new Binary(expectedResponseBytes), sasl.getChallengeResponse());
}
示例11: handleTransfer
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
private void handleTransfer(TransportImpl transport, int deliveryNumber, String deliveryTag, String messageContent)
{
byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);
Message m = Message.Factory.create();
m.setBody(new AmqpValue(messageContent));
byte[] encoded = new byte[BUFFER_SIZE];
int len = m.encode(encoded, 0, BUFFER_SIZE);
assertTrue("given array was too small", len < BUFFER_SIZE);
Transfer transfer = new Transfer();
transfer.setDeliveryId(UnsignedInteger.valueOf(deliveryNumber));
transfer.setHandle(UnsignedInteger.ZERO);
transfer.setDeliveryTag(new Binary(tag));
transfer.setMessageFormat(UnsignedInteger.valueOf(DeliveryImpl.DEFAULT_MESSAGE_FORMAT));
transport.handleFrame(new TransportFrame(0, transfer, new Binary(encoded, 0, len)));
}
示例12: handleEnd
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Override
public void handleEnd(End end, Binary payload, Integer channel)
{
TransportSession transportSession = _remoteSessions.get(channel);
if(transportSession == null)
{
// TODO - fail due to attach on non-begun session
}
else
{
_remoteSessions.remove(channel);
transportSession.receivedEnd();
transportSession.unsetRemoteChannel();
SessionImpl session = transportSession.getSession();
session.setRemoteState(EndpointState.CLOSED);
ErrorCondition errorCondition = end.getError();
if(errorCondition != null)
{
session.getRemoteCondition().copyFrom(errorCondition);
}
_connectionEndpoint.put(Event.Type.SESSION_REMOTE_CLOSE, session);
}
}
示例13: handleClose
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Override
public void handleClose(Close close, Binary payload, Integer channel)
{
_closeReceived = true;
_remoteIdleTimeout = 0;
setRemoteState(EndpointState.CLOSED);
if(_connectionEndpoint != null)
{
_connectionEndpoint.setRemoteState(EndpointState.CLOSED);
if(close.getError() != null)
{
_connectionEndpoint.getRemoteCondition().copyFrom(close.getError());
}
_connectionEndpoint.put(Event.Type.CONNECTION_REMOTE_CLOSE, _connectionEndpoint);
}
}
示例14: benchmarkData
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
private void benchmarkData() throws IOException {
Data data1 = new Data(new Binary(new byte[] {1, 2, 3}));
Data data2 = new Data(new Binary(new byte[] {4, 5, 6}));
Data data3 = new Data(new Binary(new byte[] {7, 8, 9}));
resultSet.start();
for (int i = 0; i < ITERATIONS; i++) {
byteBuf.clear();
encoder.writeObject(data1);
encoder.writeObject(data2);
encoder.writeObject(data3);
}
resultSet.encodesComplete();
resultSet.start();
for (int i = 0; i < ITERATIONS; i++) {
byteBuf.flip();
decoder.readObject();
decoder.readObject();
decoder.readObject();
}
resultSet.decodesComplete();
time("Data", resultSet);
}
示例15: handleInit
import org.apache.qpid.proton.amqp.Binary; //导入依赖的package包/类
@Override
public void handleInit(SaslInit saslInit, Binary payload, Void context)
{
if(_role == null)
{
server();
}
checkRole(Role.SERVER);
_hostname = saslInit.getHostname();
_chosenMechanism = saslInit.getMechanism();
_initReceived = true;
if(saslInit.getInitialResponse() != null)
{
setPending(saslInit.getInitialResponse().asByteBuffer());
}
if(_saslListener != null) {
_saslListener.onSaslInit(this, _transport);
}
}