From 248a9968a4f2084c6c00c87585511ac9e67dc69c Mon Sep 17 00:00:00 2001 From: Josip Grgurica Date: Fri, 4 Mar 2022 11:46:19 +0100 Subject: [PATCH] use only relative bulk get method --- .../src/main/scala/sttp/client3/internal/package.scala | 10 +++------- .../scala/sttp/client3/httpclient/WebSocketImpl.scala | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/core/src/main/scala/sttp/client3/internal/package.scala b/core/src/main/scala/sttp/client3/internal/package.scala index 352c5b301f..b1c601a711 100644 --- a/core/src/main/scala/sttp/client3/internal/package.scala +++ b/core/src/main/scala/sttp/client3/internal/package.scala @@ -80,13 +80,9 @@ package object internal { implicit class RichByteBuffer(byteBuffer: ByteBuffer) { def safeRead(): Array[Byte] = { - if (byteBuffer.hasArray) { - byteBuffer.array() - } else { - val array = new Array[Byte](byteBuffer.remaining()) - byteBuffer.get(array) - array - } + val array = new Array[Byte](byteBuffer.remaining()) + byteBuffer.get(array) + array } } } diff --git a/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala b/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala index 9791dd5a69..bf38b736cd 100644 --- a/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala +++ b/httpclient-backend/src/main/scala/sttp/client3/httpclient/WebSocketImpl.scala @@ -105,12 +105,12 @@ private[httpclient] class AddToQueueListener[F[_]]( } override def onPing(webSocket: JWebSocket, message: ByteBuffer): CompletionStage[_] = { - onFrame(WebSocketFrame.Ping(message.array())) + onFrame(WebSocketFrame.Ping(message.safeRead())) null } override def onPong(webSocket: JWebSocket, message: ByteBuffer): CompletionStage[_] = { - onFrame(WebSocketFrame.Pong(message.array())) + onFrame(WebSocketFrame.Pong(message.safeRead())) null }