Last active
March 12, 2019 08:46
-
-
Save akunzai/61380a539636400a5bf9323fdecee5cb to your computer and use it in GitHub Desktop.
Java Properties Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (args.length == 0) { | |
| println("Usage: groovy prop2xml.groovy messages.(properties|xml) [format]") | |
| println("read from STDIN: groovy prop2xml.groovy - [format]") | |
| System.exit(0) | |
| } | |
| def input = args[0] == '-' | |
| ? System.in | |
| : new File(args[0]).newInputStream() | |
| def format = args.size() > 1 | |
| ? args[1] | |
| : args[0].substring(args[0].lastIndexOf(".") + 1) | |
| def props = new Properties() | |
| input.withStream { stream -> | |
| if (format.endsWith("xml")) { | |
| props.loadFromXML(stream) | |
| props.store(System.out, null) | |
| } else { | |
| props.load(stream) | |
| props.storeToXML(System.out, null) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment