Skip to content

Commit

Permalink
use ByteStringInputStream (#309)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
pjfanning and jtjeferreira authored May 21, 2024
1 parent 2ef115e commit 6221aa6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6221aa6

Please sign in to comment.