This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-grpc.git


The following commit(s) were added to refs/heads/main by this push:
     new 6221aa69 use ByteStringInputStream (#309)
6221aa69 is described below

commit 6221aa694ea2083d8a89300edcd9ffdf1048eb49
Author: PJ Fanning <[email protected]>
AuthorDate: Tue May 21 08:53:09 2024 +0100

    use ByteStringInputStream (#309)
    
    * use ByteStringInputStream
    
    * unused import
    
    * rework legacyConvert
    
    Co-Authored-By: João Ferreira <[email protected]>
    
    * simpler code
    
    Co-Authored-By: João Ferreira <[email protected]>
    
    ---------
    
    Co-authored-by: João Ferreira <[email protected]>
---
 .../grpc/internal/ByteStringInputStream.scala      | 34 ++++++++++++++++++++++
 .../org/apache/pekko/grpc/internal/Gzip.scala      |  4 +--
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git 
a/runtime/src/main/scala/org/apache/pekko/grpc/internal/ByteStringInputStream.scala
 
b/runtime/src/main/scala/org/apache/pekko/grpc/internal/ByteStringInputStream.scala
new file mode 100644
index 00000000..b0045535
--- /dev/null
+++ 
b/runtime/src/main/scala/org/apache/pekko/grpc/internal/ByteStringInputStream.scala
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * license agreements; and to You under the Apache License, version 2.0:
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * This file is part of the Apache Pekko project, which was derived from Akka.
+ */
+
+/*
+ * Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
+ */
+
+package org.apache.pekko.grpc.internal
+
+import java.io.{ ByteArrayInputStream, InputStream, SequenceInputStream }
+
+import org.apache.pekko
+import pekko.annotation.InternalApi
+import pekko.util.ByteString
+import pekko.util.ByteString.ByteStrings
+import pekko.util.ccompat.JavaConverters._
+
+/** INTERNAL API */
+@InternalApi
+private[internal] object ByteStringInputStream {
+
+  def apply(bs: ByteString): InputStream = bs match {
+    case bss: ByteStrings =>
+      new 
SequenceInputStream(bss.bytestrings.iterator.map(apply).asJavaEnumeration)
+    case _ =>
+      new ByteArrayInputStream(bs.toArrayUnsafe())
+  }
+}
diff --git a/runtime/src/main/scala/org/apache/pekko/grpc/internal/Gzip.scala 
b/runtime/src/main/scala/org/apache/pekko/grpc/internal/Gzip.scala
index 5b6dedbe..e4aa6f2e 100644
--- a/runtime/src/main/scala/org/apache/pekko/grpc/internal/Gzip.scala
+++ b/runtime/src/main/scala/org/apache/pekko/grpc/internal/Gzip.scala
@@ -13,7 +13,7 @@
 
 package org.apache.pekko.grpc.internal
 
-import java.io.{ ByteArrayInputStream, ByteArrayOutputStream }
+import java.io.ByteArrayOutputStream
 import java.util.zip.{ GZIPInputStream, GZIPOutputStream }
 
 import org.apache.pekko.util.ByteString
@@ -30,7 +30,7 @@ object Gzip extends Codec {
   }
 
   override def uncompress(compressed: ByteString): ByteString = {
-    val gzis = new GZIPInputStream(new 
ByteArrayInputStream(compressed.toArrayUnsafe()))
+    val gzis = new GZIPInputStream(ByteStringInputStream(compressed))
 
     val baos = new ByteArrayOutputStream(compressed.size)
     val buffer = new Array[Byte](32 * 1024)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to