This is an automated email from the ASF dual-hosted git repository.
vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git
The following commit(s) were added to refs/heads/main by this push:
new ca95b2153f QPID-8664: [Broker-J] Guava removal (2/10)
ca95b2153f is described below
commit ca95b2153f5dbac7ce3e99f18cada07521038156
Author: dakirily <[email protected]>
AuthorDate: Thu Mar 27 09:05:23 2025 +0100
QPID-8664: [Broker-J] Guava removal (2/10)
This commit replaces guava primitive types convertors with the utility class
---
.../server/bytebuffer/MultiQpidByteBuffer.java | 37 ++++-----
.../server/queue/MessageContentJsonConverter.java | 9 ++-
.../apache/qpid/server/util/PrimitivesUtils.java | 92 ++++++++++++++++++++++
3 files changed, 115 insertions(+), 23 deletions(-)
diff --git
a/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/MultiQpidByteBuffer.java
b/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/MultiQpidByteBuffer.java
index 1209abfbc0..daa9df116d 100644
---
a/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/MultiQpidByteBuffer.java
+++
b/broker-core/src/main/java/org/apache/qpid/server/bytebuffer/MultiQpidByteBuffer.java
@@ -30,10 +30,7 @@ import java.nio.channels.ScatteringByteChannel;
import java.util.ArrayList;
import java.util.List;
-import com.google.common.primitives.Chars;
-import com.google.common.primitives.Ints;
-import com.google.common.primitives.Longs;
-import com.google.common.primitives.Shorts;
+import org.apache.qpid.server.util.PrimitivesUtils;
class MultiQpidByteBuffer implements QpidByteBuffer
{
@@ -71,28 +68,28 @@ class MultiQpidByteBuffer implements QpidByteBuffer
@Override
public QpidByteBuffer putShort(final int index, final short value)
{
- byte[] valueArray = Shorts.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(index, valueArray);
}
@Override
public QpidByteBuffer putChar(final int index, final char value)
{
- byte[] valueArray = Chars.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(index, valueArray);
}
@Override
public QpidByteBuffer putInt(final int index, final int value)
{
- byte[] valueArray = Ints.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(index, valueArray);
}
@Override
public QpidByteBuffer putLong(final int index, final long value)
{
- byte[] valueArray = Longs.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(index, valueArray);
}
@@ -172,7 +169,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
@Override
public final QpidByteBuffer putShort(final short value)
{
- byte[] valueArray = Shorts.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(valueArray);
}
@@ -186,14 +183,14 @@ class MultiQpidByteBuffer implements QpidByteBuffer
@Override
public final QpidByteBuffer putChar(final char value)
{
- byte[] valueArray = Chars.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(valueArray);
}
@Override
public final QpidByteBuffer putInt(final int value)
{
- byte[] valueArray = Ints.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(valueArray);
}
@@ -207,7 +204,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
@Override
public final QpidByteBuffer putLong(final long value)
{
- byte[] valueArray = Longs.toByteArray(value);
+ byte[] valueArray = PrimitivesUtils.toByteArray(value);
return put(valueArray);
}
@@ -390,7 +387,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
public short getShort(final int index)
{
final byte[] byteArray = getByteArray(index, 2);
- return Shorts.fromByteArray(byteArray);
+ return PrimitivesUtils.shortFromByteArray(byteArray);
}
@Override
@@ -403,21 +400,21 @@ class MultiQpidByteBuffer implements QpidByteBuffer
public char getChar(final int index)
{
final byte[] byteArray = getByteArray(index, 2);
- return Chars.fromByteArray(byteArray);
+ return PrimitivesUtils.charFromByteArray(byteArray);
}
@Override
public int getInt(final int index)
{
final byte[] byteArray = getByteArray(index, 4);
- return Ints.fromByteArray(byteArray);
+ return PrimitivesUtils.intFromByteArray(byteArray);
}
@Override
public long getLong(final int index)
{
final byte[] byteArray = getByteArray(index, 8);
- return Longs.fromByteArray(byteArray);
+ return PrimitivesUtils.longFromByteArray(byteArray);
}
@Override
@@ -500,7 +497,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
{
byte[] value = new byte[2];
get(value, 0, value.length);
- return Shorts.fromByteArray(value);
+ return PrimitivesUtils.shortFromByteArray(value);
}
@Override
@@ -514,7 +511,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
{
byte[] value = new byte[2];
get(value, 0, value.length);
- return Chars.fromByteArray(value);
+ return PrimitivesUtils.charFromByteArray(value);
}
@Override
@@ -522,7 +519,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
{
byte[] value = new byte[4];
get(value, 0, value.length);
- return Ints.fromByteArray(value);
+ return PrimitivesUtils.intFromByteArray(value);
}
@Override
@@ -536,7 +533,7 @@ class MultiQpidByteBuffer implements QpidByteBuffer
{
byte[] value = new byte[8];
get(value, 0, value.length);
- return Longs.fromByteArray(value);
+ return PrimitivesUtils.longFromByteArray(value);
}
@Override
diff --git
a/broker-core/src/main/java/org/apache/qpid/server/queue/MessageContentJsonConverter.java
b/broker-core/src/main/java/org/apache/qpid/server/queue/MessageContentJsonConverter.java
index cb5aa92be4..a49d44b2c5 100644
---
a/broker-core/src/main/java/org/apache/qpid/server/queue/MessageContentJsonConverter.java
+++
b/broker-core/src/main/java/org/apache/qpid/server/queue/MessageContentJsonConverter.java
@@ -36,8 +36,6 @@ import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.databind.ser.std.StdArraySerializers;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-import com.google.common.primitives.Bytes;
-import com.google.common.primitives.Ints;
class MessageContentJsonConverter
{
@@ -203,7 +201,12 @@ class MessageContentJsonConverter
public void serialize(final byte[] value, final JsonGenerator jgen,
final SerializerProvider provider)
throws IOException
{
- _underlying.serialize(Ints.toArray(Bytes.asList(value)), jgen,
provider);
+ final int[] intArray = new int[value.length];
+ for (int i = 0; i < value.length; i++)
+ {
+ intArray[i] = value[i];
+ }
+ _underlying.serialize(intArray, jgen, provider);
}
}
}
diff --git
a/broker-core/src/main/java/org/apache/qpid/server/util/PrimitivesUtils.java
b/broker-core/src/main/java/org/apache/qpid/server/util/PrimitivesUtils.java
new file mode 100644
index 0000000000..119c72257e
--- /dev/null
+++ b/broker-core/src/main/java/org/apache/qpid/server/util/PrimitivesUtils.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.server.util;
+
+public final class PrimitivesUtils
+{
+ public static final int BYTES = Short.SIZE / Byte.SIZE;
+ private static final String ARRAY_TOO_SMALL = "array too small: %s < %s";
+
+ private PrimitivesUtils() { }
+
+ private static void checkArgument(boolean expression, int p1)
+ {
+ if (!expression)
+ {
+ throw new
IllegalArgumentException(String.format(PrimitivesUtils.ARRAY_TOO_SMALL, p1,
PrimitivesUtils.BYTES));
+ }
+ }
+
+ public static byte[] toByteArray(short value)
+ {
+ return new byte[] {(byte) (value >> 8), (byte) value};
+ }
+
+ public static byte[] toByteArray(char value)
+ {
+ return new byte[] {(byte) (value >> 8), (byte) value};
+ }
+
+ public static byte[] toByteArray(int value)
+ {
+ return new byte[]
+ {
+ (byte) (value >> 24), (byte) (value >> 16), (byte) (value >> 8),
(byte) value
+ };
+ }
+
+ public static byte[] toByteArray(long value)
+ {
+ byte[] result = new byte[8];
+ for (int i = 7; i >= 0; i--)
+ {
+ result[i] = (byte) (value & 0xffL);
+ value >>= 8;
+ }
+ return result;
+ }
+
+ public static short shortFromByteArray(byte[] bytes)
+ {
+ checkArgument(bytes.length >= BYTES, bytes.length);
+ return (short) ((bytes[0] << 8) | (bytes[1]) & 0xFF);
+ }
+
+ public static char charFromByteArray(byte[] bytes)
+ {
+ checkArgument(bytes.length >= BYTES, bytes.length);
+ return (char) ((bytes[0] << 8) | (bytes[1] & 0xFF));
+ }
+
+ public static int intFromByteArray(byte[] bytes)
+ {
+ checkArgument(bytes.length >= BYTES, bytes.length);
+ return bytes[0] << 24 | (bytes[1] & 0xFF) << 16 | (bytes[2] & 0xFF) <<
8 | (bytes[3] & 0xFF);
+ }
+
+ public static long longFromByteArray(byte[] bytes)
+ {
+ checkArgument(bytes.length >= BYTES, bytes.length);
+ return (bytes[0] & 0xFFL) << 56 | (bytes[1] & 0xFFL) << 48 | (bytes[2]
& 0xFFL) << 40 |
+ (bytes[3] & 0xFFL) << 32 | (bytes[4] & 0xFFL) << 24 | (bytes[5]
& 0xFFL) << 16 |
+ (bytes[6] & 0xFFL) << 8 | (bytes[7] & 0xFFL);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]