diff --git a/actor-tests/src/test/scala/org/apache/pekko/serialization/SerializeSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/serialization/SerializeSpec.scala index fc7fecc204..3a5cc4adef 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/serialization/SerializeSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/serialization/SerializeSpec.scala @@ -14,16 +14,16 @@ package org.apache.pekko.serialization import java.io._ -import java.nio.ByteBuffer -import java.nio.ByteOrder +import java.nio.{ ByteBuffer, ByteOrder } +import java.nio.charset.StandardCharsets +import scala.annotation.nowarn import scala.concurrent.Await import scala.concurrent.duration._ +import language.postfixOps import SerializationTests._ -import scala.annotation.nowarn import com.typesafe.config._ -import language.postfixOps import test.org.apache.pekko.serialization.NoVerification import org.apache.pekko @@ -247,7 +247,7 @@ class SerializeSpec extends PekkoSpec(SerializationTests.serializeConf) { val byteSerializer = ser.serializerFor(classOf[Array[Byte]]) (byteSerializer.getClass should be).theSameInstanceAs(classOf[ByteArraySerializer]) - for (a <- Seq("foo".getBytes("UTF-8"), null: Array[Byte], Array[Byte]())) + for (a <- Seq("foo".getBytes(StandardCharsets.UTF_8), null: Array[Byte], Array[Byte]())) (byteSerializer.fromBinary(byteSerializer.toBinary(a)) should be).theSameInstanceAs(a) intercept[IllegalArgumentException] { @@ -261,13 +261,13 @@ class SerializeSpec extends PekkoSpec(SerializationTests.serializeConf) { val byteBuffer = ByteBuffer.allocate(128).order(ByteOrder.LITTLE_ENDIAN) val str = "abcdef" - val payload = str.getBytes("UTF-8") + val payload = str.getBytes(StandardCharsets.UTF_8) byteSerializer.toBinary(payload, byteBuffer) byteBuffer.position() should ===(payload.length) byteBuffer.flip() val deserialized = byteSerializer.fromBinary(byteBuffer, "").asInstanceOf[Array[Byte]] byteBuffer.remaining() should ===(0) - new String(deserialized, "UTF-8") should ===(str) + new String(deserialized, StandardCharsets.UTF_8) should ===(str) intercept[IllegalArgumentException] { byteSerializer.toBinary("pigdog", byteBuffer) diff --git a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala index 46bd72c3cd..d723350759 100644 --- a/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala +++ b/actor-tests/src/test/scala/org/apache/pekko/util/ByteStringSpec.scala @@ -18,10 +18,11 @@ import java.lang.Double.doubleToRawLongBits import java.lang.Float.floatToRawIntBits import java.nio.{ ByteBuffer, ByteOrder } import java.nio.ByteOrder.{ BIG_ENDIAN, LITTLE_ENDIAN } - -import scala.collection.mutable.Builder +import java.nio.charset.StandardCharsets import scala.annotation.nowarn +import scala.collection.mutable.Builder + import org.apache.commons.codec.binary.Hex.encodeHex import org.scalacheck.{ Arbitrary, Gen } import org.scalacheck.Arbitrary.arbitrary @@ -796,7 +797,7 @@ class ByteStringSpec extends AnyWordSpec with Matchers with Checkers { "behave as expected" when { "created from and decoding to String" in { check { (s: String) => - ByteString(s, "UTF-8").decodeString("UTF-8") == s + ByteString(s, StandardCharsets.UTF_8).decodeString(StandardCharsets.UTF_8) == s } } diff --git a/actor/src/main/scala/org/apache/pekko/serialization/PrimitiveSerializers.scala b/actor/src/main/scala/org/apache/pekko/serialization/PrimitiveSerializers.scala index 0f2f25ccbd..e256893779 100644 --- a/actor/src/main/scala/org/apache/pekko/serialization/PrimitiveSerializers.scala +++ b/actor/src/main/scala/org/apache/pekko/serialization/PrimitiveSerializers.scala @@ -14,6 +14,7 @@ package org.apache.pekko.serialization import java.nio.{ BufferOverflowException, ByteBuffer } +import java.nio.charset.StandardCharsets import org.apache.pekko import pekko.actor.ExtendedActorSystem @@ -115,12 +116,13 @@ import pekko.util.ByteString override def fromBinary(buf: ByteBuffer, manifest: String): AnyRef = { val bytes = new Array[Byte](buf.remaining()) buf.get(bytes) - new String(bytes, "UTF-8") + new String(bytes, StandardCharsets.UTF_8) } - override def toBinary(o: AnyRef): Array[Byte] = o.asInstanceOf[String].getBytes("UTF-8") + override def toBinary(o: AnyRef): Array[Byte] = o.asInstanceOf[String].getBytes(StandardCharsets.UTF_8) - override def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = new String(bytes, "UTF-8") + override def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = + new String(bytes, StandardCharsets.UTF_8) } diff --git a/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_decode_Benchmark.scala b/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_decode_Benchmark.scala index 7569836a66..90534ede0f 100644 --- a/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_decode_Benchmark.scala +++ b/bench-jmh/src/main/scala/org/apache/pekko/util/ByteString_decode_Benchmark.scala @@ -13,7 +13,7 @@ package org.apache.pekko.util -import java.nio.charset.Charset +import java.nio.charset.StandardCharsets import java.util.concurrent.TimeUnit import org.openjdk.jmh.annotations._ @@ -31,8 +31,8 @@ class ByteString_decode_Benchmark { val bss_large = ByteStrings(Vector.fill(4)(bs_large.asInstanceOf[ByteString1C].toByteString1), 4 * bs_large.length) val bc_large = bss_large.compact // compacted - val utf8String = "utf-8" - val utf8 = Charset.forName(utf8String) + val utf8 = StandardCharsets.UTF_8 + val utf8String = utf8.name /* Using Charset helps a bit, but nothing impressive: diff --git a/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala b/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala index e519af08c3..06e2efcd3b 100644 --- a/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala +++ b/cluster/src/main/scala/org/apache/pekko/cluster/VectorClock.scala @@ -13,6 +13,7 @@ package org.apache.pekko.cluster +import java.nio.charset.StandardCharsets import java.security.MessageDigest import scala.annotation.tailrec @@ -38,7 +39,7 @@ private[cluster] object VectorClock { private def hash(name: String): String = { val digester = MessageDigest.getInstance("MD5") - digester.update(name.getBytes("UTF-8")) + digester.update(name.getBytes(StandardCharsets.UTF_8)) digester.digest.map { h => "%02x".format(0xFF & h) }.mkString diff --git a/cluster/src/multi-jvm/scala/org/apache/pekko/cluster/LargeMessageClusterSpec.scala b/cluster/src/multi-jvm/scala/org/apache/pekko/cluster/LargeMessageClusterSpec.scala index adb52f42c4..812d5f1bf1 100644 --- a/cluster/src/multi-jvm/scala/org/apache/pekko/cluster/LargeMessageClusterSpec.scala +++ b/cluster/src/multi-jvm/scala/org/apache/pekko/cluster/LargeMessageClusterSpec.scala @@ -13,7 +13,11 @@ package org.apache.pekko.cluster +import java.io.NotSerializableException +import java.nio.charset.StandardCharsets + import scala.concurrent.duration._ + import com.typesafe.config.ConfigFactory import org.apache.pekko import pekko.actor.ActorIdentity @@ -29,8 +33,6 @@ import pekko.serialization.SerializerWithStringManifest import pekko.testkit._ import pekko.util.unused -import java.io.NotSerializableException - object LargeMessageClusterMultiJvmSpec extends MultiNodeConfig { val first = role("first") val second = role("second") @@ -140,7 +142,7 @@ abstract class LargeMessageClusterSpec val largeEchoProbe = TestProbe(name = "largeEchoProbe") val largeMsgSize = 2 * 1000 * 1000 - val largeMsg = ("0" * largeMsgSize).getBytes("utf-8") + val largeMsg = ("0" * largeMsgSize).getBytes(StandardCharsets.UTF_8) val largeMsgBurst = 3 val repeat = 15 for (n <- 1 to repeat) { @@ -150,7 +152,7 @@ abstract class LargeMessageClusterSpec } val ordinaryProbe = TestProbe() - echo3.tell(("0" * 1000).getBytes("utf-8"), ordinaryProbe.ref) + echo3.tell(("0" * 1000).getBytes(StandardCharsets.UTF_8), ordinaryProbe.ref) ordinaryProbe.expectMsgType[Array[Byte]] val ordinaryDurationMs = (System.nanoTime() - startTime) / 1000 / 1000 @@ -177,7 +179,7 @@ abstract class LargeMessageClusterSpec val largeEcho3 = identify(third, "largeEcho") val largeMsgSize = 1 * 1000 * 1000 - val payload = ("0" * largeMsgSize).getBytes("utf-8") + val payload = ("0" * largeMsgSize).getBytes(StandardCharsets.UTF_8) val largeMsg = if (aeronUdpEnabled) payload else Slow(payload) (1 to 3).foreach { _ => // this will ping-pong between second and third diff --git a/persistence/src/test/scala/org/apache/pekko/persistence/SnapshotFailureRobustnessSpec.scala b/persistence/src/test/scala/org/apache/pekko/persistence/SnapshotFailureRobustnessSpec.scala index 4b2e9a4756..0369188db9 100644 --- a/persistence/src/test/scala/org/apache/pekko/persistence/SnapshotFailureRobustnessSpec.scala +++ b/persistence/src/test/scala/org/apache/pekko/persistence/SnapshotFailureRobustnessSpec.scala @@ -14,6 +14,7 @@ package org.apache.pekko.persistence import java.io.IOException +import java.nio.charset.StandardCharsets import java.util.UUID import scala.concurrent.Future @@ -87,7 +88,7 @@ object SnapshotFailureRobustnessSpec { class FailingLocalSnapshotStore(config: Config) extends LocalSnapshotStore(config) { override def save(metadata: SnapshotMetadata, snapshot: Any): Unit = { if (metadata.sequenceNr == 2 || snapshot.toString.startsWith("boom")) { - val bytes = "b0rkb0rk".getBytes("UTF-8") // length >= 8 to prevent EOF exception + val bytes = "b0rkb0rk".getBytes(StandardCharsets.UTF_8) // length >= 8 to prevent EOF exception val tmpFile = withOutputStream(metadata)(_.write(bytes)) tmpFile.renameTo(snapshotFileForWrite(metadata)) } else super.save(metadata, snapshot) diff --git a/pki/src/test/scala/org/apache/pekko/pki/pem/DERPrivateKeyLoaderSpec.scala b/pki/src/test/scala/org/apache/pekko/pki/pem/DERPrivateKeyLoaderSpec.scala index dfceb76051..74ca56c618 100644 --- a/pki/src/test/scala/org/apache/pekko/pki/pem/DERPrivateKeyLoaderSpec.scala +++ b/pki/src/test/scala/org/apache/pekko/pki/pem/DERPrivateKeyLoaderSpec.scala @@ -14,7 +14,7 @@ package org.apache.pekko.pki.pem import java.io.File -import java.nio.charset.Charset +import java.nio.charset.StandardCharsets import java.nio.file.Files import java.security.PrivateKey @@ -55,7 +55,7 @@ class DERPrivateKeyLoaderSpec extends AnyWordSpec with Matchers with EitherValue resourceUrl.getProtocol should ===("file") val path = new File(resourceUrl.toURI).toPath val bytes = Files.readAllBytes(path) - val str = new String(bytes, Charset.forName("UTF-8")) + val str = new String(bytes, StandardCharsets.UTF_8) val derData = PEMDecoder.decode(str) derData } diff --git a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/BenchmarkFileReporter.scala b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/BenchmarkFileReporter.scala index d2eb6b2af0..b3cb882eac 100644 --- a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/BenchmarkFileReporter.scala +++ b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/BenchmarkFileReporter.scala @@ -14,6 +14,7 @@ package org.apache.pekko.remote.artery import java.io.File +import java.nio.charset.StandardCharsets import java.nio.file.Files import java.time.Instant import java.time.LocalDateTime @@ -84,7 +85,7 @@ object BenchmarkFileReporter { def reportResults(result: String): Unit = synchronized { println(result) - fos.write(result.getBytes("utf8")) + fos.write(result.getBytes(StandardCharsets.UTF_8)) fos.write('\n') fos.flush() } diff --git a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/LatencySpec.scala b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/LatencySpec.scala index e17bd003f1..ba0ac9c2e0 100644 --- a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/LatencySpec.scala +++ b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/LatencySpec.scala @@ -13,6 +13,7 @@ package org.apache.pekko.remote.artery +import java.nio.charset.StandardCharsets import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicLongArray import java.util.concurrent.locks.LockSupport @@ -261,7 +262,7 @@ abstract class LatencySpec extends RemotingMultiNodeSpec(LatencySpec) { import testSettings._ runOn(first) { - val payload = ("0" * payloadSize).getBytes("utf-8") + val payload = ("0" * payloadSize).getBytes(StandardCharsets.UTF_8) // by default run for 2 seconds, but can be adjusted with the totalMessagesFactor val totalMessages = (2 * messageRate * totalMessagesFactor).toInt val sendTimes = new AtomicLongArray(totalMessages) diff --git a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/MaxThroughputSpec.scala b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/MaxThroughputSpec.scala index 19ecf1cc77..0ee81052da 100644 --- a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/MaxThroughputSpec.scala +++ b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/MaxThroughputSpec.scala @@ -13,10 +13,14 @@ package org.apache.pekko.remote.artery +import java.io.NotSerializableException import java.nio.ByteBuffer +import java.nio.charset.StandardCharsets import java.util.concurrent.Executors import java.util.concurrent.TimeUnit.NANOSECONDS + import scala.concurrent.duration._ + import com.typesafe.config.ConfigFactory import org.apache.pekko import pekko.actor._ @@ -28,8 +32,6 @@ import pekko.serialization.{ ByteBufferSerializer, SerializerWithStringManifest import pekko.serialization.jackson.CborSerializable import pekko.testkit._ -import java.io.NotSerializableException - object MaxThroughputSpec extends MultiNodeConfig { val first = role("first") val second = role("second") @@ -171,7 +173,7 @@ object MaxThroughputSpec extends MultiNodeConfig { val numTargets = targets.size import testSettings._ - val payload = ("0" * testSettings.payloadSize).getBytes("utf-8") + val payload = ("0" * testSettings.payloadSize).getBytes(StandardCharsets.UTF_8) var startTime = 0L var remaining = totalMessages var maxRoundTripMillis = 0L diff --git a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamConcistencySpec.scala b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamConcistencySpec.scala index cab62e9061..768c7447f1 100644 --- a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamConcistencySpec.scala +++ b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamConcistencySpec.scala @@ -15,6 +15,7 @@ package org.apache.pekko.remote.artery package aeron import java.io.File +import java.nio.charset.StandardCharsets import java.util.concurrent.atomic.AtomicInteger import scala.concurrent.Await @@ -127,7 +128,7 @@ abstract class AeronStreamConsistencySpec val done = TestLatch(1) val killSwitch = KillSwitches.shared("test") val started = TestProbe() - val startMsg = "0".getBytes("utf-8") + val startMsg = "0".getBytes(StandardCharsets.UTF_8) Source .fromGraph(new AeronSource(channel(first), streamId, aeron, taskRunner, pool, NoOpRemotingFlightRecorder, 0)) .via(killSwitch.flow) @@ -137,7 +138,7 @@ abstract class AeronStreamConsistencySpec started.ref ! Done else { val c = count.incrementAndGet() - val x = new String(bytes.toArray, "utf-8").toInt + val x = new String(bytes.toArray, StandardCharsets.UTF_8).toInt if (x != c) { throw new IllegalArgumentException(s"# wrong message $x expected $c") } @@ -174,7 +175,7 @@ abstract class AeronStreamConsistencySpec .throttle(10000, 1.second, 1000, ThrottleMode.Shaping) .map { n => val envelope = pool.acquire() - envelope.byteBuffer.put(n.toString.getBytes("utf-8")) + envelope.byteBuffer.put(n.toString.getBytes(StandardCharsets.UTF_8)) envelope.byteBuffer.flip() envelope } diff --git a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamLatencySpec.scala b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamLatencySpec.scala index e68272ed66..4ac3632387 100644 --- a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamLatencySpec.scala +++ b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamLatencySpec.scala @@ -15,6 +15,7 @@ package org.apache.pekko.remote.artery package aeron import java.io.File +import java.nio.charset.StandardCharsets import java.util.concurrent.CyclicBarrier import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicBoolean @@ -180,7 +181,7 @@ abstract class AeronStreamLatencySpec import testSettings._ runOn(first) { - val payload = ("1" * payloadSize).getBytes("utf-8") + val payload = ("1" * payloadSize).getBytes(StandardCharsets.UTF_8) // by default run for 2 seconds, but can be adjusted with the totalMessagesFactor val totalMessages = (2 * messageRate * totalMessagesFactor).toInt val sendTimes = new AtomicLongArray(totalMessages) @@ -193,7 +194,7 @@ abstract class AeronStreamLatencySpec val lastRepeat = new AtomicBoolean(false) val killSwitch = KillSwitches.shared(testName) val started = TestProbe() - val startMsg = "0".getBytes("utf-8") + val startMsg = "0".getBytes(StandardCharsets.UTF_8) Source .fromGraph(new AeronSource(channel(first), streamId, aeron, taskRunner, pool, NoOpRemotingFlightRecorder, 0)) .via(killSwitch.flow) diff --git a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamMaxThroughputSpec.scala b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamMaxThroughputSpec.scala index 16f410cd7c..1af66cfa3c 100644 --- a/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamMaxThroughputSpec.scala +++ b/remote-tests/src/multi-jvm/scala/org/apache/pekko/remote/artery/aeron/AeronStreamMaxThroughputSpec.scala @@ -15,6 +15,7 @@ package org.apache.pekko.remote.artery package aeron import java.io.File +import java.nio.charset.StandardCharsets import java.util.concurrent.Executors import scala.collection.AbstractIterator @@ -196,7 +197,7 @@ abstract class AeronStreamMaxThroughputSpec runOn(first) { enterBarrier(receiverName + "-started") - val payload = ("0" * payloadSize).getBytes("utf-8") + val payload = ("0" * payloadSize).getBytes(StandardCharsets.UTF_8) Source .fromIterator(() => iterate(1, totalMessages)) .map { _ => diff --git a/remote/src/test/scala/org/apache/pekko/remote/artery/SerializationErrorSpec.scala b/remote/src/test/scala/org/apache/pekko/remote/artery/SerializationErrorSpec.scala index a1e2353afc..1b2b791cda 100644 --- a/remote/src/test/scala/org/apache/pekko/remote/artery/SerializationErrorSpec.scala +++ b/remote/src/test/scala/org/apache/pekko/remote/artery/SerializationErrorSpec.scala @@ -13,6 +13,8 @@ package org.apache.pekko.remote.artery +import java.nio.charset.StandardCharsets + import org.apache.pekko import pekko.actor.{ ActorIdentity, Identify, RootActorPath } import pekko.testkit.EventFilter @@ -71,7 +73,7 @@ class SerializationErrorSpec extends ArteryMultiNodeSpec(ArterySpecSupport.defau EventFilter .error(pattern = """Failed to deserialize message from \[.*\] with serializer id \[4\]""", occurrences = 1) .intercept { - remoteRef ! "boom".getBytes("utf-8") + remoteRef ! "boom".getBytes(StandardCharsets.UTF_8) }(systemB) remoteRef ! "ping2" diff --git a/serialization-jackson/src/test/scala/org/apache/pekko/serialization/jackson/JacksonSerializerSpec.scala b/serialization-jackson/src/test/scala/org/apache/pekko/serialization/jackson/JacksonSerializerSpec.scala index a880931ae9..b0759cf469 100644 --- a/serialization-jackson/src/test/scala/org/apache/pekko/serialization/jackson/JacksonSerializerSpec.scala +++ b/serialization-jackson/src/test/scala/org/apache/pekko/serialization/jackson/JacksonSerializerSpec.scala @@ -180,7 +180,7 @@ class JacksonJsonSerializerSpec extends JacksonSerializerSpec("jackson-json") { def serializeToJsonString(obj: AnyRef, sys: ActorSystem = system): String = { val blob = serializeToBinary(obj, sys) - new String(blob, "utf-8") + new String(blob, StandardCharsets.UTF_8) } def deserializeFromJsonString( @@ -188,7 +188,7 @@ class JacksonJsonSerializerSpec extends JacksonSerializerSpec("jackson-json") { serializerId: Int, manifest: String, sys: ActorSystem = system): AnyRef = { - val blob = json.getBytes("utf-8") + val blob = json.getBytes(StandardCharsets.UTF_8) deserializeFromBinary(blob, serializerId, manifest, sys) } diff --git a/slf4j/src/test/scala/org/apache/pekko/event/slf4j/Slf4jLoggerSpec.scala b/slf4j/src/test/scala/org/apache/pekko/event/slf4j/Slf4jLoggerSpec.scala index 190c15114d..612874a0b6 100644 --- a/slf4j/src/test/scala/org/apache/pekko/event/slf4j/Slf4jLoggerSpec.scala +++ b/slf4j/src/test/scala/org/apache/pekko/event/slf4j/Slf4jLoggerSpec.scala @@ -14,6 +14,7 @@ package org.apache.pekko.event.slf4j import java.io.ByteArrayOutputStream +import java.nio.charset.StandardCharsets import scala.concurrent.duration._ @@ -71,7 +72,7 @@ object Slf4jLoggerSpec { class MyLogSource val output = new ByteArrayOutputStream - def outputString: String = output.toString("UTF-8") + def outputString: String = output.toString(StandardCharsets.UTF_8.name) class TestAppender[E] extends OutputStreamAppender[E] { diff --git a/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipSpec.scala b/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipSpec.scala index be82439a1d..97e4937c1f 100644 --- a/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipSpec.scala +++ b/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipSpec.scala @@ -14,6 +14,7 @@ package org.apache.pekko.stream.io.compression import java.io.{ InputStream, OutputStream } +import java.nio.charset.StandardCharsets import java.util.zip.{ GZIPInputStream, GZIPOutputStream, ZipException } import org.apache.pekko @@ -47,7 +48,7 @@ class GzipSpec extends CoderSpec("gzip") { ex.ultimateCause.getMessage should equal("Truncated GZIP stream") } "throw an error if compressed data is just missing the trailer at the end" in { - def brokenCompress(payload: String) = newCompressor().compress(ByteString(payload, "UTF-8")) + def brokenCompress(payload: String) = newCompressor().compress(ByteString(payload, StandardCharsets.UTF_8)) val ex = the[RuntimeException] thrownBy ourDecode(brokenCompress("abcdefghijkl")) ex.ultimateCause.getMessage should equal("Truncated GZIP stream") } diff --git a/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipWithCustomCompressionLevelSpec.scala b/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipWithCustomCompressionLevelSpec.scala index 3883cd9230..e106e8cc65 100644 --- a/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipWithCustomCompressionLevelSpec.scala +++ b/stream-tests/src/test/scala/org/apache/pekko/stream/io/compression/GzipWithCustomCompressionLevelSpec.scala @@ -13,6 +13,7 @@ package org.apache.pekko.stream.io.compression +import java.nio.charset.StandardCharsets import java.util.zip.{ Deflater, ZipException } import org.apache.pekko @@ -39,7 +40,7 @@ class GzipWithCustomCompressionLevelSpec extends GzipSpec { ex.ultimateCause.getMessage should equal("Truncated GZIP stream") } "throw an error if compressed data is just missing the trailer at the end" in { - def brokenCompress(payload: String) = newCompressor().compress(ByteString(payload, "UTF-8")) + def brokenCompress(payload: String) = newCompressor().compress(ByteString(payload, StandardCharsets.UTF_8)) val ex = the[RuntimeException] thrownBy ourDecode(brokenCompress("abcdefghijkl")) ex.ultimateCause.getMessage should equal("Truncated GZIP stream") } diff --git a/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/BidiFlowSpec.scala b/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/BidiFlowSpec.scala index 541f38e81a..fbb9b53e24 100644 --- a/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/BidiFlowSpec.scala +++ b/stream-tests/src/test/scala/org/apache/pekko/stream/scaladsl/BidiFlowSpec.scala @@ -13,6 +13,8 @@ package org.apache.pekko.stream.scaladsl +import java.nio.charset.StandardCharsets + import scala.annotation.nowarn import scala.collection.immutable import scala.concurrent.Await @@ -31,7 +33,7 @@ class BidiFlowSpec extends StreamSpec { val bidi = BidiFlow.fromFlows( Flow[Int].map(x => x.toLong + 2).withAttributes(name("top")), - Flow[ByteString].map(_.decodeString("UTF-8")).withAttributes(name("bottom"))) + Flow[ByteString].map(_.decodeString(StandardCharsets.UTF_8)).withAttributes(name("bottom"))) val inverse = BidiFlow.fromFlows( Flow[Long].map(x => x.toInt + 2).withAttributes(name("top")), @@ -41,7 +43,7 @@ class BidiFlowSpec extends StreamSpec { Source.single(42) ~> s val top = b.add(Flow[Int].map(x => x.toLong + 2)) - val bottom = b.add(Flow[ByteString].map(_.decodeString("UTF-8"))) + val bottom = b.add(Flow[ByteString].map(_.decodeString(StandardCharsets.UTF_8))) BidiShape(top.in, top.out, bottom.in, bottom.out) }) diff --git a/testkit/src/test/scala/org/apache/pekko/testkit/CoronerSpec.scala b/testkit/src/test/scala/org/apache/pekko/testkit/CoronerSpec.scala index 3f9cbcd77a..5e0d1111a8 100644 --- a/testkit/src/test/scala/org/apache/pekko/testkit/CoronerSpec.scala +++ b/testkit/src/test/scala/org/apache/pekko/testkit/CoronerSpec.scala @@ -15,6 +15,7 @@ package org.apache.pekko.testkit import java.io._ import java.lang.management.ManagementFactory +import java.nio.charset.StandardCharsets import java.util.concurrent.Semaphore import java.util.concurrent.locks.ReentrantLock @@ -28,9 +29,9 @@ class CoronerSpec extends AnyWordSpec with Matchers { private def captureOutput[A](f: PrintStream => A): (A, String) = { val bytes = new ByteArrayOutputStream() - val out = new PrintStream(bytes, true, "UTF-8") + val out = new PrintStream(bytes, true, StandardCharsets.UTF_8.name) val result = f(out) - (result, new String(bytes.toByteArray(), "UTF-8")) + (result, bytes.toString(StandardCharsets.UTF_8.name)) } "A Coroner" must {