Created
July 10, 2012 08:17
-
-
Save anonymous/3081986 to your computer and use it in GitHub Desktop.
Trying code from SO thread: http://stackoverflow.com/questions/11369511/why-does-groovy-think-im-passing-an-instance-of-the-class-from-a-static-method#comment14982771_11369511
This file contains 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
$ groovy -version | |
Groovy Version: 1.8.6 JVM: 1.6.0_33 Vendor: Apple Inc. OS: Mac OS X | |
$ ls | |
CharacterMap.groovy bar.txt | |
$ groovy -Dlocation=bar.txt CharacterMap.groovy foo | |
Jul 10, 2012 1:15:31 AM java.lang.Class constructor | |
WARNING: Server configuration groovy file not configured with system property location | |
foo | |
$ cat CharacterMap.groovy | |
import static java.util.logging.Logger.* | |
import static java.util.logging.Level.* | |
class CharacterMap { | |
public static final String CHARACTER_CONFIGURATION = 'location' | |
static Map<String,String> characterMap = null | |
public static String ASCIIize(String input) | |
{ | |
if (!characterMap) | |
{ | |
def property = System.getProperty( CHARACTER_CONFIGURATION ) | |
ConfigObject config = null | |
if( property ) { | |
ConfigSlurper cs = new ConfigSlurper() | |
File file = new File( property ) | |
URL location = file.toURL() | |
config = cs.parse(location) | |
} | |
if (config) | |
{ | |
characterMap = config.characters | |
} | |
else | |
{ | |
getAnonymousLogger().logp WARNING, getClass().name, 'constructor', | |
"Server configuration groovy file not configured with system property ${CHARACTER_CONFIGURATION}" | |
return input | |
} | |
} | |
for (String key: characterMap.keySet()) | |
{ | |
if (input.contains(key)) | |
{ | |
input = input.replace(key, characterMap.get(key)) | |
} | |
} | |
return input | |
} | |
public static void main(String[] args) | |
{ | |
print ASCIIize(args[0]) | |
} | |
} | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment