238 Path parent = path.getParent(); |
238 Path parent = path.getParent(); |
239 String filename = path.getFileName().toString() + suffix; |
239 String filename = path.getFileName().toString() + suffix; |
240 return parent != null ? parent.resolve(filename) : Path.of(filename); |
240 return parent != null ? parent.resolve(filename) : Path.of(filename); |
241 } |
241 } |
242 |
242 |
|
243 public static String getSuffix(Path path) { |
|
244 String filename = replaceSuffix(path.getFileName(), null).toString(); |
|
245 return path.getFileName().toString().substring(filename.length()); |
|
246 } |
|
247 |
243 @FunctionalInterface |
248 @FunctionalInterface |
244 public static interface XmlConsumer { |
249 public static interface XmlConsumer { |
245 void accept(XMLStreamWriter xml) throws IOException, XMLStreamException; |
250 void accept(XMLStreamWriter xml) throws IOException, XMLStreamException; |
246 } |
251 } |
247 |
252 |
248 public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws |
253 public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws |
249 IOException { |
254 IOException { |
250 XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); |
255 XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); |
251 try (Writer w = new BufferedWriter(new FileWriter(dstFile.toFile()))) { |
256 try (Writer w = Files.newBufferedWriter(dstFile)) { |
252 // Wrap with pretty print proxy |
257 // Wrap with pretty print proxy |
253 XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance( |
258 XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance( |
254 XMLStreamWriter.class.getClassLoader(), new Class<?>[]{ |
259 XMLStreamWriter.class.getClassLoader(), new Class<?>[]{ |
255 XMLStreamWriter.class}, new PrettyPrintHandler( |
260 XMLStreamWriter.class}, new PrettyPrintHandler( |
256 xmlFactory.createXMLStreamWriter(w))); |
261 xmlFactory.createXMLStreamWriter(w))); |