based on Google I managed to write a little Groovy script that packs a zip just as I needed.
ZipOutputStream zipOutput = new ZipOutputStream(new FileOutputStream("${uid}.pufi"));
ZipEntry mainentry = new ZipEntry('main.xml')
zipOutput.putNextEntry(mainentry)
zipOutput << "mainmainmain"
zipOutput.closeEntry()
ZipEntry manifentry = new ZipEntry('manifest.xml')
zipOutput.putNextEntry(manifentry)
zipOutput << new FileInputStream(options.manifest)
zipOutput.closeEntry()
It works, but I would like to know how does Groovy figure out what to call on lines entry << "foobar" or entry << new FileInputStream(..). As I see ZipOutputStream is a Java class, its javadoc doesn’t contain any method, that could be called with even String or InputStream arguments. Could you explain me how does it work and where is it documented? I’d like to know more about Groovy.. 🙂
Groovy adds additional methods to some basic Java classes in order to use them in a more groovy way. For a complete overview af the additional methods look at http://groovy.codehaus.org/groovy-jdk. In your case, the method
leftShiftwas added the class OutputStream. Groovy also overloads the<<operator, so it’s the same as calling the methodleftShifton the object.