Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8303503

(zipfs) ZipFileSystem does not set language encoding flag for directories

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      If you are using special characters in a directory, the language encoding flag is not set, which typically results in an empty directory with broken encoding when looking at the archive with, for instance, 7zip, unzip or the Windows Explorer.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      $ zipdetails test.zip
      [...]
      0006 General Purpose Flag 0800
           [Bit 11] 1 'Language Encoding'
      00E1 Filename 'äöß/'
      [...]

      ACTUAL -
      $ zipdetails test.zip
      [...]
      0006 General Purpose Flag 0000
      00E1 Filename 'äöß/'
      [...]


      ---------- BEGIN SOURCE ----------
      import java.net.URI;
      import java.nio.file.FileSystems;
      import java.nio.file.Files;
      import java.util.HashMap;
      import java.util.Map;

      class Test {
          static void main(String[] args) throws Exception {
                  Map<String, Object> env = new HashMap<>();
                  env.put("create", "true");
                  URI uri = new URI("jar:file:/" + System.getProperty("user.home") + "/Desktop/test.zip");

                  try (var fileSystem = FileSystems.newFileSystem(uri, env)) {
                      var path = fileSystem.getPath("äöß/käfer.txt");
                      Files.createDirectory(path.getParent());
                      Files.writeString(path, "Test!");
                  }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use:
      env.put("encoding", "Cp437");

      This works without the language encoding flag, but does not include as many characters, of course.

      FREQUENCY : always


      Attachments

        Activity

          People

            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: