Skip to content

Commit 3bd2bac

Browse files
Removed all usages of constructor
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
1 parent a783a27 commit 3bd2bac

File tree

10 files changed

+26
-27
lines changed

10 files changed

+26
-27
lines changed

amqp/src/main/java/io/cloudevents/amqp/impl/ProtonAmqpBinaryMessageReader.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,26 @@
1717

1818
package io.cloudevents.amqp.impl;
1919

20-
import java.util.Objects;
21-
import java.util.function.BiConsumer;
22-
23-
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
24-
2520
import io.cloudevents.SpecVersion;
2621
import io.cloudevents.core.data.BytesCloudEventData;
2722
import io.cloudevents.core.message.impl.BaseGenericBinaryMessageReaderImpl;
23+
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
24+
25+
import java.util.Objects;
26+
import java.util.function.BiConsumer;
2827

2928
/**
3029
* An AMQP 1.0 message reader that can be read as a <em>CloudEvent</em>.
3130
* <p>
32-
*
31+
*
3332
* This reader reads sections of an AMQP message to construct a CloudEvent representation by doing the following:
3433
* <ul>
3534
* <li> If the content-type property is set for an AMQP message, the value of the property
3635
* is represented as a cloud event datacontenttype attribute.
3736
* <li> If the (mandatory) application-properties of the AMQP message contains attributes and/or extentions,
3837
* this reader will represent each property/extension as a cloud event attribute.
3938
* </ul>
40-
*
39+
*
4140
*/
4241
public final class ProtonAmqpBinaryMessageReader extends BaseGenericBinaryMessageReaderImpl<String, Object> {
4342

@@ -53,12 +52,12 @@ public final class ProtonAmqpBinaryMessageReader extends BaseGenericBinaryMessag
5352
* The applicationProperties MUST not be {@code null}.
5453
* @param contentType The content-type property of the AMQP message or {@code null} if the message content type is unknown.
5554
* @param payload The message payload or {@code null} if the message does not contain any payload.
56-
*
55+
*
5756
* @throws NullPointerException if the applicationPropereties is {@code null}.
5857
*/
59-
public ProtonAmqpBinaryMessageReader(final SpecVersion version, final ApplicationProperties applicationProperties,
60-
final String contentType, final byte[] payload) {
61-
super(version, payload != null && payload.length > 0 ? new BytesCloudEventData(payload) : null);
58+
public ProtonAmqpBinaryMessageReader(final SpecVersion version, final ApplicationProperties applicationProperties,
59+
final String contentType, final byte[] payload) {
60+
super(version, payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null);
6261
this.contentType = contentType;
6362
this.applicationProperties = Objects.requireNonNull(applicationProperties);
6463
}
@@ -70,7 +69,7 @@ protected boolean isContentTypeHeader(final String key) {
7069

7170
/**
7271
* Tests whether the given attribute key is prefixed with <em>cloudEvents:</em>
73-
*
72+
*
7473
* @param key The key to test for the presence of the prefix.
7574
* @return True if the specified key starts with the prefix or
7675
* false otherwise.
@@ -83,9 +82,9 @@ protected boolean isCloudEventsHeader(final String key) {
8382

8483
/**
8584
* Gets the cloud event attribute key without the preceding prefix.
86-
*
85+
*
8786
* @param key The key containing the AMQP specific prefix.
88-
*
87+
*
8988
* @return The key without the prefix.
9089
*/
9190
@Override
@@ -119,7 +118,7 @@ protected void forEachHeader(final BiConsumer<String, Object> fn) {
119118
* Gets the cloud event representation of the value.
120119
* <p>
121120
* This method simply returns the string representation of the type of value passed as argument.
122-
*
121+
*
123122
* @param value The value of a CloudEvent attribute or extension.
124123
*
125124
* @return The string representation of the specified value.

core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public String toString() {
4646
* @param value byte array to wrap
4747
* @return byte array wrapped in a {@link BytesCloudEventData}, which implements {@link CloudEventData}.
4848
*/
49-
public BytesCloudEventData wrap(byte[] value) {
49+
public static BytesCloudEventData wrap(byte[] value) {
5050
return new BytesCloudEventData(value);
5151
}
5252
}

core/src/main/java/io/cloudevents/core/impl/BaseCloudEventBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public BaseCloudEventBuilder(CloudEvent event) {
6161
// to encode data
6262

6363
public SELF withData(byte[] data) {
64-
this.data = new BytesCloudEventData(data);
64+
this.data = BytesCloudEventData.wrap(data);
6565
return this.self;
6666
}
6767

core/src/test/java/io/cloudevents/core/mock/CSVFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public CloudEvent deserialize(byte[] bytes, CloudEventDataMapper mapper) {
9191
}
9292
if (data != null) {
9393
if (mapper != null) {
94-
builder.withData(mapper.map(new BytesCloudEventData(data)));
94+
builder.withData(mapper.map(BytesCloudEventData.wrap(data)));
9595
} else {
9696
builder.withData(data);
9797
}

core/src/test/java/io/cloudevents/core/mock/MockBinaryMessageWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public MockBinaryMessageWriter(SpecVersion version, Map<String, Object> attribut
4646
}
4747

4848
public MockBinaryMessageWriter(SpecVersion version, Map<String, Object> attributes, byte[] data, Map<String, Object> extensions) {
49-
this(version, attributes, new BytesCloudEventData(data), extensions);
49+
this(version, attributes, BytesCloudEventData.wrap(data), extensions);
5050
}
5151

5252
public MockBinaryMessageWriter() {

formats/json-jackson/src/main/java/io/cloudevents/jackson/CloudEventDeserializer.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> w
9090
boolean isBase64 = "base64".equals(getOptionalStringNode(this.node, this.p, "datacontentencoding"));
9191
if (node.has("data")) {
9292
if (isBase64) {
93-
data = new BytesCloudEventData(node.remove("data").binaryValue());
93+
data = BytesCloudEventData.wrap(node.remove("data").binaryValue());
9494
} else {
9595
if (JsonFormat.dataIsJsonContentType(contentType)) {
9696
// This solution is quite bad, but i see no alternatives now.
@@ -99,7 +99,7 @@ public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> w
9999
} else {
100100
JsonNode dataNode = node.remove("data");
101101
assertNodeType(dataNode, JsonNodeType.STRING, "data", "Because content type is not a json, only a string is accepted as data");
102-
data = new BytesCloudEventData(dataNode.asText().getBytes());
102+
data = BytesCloudEventData.wrap(dataNode.asText().getBytes());
103103
}
104104
}
105105
}
@@ -108,7 +108,7 @@ public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> w
108108
throw MismatchedInputException.from(p, CloudEvent.class, "CloudEvent cannot have both 'data' and 'data_base64' fields");
109109
}
110110
if (node.has("data_base64")) {
111-
data = new BytesCloudEventData(node.remove("data_base64").binaryValue());
111+
data = BytesCloudEventData.wrap(node.remove("data_base64").binaryValue());
112112
} else if (node.has("data")) {
113113
if (JsonFormat.dataIsJsonContentType(contentType)) {
114114
// This solution is quite bad, but i see no alternatives now.
@@ -117,7 +117,7 @@ public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> w
117117
} else {
118118
JsonNode dataNode = node.remove("data");
119119
assertNodeType(dataNode, JsonNodeType.STRING, "data", "Because content type is not a json, only a string is accepted as data");
120-
data = new BytesCloudEventData(dataNode.asText().getBytes());
120+
data = BytesCloudEventData.wrap(dataNode.asText().getBytes());
121121
}
122122
}
123123
}

http/basic/src/main/java/io/cloudevents/http/impl/HttpMessageReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public HttpMessageReader(SpecVersion version, Consumer<BiConsumer<String, String
3737
}
3838

3939
public HttpMessageReader(SpecVersion version, Consumer<BiConsumer<String, String>> forEachHeader, byte[] body) {
40-
this(version, forEachHeader, body != null && body.length > 0 ? new BytesCloudEventData(body) : null);
40+
this(version, forEachHeader, body != null && body.length > 0 ? BytesCloudEventData.wrap(body) : null);
4141
}
4242

4343
@Override

http/restful-ws/src/main/java/io/cloudevents/http/restful/ws/impl/BinaryRestfulWSMessageReaderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class BinaryRestfulWSMessageReaderImpl extends BaseGenericBinaryMes
3333
private final MultivaluedMap<String, String> headers;
3434

3535
public BinaryRestfulWSMessageReaderImpl(SpecVersion version, MultivaluedMap<String, String> headers, byte[] body) {
36-
super(version, body != null && body.length > 0 ? new BytesCloudEventData(body) : null);
36+
super(version, body != null && body.length > 0 ? BytesCloudEventData.wrap(body) : null);
3737

3838
Objects.requireNonNull(headers);
3939
this.headers = headers;

http/vertx/src/main/java/io/cloudevents/http/vertx/impl/BinaryVertxMessageReaderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class BinaryVertxMessageReaderImpl extends BaseGenericBinaryMessageReader
3232
private final MultiMap headers;
3333

3434
public BinaryVertxMessageReaderImpl(SpecVersion version, MultiMap headers, Buffer body) {
35-
super(version, body != null && body.length() > 0 ? new BytesCloudEventData(body.getBytes()) : null);
35+
super(version, body != null && body.length() > 0 ? BytesCloudEventData.wrap(body.getBytes()) : null);
3636

3737
Objects.requireNonNull(headers);
3838
this.headers = headers;

kafka/src/main/java/io/cloudevents/kafka/impl/KafkaBinaryMessageReaderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class KafkaBinaryMessageReaderImpl extends BaseGenericBinaryMessageReader
3131
private final Headers headers;
3232

3333
public KafkaBinaryMessageReaderImpl(SpecVersion version, Headers headers, byte[] payload) {
34-
super(version, payload != null && payload.length > 0 ? new BytesCloudEventData(payload) : null);
34+
super(version, payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null);
3535

3636
Objects.requireNonNull(headers);
3737
this.headers = headers;

0 commit comments

Comments
 (0)