|
6 | 6 |
|
7 | 7 | package org.cadixdev.atlas.util;
|
8 | 8 |
|
| 9 | +import static java.nio.file.StandardCopyOption.ATOMIC_MOVE; |
| 10 | +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; |
| 11 | + |
9 | 12 | import java.io.IOException;
|
10 | 13 | import java.io.InputStream;
|
11 | 14 | import java.io.OutputStream;
|
|
19 | 22 | import java.util.jar.Manifest;
|
20 | 23 | import java.util.zip.ZipEntry;
|
21 | 24 |
|
22 |
| -import static java.nio.file.StandardCopyOption.ATOMIC_MOVE; |
23 |
| -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; |
24 |
| - |
| 25 | +/** |
| 26 | + * A helper class for repackaging jar files so that they're read by Java correctly, see {@link #verifyJarManifest(Path)} |
| 27 | + * for more details. |
| 28 | + * |
| 29 | + * @author Kyle Wood |
| 30 | + * @since 0.2.1 |
| 31 | + */ |
25 | 32 | public final class JarRepacker {
|
26 | 33 |
|
27 |
| - private JarRepacker() {} |
| 34 | + private JarRepacker() { |
| 35 | + } |
28 | 36 |
|
29 | 37 | /**
|
30 | 38 | * {@link JarInputStream} requires that if a {@code META-INF/MANIFEST.MF} record is present in a jar file, it must be
|
@@ -86,14 +94,16 @@ private static void fixJarManifest(final Path outputJar) throws IOException {
|
86 | 94 | out.putNextEntry(new ZipEntry(name));
|
87 | 95 | try (final InputStream input = jarFile.getInputStream(currentEntry)) {
|
88 | 96 | copy(input, out, buffer);
|
89 |
| - } finally { |
| 97 | + } |
| 98 | + finally { |
90 | 99 | out.closeEntry();
|
91 | 100 | }
|
92 | 101 | }
|
93 | 102 | }
|
94 | 103 |
|
95 | 104 | Files.move(tempOut, outputJar, REPLACE_EXISTING, ATOMIC_MOVE);
|
96 |
| - } finally { |
| 105 | + } |
| 106 | + finally { |
97 | 107 | Files.deleteIfExists(tempOut);
|
98 | 108 | }
|
99 | 109 | }
|
@@ -137,4 +147,5 @@ private static void copy(final InputStream from, final OutputStream to, final by
|
137 | 147 | to.write(buffer, 0, read);
|
138 | 148 | }
|
139 | 149 | }
|
| 150 | + |
140 | 151 | }
|
0 commit comments