Scripting dcm4che2 with Groovy

Groovy is a very elegant way of scripting dcm4che2:

import org.dcm4che2.data.*
import org.dcm4che2.io.*

// open stream and ensure that it is closed properly
new DicomInputStream(/d:\foo.dcm/ as File).withStream {dicomInputSteam ->
    // read the object from input stream
    def dicomObject = dicomInputSteam.readDicomObject()
    
    // iterate through all elements and print the element
    dicomObject.each {dicomElement ->
        println dicomElement
    }
}