Posts Tagged groovy

GPG Encryption — Using Groovy

Here is a great example of how Groovy is so much less verbose than Java.

The script below is a simple utility I wrote that encrypts a directory of files using GPG. The command.execute() syntax in groovy is so much less verbose than the Java counterpart.

def fileEncrypter(srcFolder, destFolder)
{
	new File(destFolder).eachFile{file ->
		println "Deleting File: " + file.absolutePath
		file.delete()
	}
 
	new File(srcFolder).eachFile{file ->
		String command = "gpg -e -o "
		command += destFolder + "/" + file.name
		command += ".pgp -r "My Key" --yes -q "
		command += srcFolder + "/" + file.name
		println "Encrypting file: " + file.absolutePath
		command.execute().text
	}
}

Tags: ,

The day I discovered Groovy

Groovy has changed my life. At least my life as a software engineer. After many years of Java programming, I was disenchanted with the language’s restrictiveness. I delved into Ruby to find solace in dynamic languages and I found that I wasn’t exactly happy switching completely out of the Java paradigm. Especially when it came to constructing Enterprise-level applications. Well… along came Groovy… and my world has changed. Closures, Dynamic Typing and many other features that allow you to get things done quicker… and it all runs within the JVM. Brilliant…

Here are some cool examples of looping mechanisms in Groovy:

0.upto(4) { print "$it " }

outputs

0 1 2 3 4

http://groovy.codehaus.org/Looping

Tags: