Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Upcoming SlideShare
G* Workshop in Fukuoka - Introduction
Next
Download to read offline and view in fullscreen.

1

Share

Download to read offline

お題でGroovyプログラミング: Part A

Download to read offline

JGGUGサマースペシャルg*ワークショップ2009での発表資料。Part Bは上原さん、Part Cは須江さん。

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

お題でGroovyプログラミング: Part A

  1. 1. ! !
  2. 2. ! http://groups.google.com/group/jggug-summer-2009 ! ! jggug-summer-2009@googlegroups.com subject / ! !
  3. 3. ! ! ! ! ! !
  4. 4. ! ! JAVA_HOME GROOVY_HOME ! $GROOVY_HOME/bin ! % groovy -v Groovy Version: 1.6.4 JVM: 1.5.0_19
  5. 5. ! ! ! ! – ! – ! –
  6. 6. ! ! Input/OutputStream Reader/Writer % groovy filecopy <srcfile> <destfile>
  7. 7. ! ! ! ! File#getText(), readBytes(), append(), leftShift()... ! ! String#execute() groovy.util.AntBuilder
  8. 8. java.io.File src = new File(args[0]) dest = new File(args[1]) dest << src.text dest.leftShift(src.getText()) leftShift append GDK
  9. 9. src = new File(args[0]) dest = new File(args[1]) dest << src.readBytes() OutOfMemoryError
  10. 10. proc = "cp ${args[0]} ${args[1]}".execute() proc.waitFor() waitFor() cp OK UNIX cp
  11. 11. ant = new AntBuilder() ant.copy(file:args[0], tofile:args[1]) Ant copy OK
  12. 12. ! ! % groovy feedreader <URL>
  13. 13. ! !
  14. 14. <rdf:RDF> <channel> ... </channel> <item> <title>...</title> ... </item> <item> <title>...</title> ... </item> </rdf:RDF>
  15. 15. <rss> <channel> ... <item> <title>...</title> ... </item> <item> <title>...</title> ... </item> </channel> </rss>
  16. 16. <feed> ... <entry> <title>...</title> ... </entry> <entry> <title>...</title> ... </entry> </feed>
  17. 17. root = new XmlSlurper().parse(args[0]) switch(root.name()) { case 'RDF' : nodes = root.item; break case 'rss' : nodes = root.channel.item; break case 'feed': nodes = root.entry; break } nodes.each { println it.title }
  18. 18. ! ! % groovy -l 8080 httpserver
  19. 19. ! -l <port> ! ! line ! return 'success'
  20. 20. if (!line) { println 'HTTP/1.0 200 OK' println 'Content-Type: text/htmln' println new File('message.html').text return 'success' } If
  21. 21. ! % groovy -l 8080 httpserver
  22. 22. ! !
  23. 23. import groovy.text.SimpleTemplateEngine as STE if (!line) { println 'HTTP/1.0 200 OK' println 'Content-Type: text/htmln' text = new File('message.html').text println new STE().createTemplate(text).make() return 'success' }
  24. 24. ! ! ! http://ja.doukaku.org/205/ % groovy cmdopt <arguments...>
  25. 25. cli = new CliBuilder(usage:'cmdopt -o [-q] [-d{0|1|2}] [ ...]') cli.with { o longOpt:'output', 'set output', required:true q longOpt:'quote', 'set quote' d longOpt:'debug', 'set debug level', args:1, argName:'level' } if (!(opt = cli.parse(args))) die 'bad command line' params = opt.arguments() if (params.size() < 1) die 'parameter must be specified' level = opt.d ? opt.d as int : 0 if (!(level in 0..2)) die 'debug level must be in 0-2'
  26. 26. println '[ ]' println "o(output): ${opt.o ? 'ON' : 'OFF'}" println "q(quote): ${opt.q ? 'ON' : 'OFF'}" println "d(debug): $level" println 'n[ ]' println " : ${params.size()}" params.eachWithIndex { param, i -> println "${i + 1}: $param" } def die(msg) { cli.writer.println "error: $msg" cli.usage() System.exit 1 }
  • ShunyaShishido

    Jul. 1, 2013

JGGUGサマースペシャルg*ワークショップ2009での発表資料。Part Bは上原さん、Part Cは須江さん。

Views

Total views

1,656

On Slideshare

0

From embeds

0

Number of embeds

2

Actions

Downloads

2

Shares

0

Comments

0

Likes

1

×