pathikrit/better-files

Zip/unzip file with JDK 11 throws java.nio.charset.MalformedInputException

CharlesD91 opened this issue · 0 comments

Hello,

Using Ubuntu 18.04.3 LTS and openjdk version "11.0.5" 2019-10-15, the following code throws java.lang.IllegalArgumentException: java.nio.charset.MalformedInputException: Input length = 1:

import better.files.File

for {
      tempFile <- File.temporaryFile("file_", ".txt")
      _ = tempFile.overwrite("hello")
      tempZip <- File.temporaryFile("zip_", ".zip")
        .map(_.zipIn(Iterator(tempFile)))
 } {
      println(tempZip.unzip().list.next.contentAsString)
 }

while it works using JDK 8.

Also specifying the Charset during the zip fixes the problem; the following code works:

import java.nio.charset.Charset
import better.files.File

for {
      tempFile <- File.temporaryFile("file_", ".txt")
      _ = tempFile.overwrite("hello")
      tempZip <- File.temporaryFile("zip_", ".zip")
        .map(_.zipIn(Iterator(tempFile))(Charset.forName("UTF-8")))
} {
      println(tempZip.unzip().list.next.contentAsString)
}