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 d4f6e91aa4 QPID-8664: [Broker-J] Guava removal (7/10) (#273)
d4f6e91aa4 is described below

commit d4f6e91aa4870f51fd9e8a62cdbeefff4ae8d61c
Author: Daniil Kirilyuk <daniel.kiril...@gmail.com>
AuthorDate: Tue Apr 22 13:14:09 2025 +0200

    QPID-8664: [Broker-J] Guava removal (7/10) (#273)
    
    This commit replaces guava byte stream utilities with the utility class
---
 .../apache/qpid/server/queue/AbstractQueue.java    |   6 +-
 .../qpid/server/util/LimitedInputStream.java       | 105 +++++++++++++++++++++
 .../qpid/server/bytebuffer/QpidByteBufferTest.java |   3 +-
 .../apache/qpid/server/test/KerberosUtilities.java |   3 +-
 .../MessageConverter_Internal_to_0_10Test.java     |   3 +-
 .../v0_8/MessageConverter_Internal_to_0_8Test.java |   3 +-
 .../protocol/v1_0/store/jdbc/JDBCLinkStore.java    |   3 +-
 .../MessageConverter_1_0_to_v0_10Test.java         |   4 +-
 .../MessageConverter_1_0_to_v0_8Test.java          |   4 +-
 .../org/apache/qpid/tests/http/HttpTestHelper.java |   4 +-
 .../http/compression/CompressedResponsesTest.java  |   4 +-
 .../qpid/systests/admin/SpawnBrokerAdmin.java      |   3 +-
 12 files changed, 118 insertions(+), 27 deletions(-)

diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java 
b/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
index 6637d7b617..a398f6f48d 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
@@ -60,7 +60,6 @@ import java.util.zip.GZIPOutputStream;
 import javax.security.auth.Subject;
 
 import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -142,6 +141,7 @@ import org.apache.qpid.server.util.Action;
 import org.apache.qpid.server.util.ConnectionScopedRuntimeException;
 import org.apache.qpid.server.util.Deletable;
 import org.apache.qpid.server.util.DeleteDeleteTask;
+import org.apache.qpid.server.util.LimitedInputStream;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
 import org.apache.qpid.server.virtualhost.HouseKeepingTask;
 import 
org.apache.qpid.server.virtualhost.MessageDestinationIsAlternateException;
@@ -2803,13 +2803,13 @@ public abstract class AbstractQueue<X extends 
AbstractQueue<X>>
                 if (_limit != UNLIMITED && _decompressBeforeLimiting)
                 {
                     inputStream = new GZIPInputStream(inputStream);
-                    inputStream = ByteStreams.limit(inputStream, _limit);
+                    inputStream = new LimitedInputStream(inputStream, _limit);
                     outputStream = new GZIPOutputStream(outputStream, true);
                 }
 
                 try
                 {
-                    ByteStreams.copy(inputStream, outputStream);
+                    inputStream.transferTo(outputStream);
                 }
                 finally
                 {
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/util/LimitedInputStream.java 
b/broker-core/src/main/java/org/apache/qpid/server/util/LimitedInputStream.java
new file mode 100644
index 0000000000..dd34fc1438
--- /dev/null
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/util/LimitedInputStream.java
@@ -0,0 +1,105 @@
+/*
+ *
+ * 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;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Objects;
+
+public class LimitedInputStream extends FilterInputStream
+{
+
+    private long left;
+    private long mark = -1;
+
+    public LimitedInputStream(InputStream in, long limit) {
+        super(in);
+        Objects.requireNonNull(in);
+        if (limit < 0)
+        {
+            throw new IllegalArgumentException("limit must be non-negative");
+        };
+        left = limit;
+    }
+
+    @Override
+    public int available() throws IOException
+    {
+        return (int) Math.min(in.available(), left);
+    }
+
+    // it's okay to mark even if mark isn't supported, as reset won't work
+    @Override
+    public synchronized void mark(int readLimit) {
+        in.mark(readLimit);
+        mark = left;
+    }
+
+    @Override
+    public int read() throws IOException {
+        if (left == 0) {
+            return -1;
+        }
+
+        int result = in.read();
+        if (result != -1) {
+            --left;
+        }
+        return result;
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        if (left == 0) {
+            return -1;
+        }
+
+        len = (int) Math.min(len, left);
+        int result = in.read(b, off, len);
+        if (result != -1) {
+            left -= result;
+        }
+        return result;
+    }
+
+    @Override
+    public synchronized void reset() throws IOException {
+        if (!in.markSupported()) {
+            throw new IOException("Mark not supported");
+        }
+        if (mark == -1) {
+            throw new IOException("Mark not set");
+        }
+
+        in.reset();
+        left = mark;
+    }
+
+    @Override
+    public long skip(long n) throws IOException {
+        n = Math.min(n, left);
+        long skipped = in.skip(n);
+        left -= skipped;
+        return skipped;
+    }
+}
diff --git 
a/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
 
b/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
index be2f8dded4..a3e4523ff5 100644
--- 
a/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
+++ 
b/broker-core/src/test/java/org/apache/qpid/server/bytebuffer/QpidByteBufferTest.java
@@ -41,7 +41,6 @@ import java.nio.InvalidMarkException;
 import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 
-import com.google.common.io.ByteStreams;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -531,7 +530,7 @@ public class QpidByteBufferTest extends UnitTestBase
         final ByteArrayOutputStream destination = new ByteArrayOutputStream();
         try (final InputStream is = _slicedBuffer.asInputStream())
         {
-            ByteStreams.copy(is, destination);
+            is.transferTo(destination);
         }
 
         final byte[] expected =  new byte[source.length - 2];
diff --git 
a/broker-core/src/test/java/org/apache/qpid/server/test/KerberosUtilities.java 
b/broker-core/src/test/java/org/apache/qpid/server/test/KerberosUtilities.java
index d1c000faaf..42accdff7f 100644
--- 
a/broker-core/src/test/java/org/apache/qpid/server/test/KerberosUtilities.java
+++ 
b/broker-core/src/test/java/org/apache/qpid/server/test/KerberosUtilities.java
@@ -50,7 +50,6 @@ import javax.security.auth.login.Configuration;
 import javax.security.auth.login.LoginContext;
 import javax.security.auth.login.LoginException;
 
-import com.google.common.io.ByteStreams;
 import org.ietf.jgss.GSSContext;
 import org.ietf.jgss.GSSCredential;
 import org.ietf.jgss.GSSException;
@@ -323,7 +322,7 @@ public class KerberosUtilities
         final String config;
         try (final InputStream is = resource.openStream())
         {
-            config = new String(ByteStreams.toByteArray(is), UTF_8);
+            config = new String(is.readAllBytes(), UTF_8);
         }
         catch (IOException e)
         {
diff --git 
a/broker-plugins/amqp-0-10-protocol/src/test/java/org/apache/qpid/server/protocol/v0_10/MessageConverter_Internal_to_0_10Test.java
 
b/broker-plugins/amqp-0-10-protocol/src/test/java/org/apache/qpid/server/protocol/v0_10/MessageConverter_Internal_to_0_10Test.java
index 7b41a309ad..45799ca458 100644
--- 
a/broker-plugins/amqp-0-10-protocol/src/test/java/org/apache/qpid/server/protocol/v0_10/MessageConverter_Internal_to_0_10Test.java
+++ 
b/broker-plugins/amqp-0-10-protocol/src/test/java/org/apache/qpid/server/protocol/v0_10/MessageConverter_Internal_to_0_10Test.java
@@ -34,7 +34,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
 
 import org.junit.jupiter.api.Test;
 
@@ -268,7 +267,7 @@ class MessageConverter_Internal_to_0_10Test extends 
UnitTestBase
         try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
              final InputStream contentInputStream = content.asInputStream())
         {
-            ByteStreams.copy(contentInputStream, bos);
+            contentInputStream.transferTo(bos);
             content.dispose();
             return bos.toByteArray();
         }
diff --git 
a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
 
b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
index 2c832c6ee6..92a1c1bb51 100644
--- 
a/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
+++ 
b/broker-plugins/amqp-0-8-protocol/src/test/java/org/apache/qpid/server/protocol/v0_8/MessageConverter_Internal_to_0_8Test.java
@@ -34,7 +34,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import com.google.common.collect.Lists;
-import com.google.common.io.ByteStreams;
 
 import org.junit.jupiter.api.Test;
 
@@ -268,7 +267,7 @@ class MessageConverter_Internal_to_0_8Test extends 
UnitTestBase
         try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
              final InputStream contentInputStream = content.asInputStream())
         {
-            ByteStreams.copy(contentInputStream, bos);
+            contentInputStream.transferTo(bos);
             content.dispose();
             return bos.toByteArray();
         }
diff --git 
a/broker-plugins/amqp-1-0-jdbc-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStore.java
 
b/broker-plugins/amqp-1-0-jdbc-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStore.java
index fd385090bf..bead8bd214 100644
--- 
a/broker-plugins/amqp-1-0-jdbc-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStore.java
+++ 
b/broker-plugins/amqp-1-0-jdbc-store/src/main/java/org/apache/qpid/server/protocol/v1_0/store/jdbc/JDBCLinkStore.java
@@ -40,7 +40,6 @@ import java.util.Arrays;
 import java.util.Base64;
 import java.util.Collection;
 
-import com.google.common.io.ByteStreams;
 import com.google.common.io.CharStreams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -374,7 +373,7 @@ public class JDBCLinkStore extends AbstractLinkStore
             Blob blob = resultSet.getBlob(index);
             try (InputStream is = blob.getBinaryStream())
             {
-                sourceBytes = ByteStreams.toByteArray(is);
+                sourceBytes = is.readAllBytes();
             }
             catch (IOException e)
             {
diff --git 
a/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10Test.java
 
b/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10Test.java
index 5fe8e433d1..7e073b2552 100644
--- 
a/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10Test.java
+++ 
b/broker-plugins/amqp-msg-conv-0-10-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_10_v1_0/MessageConverter_1_0_to_v0_10Test.java
@@ -38,8 +38,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.google.common.io.ByteStreams;
-
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
@@ -866,7 +864,7 @@ class MessageConverter_1_0_to_v0_10Test extends UnitTestBase
         try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
              final InputStream contentInputStream = content.asInputStream())
         {
-            ByteStreams.copy(contentInputStream, bos);
+            contentInputStream.transferTo(bos);
             content.dispose();
             return bos.toByteArray();
         }
diff --git 
a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
 
b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
index e8cc392f22..df51ea4c60 100644
--- 
a/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
+++ 
b/broker-plugins/amqp-msg-conv-0-8-to-1-0/src/test/java/org/apache/qpid/server/protocol/converter/v0_8_v1_0/MessageConverter_1_0_to_v0_8Test.java
@@ -38,8 +38,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import com.google.common.io.ByteStreams;
-
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 
@@ -831,7 +829,7 @@ class MessageConverter_1_0_to_v0_8Test extends UnitTestBase
         try (final ByteArrayOutputStream bos = new ByteArrayOutputStream();
              final InputStream contentInputStream = content.asInputStream())
         {
-            ByteStreams.copy(contentInputStream, bos);
+            contentInputStream.transferTo(bos);
             content.dispose();
             return bos.toByteArray();
         }
diff --git 
a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
 
b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
index 126cfe202a..fb0cefc525 100644
--- 
a/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
+++ 
b/systests/qpid-systests-http-management/src/main/java/org/apache/qpid/tests/http/HttpTestHelper.java
@@ -58,8 +58,6 @@ import jakarta.servlet.http.HttpServletResponse;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
-import com.google.common.io.ByteStreams;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -206,7 +204,7 @@ public class HttpTestHelper
     {
         try (InputStream is = connection.getInputStream())
         {
-            final byte[] bytes = ByteStreams.toByteArray(is);
+            final byte[] bytes = is.readAllBytes();
             if (LOGGER.isTraceEnabled())
             {
                 LOGGER.trace("RESPONSE:" + new String(bytes, UTF_8));
diff --git 
a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
 
b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
index ba5f3232bf..c091f376ee 100644
--- 
a/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
+++ 
b/systests/qpid-systests-http-management/src/test/java/org/apache/qpid/tests/http/compression/CompressedResponsesTest.java
@@ -36,8 +36,6 @@ import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
-import com.google.common.io.ByteStreams;
-
 import org.junit.jupiter.api.Test;
 
 import org.apache.qpid.tests.http.HttpTestBase;
@@ -104,7 +102,7 @@ public class CompressedResponsesTest extends HttpTestBase
             byte[] bytes;
             try(ByteArrayOutputStream contentBuffer = new 
ByteArrayOutputStream())
             {
-                ByteStreams.copy(conn.getInputStream(), contentBuffer);
+                conn.getInputStream().transferTo(contentBuffer);
                 bytes = contentBuffer.toByteArray();
             }
             try (InputStream jsonStream = expectCompression
diff --git 
a/systests/qpid-systests-spawn-admin/src/main/java/org/apache/qpid/systests/admin/SpawnBrokerAdmin.java
 
b/systests/qpid-systests-spawn-admin/src/main/java/org/apache/qpid/systests/admin/SpawnBrokerAdmin.java
index 96b7cf006b..5bf44a3b25 100644
--- 
a/systests/qpid-systests-spawn-admin/src/main/java/org/apache/qpid/systests/admin/SpawnBrokerAdmin.java
+++ 
b/systests/qpid-systests-spawn-admin/src/main/java/org/apache/qpid/systests/admin/SpawnBrokerAdmin.java
@@ -63,7 +63,6 @@ import javax.naming.NamingException;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.io.ByteStreams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -726,7 +725,7 @@ public class SpawnBrokerAdmin implements BrokerAdmin, 
Closeable
             try (InputStream is = 
getClass().getClassLoader().getResourceAsStream(config);
                  OutputStream os = new 
FileOutputStream(testInitialConfiguration))
             {
-                ByteStreams.copy(is, os);
+                is.transferTo(os);
             }
         }
         else


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to