31 import java.nio.file.FileSystem; |
31 import java.nio.file.FileSystem; |
32 import java.nio.file.FileSystems; |
32 import java.nio.file.FileSystems; |
33 import java.nio.file.Files; |
33 import java.nio.file.Files; |
34 import java.nio.file.Path; |
34 import java.nio.file.Path; |
35 import java.util.Arrays; |
35 import java.util.Arrays; |
|
36 import java.util.Map; |
36 import java.util.spi.ToolProvider; |
37 import java.util.spi.ToolProvider; |
37 import java.util.zip.CRC32; |
38 import java.util.zip.CRC32; |
38 import java.util.zip.ZipEntry; |
39 import java.util.zip.ZipEntry; |
39 import java.util.zip.ZipFile; |
40 import java.util.zip.ZipFile; |
40 import java.util.zip.ZipOutputStream; |
41 import java.util.zip.ZipOutputStream; |
114 String replacedValue = "bar"; |
115 String replacedValue = "bar"; |
115 Path zipFile = Path.of(jarFileName); |
116 Path zipFile = Path.of(jarFileName); |
116 |
117 |
117 // Create JAR file with a STORED(non-compressed) entry |
118 // Create JAR file with a STORED(non-compressed) entry |
118 Files.writeString(Path.of(storedFileName), "foobar"); |
119 Files.writeString(Path.of(storedFileName), "foobar"); |
119 int rc = JAR_TOOL.run(System.out, System.err, |
120 JAR_TOOL.run(System.out, System.err, |
120 "cM0vf", jarFileName, storedFileName); |
121 "cM0vf", jarFileName, storedFileName); |
121 |
122 |
122 // Replace the STORED entry |
123 // Replace the STORED entry using the default(DEFLATED) compression |
|
124 // method. |
123 try (FileSystem fs = FileSystems.newFileSystem(zipFile)) { |
125 try (FileSystem fs = FileSystems.newFileSystem(zipFile)) { |
124 Files.writeString(fs.getPath(storedFileName), replacedValue); |
126 Files.writeString(fs.getPath(storedFileName), replacedValue); |
125 } |
127 } |
126 Entry e1 = Entry.of(storedFileName, ZipEntry.STORED, replacedValue); |
128 Entry e1 = Entry.of(storedFileName, ZipEntry.DEFLATED, replacedValue); |
127 verify(zipFile, e1); |
129 verify(zipFile, e1); |
128 } |
130 } |
129 |
131 |
130 /** |
132 /** |
131 * Test updating an entry that is STORED (not compressed) |
133 * Test updating an entry that is STORED (not compressed) |
157 |
159 |
158 verify(zipfile, e1, e2); |
160 verify(zipfile, e1, e2); |
159 |
161 |
160 String newContents = "hi"; |
162 String newContents = "hi"; |
161 |
163 |
|
164 // Set the required compression method |
|
165 Map<String, Boolean> map = Map.of("noCompression", |
|
166 e1.method != ZipEntry.DEFLATED); |
|
167 |
162 // replace contents of e1 |
168 // replace contents of e1 |
163 try (FileSystem fs = FileSystems.newFileSystem(zipfile)) { |
169 try (FileSystem fs = FileSystems.newFileSystem(zipfile, map)) { |
164 Path foo = fs.getPath(e1.name); |
170 Path foo = fs.getPath(e1.name); |
165 Files.writeString(foo, newContents); |
171 Files.writeString(foo, newContents); |
166 } |
172 } |
167 |
173 |
168 verify(zipfile, e1.content(newContents), e2); |
174 verify(zipfile, e1.content(newContents), e2); |