Skip to content

Commit

Permalink
Update ByteStringInputStream.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Apr 19, 2024
1 parent 9aeb43c commit b95c28f
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import scala.util.Try
import org.apache.pekko
import pekko.annotation.InternalApi
import pekko.util.ByteString
import pekko.util.ByteString.ByteString1C

/** INTERNAL API */
@InternalApi
Expand All @@ -36,6 +37,15 @@ private[http2] object ByteStringInputStream {
byteStringInputStreamMethodTypeOpt.map { mh =>
mh.invoke(bs).asInstanceOf[InputStream]
}.getOrElse {
new ByteArrayInputStream(bs.toArrayUnsafe())
legacyConvert(bs)
}

private def legacyConvert(bs: ByteString): InputStream =
bs match {
case cs: ByteString1C =>
new ByteArrayInputStream(cs.toArrayUnsafe())
case _ =>
// NOTE: We actually measured recently, and compact + use array was pretty good usually
apply(bs.compact)
}
}

0 comments on commit b95c28f

Please sign in to comment.