|
32 | 32 | import java.util.Collection; |
33 | 33 | import java.util.List; |
34 | 34 | import java.util.Map; |
35 | | -import java.util.function.Predicate; |
36 | 35 | import java.util.stream.Stream; |
37 | 36 |
|
38 | 37 | @Component |
@@ -146,23 +145,22 @@ private static String convertToAsciiChar(char ch) { |
146 | 145 | } |
147 | 146 |
|
148 | 147 | public void compressNetexFiles(Exchange exchange, @Header(Exchange.FILE_NAME) String compressedFileName) { |
149 | | - Path netexOutputPath = Paths.get(generatedOutputPath); |
150 | | - Path zipOutputPath = Paths.get(compressedOutputPath); |
151 | | - Path zipOutputFilePath = Paths.get(zipOutputPath.toString(), compressedFileName); |
152 | | - PathMatcher matcher = netexOutputPath.getFileSystem().getPathMatcher(XML_GLOB); |
153 | | - Predicate<Path> isRegularFile = path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS); |
154 | | - |
155 | | - if (!Files.exists(zipOutputPath)) { |
156 | | - try { |
157 | | - Files.createDirectory(zipOutputPath); |
158 | | - } catch (IOException e) { |
159 | | - throw new ExtimeException("Error while compressing NeTEx files", e); |
160 | | - } |
| 148 | + Path netexOutputDirPath = Paths.get(generatedOutputPath); |
| 149 | + Path zipOutputDirPath = Paths.get(compressedOutputPath); |
| 150 | + try { |
| 151 | + Files.createDirectories(netexOutputDirPath); |
| 152 | + Files.createDirectories(zipOutputDirPath); |
| 153 | + } catch (IOException e) { |
| 154 | + throw new ExtimeException("Error while compressing NeTEx files", e); |
161 | 155 | } |
162 | 156 |
|
163 | | - try (Stream<Path> stream = Files.list(netexOutputPath)) { |
| 157 | + Path zipOutputFilePath = zipOutputDirPath.resolve(compressedFileName); |
| 158 | + PathMatcher matcher = netexOutputDirPath.getFileSystem().getPathMatcher(XML_GLOB); |
| 159 | + |
| 160 | + try (Stream<Path> stream = Files.list(netexOutputDirPath)) { |
164 | 161 | File[] files = stream |
165 | | - .filter(isRegularFile.and(path -> matcher.matches(path.getFileName()))) |
| 162 | + .filter(path -> Files.isRegularFile(path, LinkOption.NOFOLLOW_LINKS)) |
| 163 | + .filter(path -> matcher.matches(path.getFileName())) |
166 | 164 | .map(Path::toFile) |
167 | 165 | .toArray(File[]::new); |
168 | 166 | ZipUtil.packEntries(files, zipOutputFilePath.toFile()); |
|
0 commit comments