Skip to content

Commit

Permalink
Merge pull request #5 from joan38/input-stream
Browse files Browse the repository at this point in the history
Don't use JDK 9 readAllBytes
  • Loading branch information
eed3si9n authored Aug 18, 2020
2 parents 1a7edbb + bfc2568 commit 9e3dc32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/src/main/scala/com/eed3si9n/jarjarabrams/Shader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.io.{ByteArrayInputStream, InputStream}
import java.nio.file.{ Files, Path, StandardOpenOption }
import org.pantsbuild.jarjar.{ JJProcessor, _ }
import org.pantsbuild.jarjar.util.EntryStruct
import com.eed3si9n.jarjarabrams.Utils.readAllBytes

object Shader {
def shadeDirectory(
Expand All @@ -18,7 +19,7 @@ object Shader {
newMappings.foreach { case (inputStream, mapping) =>
val out = dir.resolve(mapping)
if (!Files.exists(out.getParent)) Files.createDirectories(out.getParent)
Files.write(out, inputStream.readAllBytes(), StandardOpenOption.CREATE)
Files.write(out, readAllBytes(inputStream), StandardOpenOption.CREATE)
}
}

Expand Down Expand Up @@ -63,7 +64,7 @@ object Shader {
mappings.map(f => if (f._2.contains('\\')) (f._1, f._2.replace('\\', '/')) else f)
val shadedInputStreams = sanitizedMappings.flatMap { f =>
val entry = new EntryStruct
entry.data = f._1.readAllBytes()
entry.data = readAllBytes(f._1)
entry.name = f._2
entry.time = -1
entry.skipTransform = false
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/scala/com/eed3si9n/jarjarabrams/Utils.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.eed3si9n.jarjarabrams

import java.io.InputStream

object Utils {
// Use InputStream.readAllBytes() once on JDK >=9
def readAllBytes(inputStream: InputStream): Array[Byte] =
Stream.continually(inputStream.read).takeWhile(_ != -1).map(_.toByte).toArray
}

0 comments on commit 9e3dc32

Please sign in to comment.