0

When analyzing the resulting file, the value is written correctly so setUnixMode() probably works ok, but getUnixMode() always returns 0. Does anyone have any experience with this?

File file = new File("Test.file");
ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(new FileOutputStream(file));   
ZipArchiveEntry zipArchiveEntry = new ZipArchiveEntry("Entry");  
zipArchiveEntry.setUnixMode(0744);
zipArchiveOutputStream.putArchiveEntry(zipArchiveEntry);
zipArchiveOutputStream.write("TestBytes".getBytes());
zipArchiveOutputStream.closeArchiveEntry();
zipArchiveOutputStream.close();
                        
ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(new FileInputStream(file));
ZipArchiveEntry entryOut = zipArchiveInputStream.getNextZipEntry();
System.out.println(entryOut.getUnixMode());
Jolinar
  • 866
  • 8
  • 16

2 Answers2

0

getUnixMode() returns 0 when platform != PLATFORM_UNIX (see here for the source code). So you also have to specify the platform: zipArchiveEntry.setPlatform(ZipArchiveEntry.PLATFORM_UNIX)

rmunge
  • 3,653
  • 5
  • 19
0

Due to the design of the ZIP format, it is not possible to read the unix mode when the ZIP is opened as a stream.

ZipArchiveInputStream is limited and may even return false contents in some cases, use ZipFile whenever possible. See the ZIP documentation page for details. This limitation is a result of streaming data vs using random access and not a limitation of Compress' specific implementation.

source

The fix is to use ZipFile instead. I have tried this and can confirm that when doing so it works.

Nand
  • 568
  • 3
  • 18