|
34 | 34 | import java.nio.channels.Channels;
|
35 | 35 | import java.nio.channels.ReadableByteChannel;
|
36 | 36 | import java.nio.charset.StandardCharsets;
|
| 37 | +import java.nio.file.FileVisitResult; |
37 | 38 | import java.nio.file.Files;
|
38 | 39 | import java.nio.file.Path;
|
39 | 40 | import java.nio.file.Paths;
|
| 41 | +import java.nio.file.SimpleFileVisitor; |
| 42 | +import java.nio.file.attribute.BasicFileAttributes; |
40 | 43 | import java.util.ArrayList;
|
41 | 44 | import java.util.Arrays;
|
42 | 45 | import java.util.Collection;
|
@@ -2851,6 +2854,39 @@ public static void fileJsonToXml(String jsonFileName, String xmlFileName) throws
|
2851 | 2854 | fileJsonToXml(jsonFileName, xmlFileName, Xml.XmlStringBuilder.Step.TWO_SPACES);
|
2852 | 2855 | }
|
2853 | 2856 |
|
| 2857 | + public static void jsonFolderToXml( |
| 2858 | + String jsonFolder, String xmlFolder, Xml.XmlStringBuilder.Step identStep) |
| 2859 | + throws IOException { |
| 2860 | + Path sourceRoot = Paths.get(jsonFolder); |
| 2861 | + Path targetRoot = Paths.get(xmlFolder); |
| 2862 | + Files.walkFileTree(sourceRoot, new SimpleFileVisitor<>() { |
| 2863 | + @Override |
| 2864 | + public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { |
| 2865 | + covertJsonToXml(path, sourceRoot, targetRoot, identStep); |
| 2866 | + return FileVisitResult.CONTINUE; |
| 2867 | + } |
| 2868 | + }); |
| 2869 | + } |
| 2870 | + |
| 2871 | + public static void jsonFolderToXml(String jsonFolder, String xmlFolder) throws IOException { |
| 2872 | + jsonFolderToXml(jsonFolder, xmlFolder, Xml.XmlStringBuilder.Step.TWO_SPACES); |
| 2873 | + } |
| 2874 | + |
| 2875 | + public static void covertJsonToXml(Path path, Path sourceRoot, Path targetRoot, |
| 2876 | + Xml.XmlStringBuilder.Step identStep) throws IOException { |
| 2877 | + Path relativePath = sourceRoot.relativize(path); |
| 2878 | + String fileName = relativePath.getFileName().toString(); |
| 2879 | + String xmlFileName; |
| 2880 | + if (fileName.endsWith(".json")) { |
| 2881 | + xmlFileName = fileName.substring(0, fileName.length() - 5) + ".xml"; |
| 2882 | + } else { |
| 2883 | + return; |
| 2884 | + } |
| 2885 | + Path targetPath = targetRoot.resolve(relativePath).getParent().resolve(xmlFileName); |
| 2886 | + Files.createDirectories(targetPath.getParent()); |
| 2887 | + fileJsonToXml(path.toAbsolutePath().toString(), targetPath.toString(), identStep); |
| 2888 | + } |
| 2889 | + |
2854 | 2890 | public static void streamJsonToXml(
|
2855 | 2891 | InputStream jsonInputStream,
|
2856 | 2892 | OutputStream xmlOutputStream,
|
|
0 commit comments