SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
!




!
!


        http://groups.google.com/group/jggug-summer-2009
!


    !


        jggug-summer-2009@googlegroups.com
        subject                    /
    !


!
!


    !


!


    !


!


    !
!




!           JAVA_HOME          GROOVY_HOME

!   $GROOVY_HOME/bin

!


    % groovy -v
    Groovy Version: 1.6.4 JVM: 1.5.0_19
!


    !


!


    !


        –
    !


        –
    !


        –
!




    !   Input/OutputStream   Reader/Writer


    % groovy filecopy <srcfile> <destfile>
!


!


    !


    !
                     File#getText(), readBytes(), append(), leftShift()...
    !


    !
                   String#execute()



        groovy.util.AntBuilder
java.io.File



src = new File(args[0])
dest = new File(args[1])
dest << src.text
                dest.leftShift(src.getText())
                leftShift append
                          GDK
src = new File(args[0])
dest = new File(args[1])
dest << src.readBytes()




             OutOfMemoryError
proc = "cp ${args[0]} ${args[1]}".execute()
proc.waitFor()

         waitFor()
         cp



                     OK   UNIX cp
ant = new AntBuilder()
ant.copy(file:args[0], tofile:args[1])

       Ant copy


                        OK
!




!




    % groovy feedreader <URL>
!




!
<rdf:RDF>
  <channel>
  ...
  </channel>
  <item>
    <title>...</title>
    ...
  </item>
  <item>
    <title>...</title>
    ...
  </item>
</rdf:RDF>
<rss>
  <channel>
    ...
    <item>
      <title>...</title>
      ...
    </item>
    <item>
      <title>...</title>
      ...
    </item>
  </channel>
</rss>
<feed>
  ...
  <entry>
    <title>...</title>
    ...
  </entry>
  <entry>
    <title>...</title>
    ...
  </entry>
</feed>
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 }
!




    !




    % groovy -l 8080 httpserver
!   -l <port>
    !




    !

                    line

    !                      return
        'success'
if (!line) {
  println 'HTTP/1.0 200 OK'
  println 'Content-Type: text/htmln'
  println new File('message.html').text
  return 'success'
}

                If
!




    % groovy -l 8080 httpserver
!


    !
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'
}
!




    !


    !      http://ja.doukaku.org/205/


    % groovy cmdopt <arguments...>
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'
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
}

Más contenido relacionado

La actualidad más candente

Biicode OpenExpoDay
Biicode OpenExpoDayBiicode OpenExpoDay
Biicode OpenExpoDay
fcofdezc
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
Shawn Meng
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
Nat Weerawan
 

La actualidad más candente (20)

gunicorn introduction
gunicorn introductiongunicorn introduction
gunicorn introduction
 
루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날루비가 얼랭에 빠진 날
루비가 얼랭에 빠진 날
 
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
Jan Stępień - GraalVM: Fast, Polyglot, Native - Codemotion Berlin 2018
 
nginx mod PSGI
nginx mod PSGInginx mod PSGI
nginx mod PSGI
 
Biicode OpenExpoDay
Biicode OpenExpoDayBiicode OpenExpoDay
Biicode OpenExpoDay
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails
 
Make BDD great again
Make BDD great againMake BDD great again
Make BDD great again
 
How Secure Are Docker Containers?
How Secure Are Docker Containers?How Secure Are Docker Containers?
How Secure Are Docker Containers?
 
Build web application by express
Build web application by expressBuild web application by express
Build web application by express
 
OWASP Proxy
OWASP ProxyOWASP Proxy
OWASP Proxy
 
Finding Clojure
Finding ClojureFinding Clojure
Finding Clojure
 
Lightweight DAS components in Perl
Lightweight DAS components in PerlLightweight DAS components in Perl
Lightweight DAS components in Perl
 
Couchdb
CouchdbCouchdb
Couchdb
 
Node.js - Best practices
Node.js  - Best practicesNode.js  - Best practices
Node.js - Best practices
 
tdc2012
tdc2012tdc2012
tdc2012
 
GettingStartedWithPHP
GettingStartedWithPHPGettingStartedWithPHP
GettingStartedWithPHP
 
2015 555 kharchenko_ppt
2015 555 kharchenko_ppt2015 555 kharchenko_ppt
2015 555 kharchenko_ppt
 
R版Getopt::Longを作ってみた
R版Getopt::Longを作ってみたR版Getopt::Longを作ってみた
R版Getopt::Longを作ってみた
 
Redis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your applicationRedis & ZeroMQ: How to scale your application
Redis & ZeroMQ: How to scale your application
 
LogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesomeLogStash - Yes, logging can be awesome
LogStash - Yes, logging can be awesome
 

Destacado

Destacado (15)

G* Workshop in Fukuoka - Introduction
G* Workshop in Fukuoka - IntroductionG* Workshop in Fukuoka - Introduction
G* Workshop in Fukuoka - Introduction
 
[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration[English version] JavaFX and Web Integration
[English version] JavaFX and Web Integration
 
JGGUG合宿2011報告
JGGUG合宿2011報告JGGUG合宿2011報告
JGGUG合宿2011報告
 
API Meetupのこれまでとこれから
API MeetupのこれまでとこれからAPI Meetupのこれまでとこれから
API Meetupのこれまでとこれから
 
シェアリングエコノミー推進に係る政府の取り組について(犬童周作)
シェアリングエコノミー推進に係る政府の取り組について(犬童周作)シェアリングエコノミー推進に係る政府の取り組について(犬童周作)
シェアリングエコノミー推進に係る政府の取り組について(犬童周作)
 
minikura API がもたらした“予想外”な価値・課題
minikura API がもたらした“予想外”な価値・課題minikura API がもたらした“予想外”な価値・課題
minikura API がもたらした“予想外”な価値・課題
 
Uberご紹介(髙橋正巳)
Uberご紹介(髙橋正巳)Uberご紹介(髙橋正巳)
Uberご紹介(髙橋正巳)
 
APIエコノミーの現状と今後の期待
APIエコノミーの現状と今後の期待APIエコノミーの現状と今後の期待
APIエコノミーの現状と今後の期待
 
Routeサービスを使ったCloud FoundryアプリのAPI管理
Routeサービスを使ったCloud FoundryアプリのAPI管理Routeサービスを使ったCloud FoundryアプリのAPI管理
Routeサービスを使ったCloud FoundryアプリのAPI管理
 
OpenAPI Specification概要
OpenAPI Specification概要OpenAPI Specification概要
OpenAPI Specification概要
 
Apigee+OASでらくらくAPI開発(予定)
Apigee+OASでらくらくAPI開発(予定)Apigee+OASでらくらくAPI開発(予定)
Apigee+OASでらくらくAPI開発(予定)
 
NHK Linked Data API 〜つながる番組データを目指して〜
NHK Linked Data API 〜つながる番組データを目指して〜NHK Linked Data API 〜つながる番組データを目指して〜
NHK Linked Data API 〜つながる番組データを目指して〜
 
[Azure Deep Dive] APIエコノミーに向けて ~Azure API ManagementによるAPIの公開と管理~ (2016/12/16)
[Azure Deep Dive] APIエコノミーに向けて ~Azure API ManagementによるAPIの公開と管理~ (2016/12/16)[Azure Deep Dive] APIエコノミーに向けて ~Azure API ManagementによるAPIの公開と管理~ (2016/12/16)
[Azure Deep Dive] APIエコノミーに向けて ~Azure API ManagementによるAPIの公開と管理~ (2016/12/16)
 
APIdays Australia 2017 TOI #APIdaysAU
APIdays Australia 2017 TOI #APIdaysAUAPIdays Australia 2017 TOI #APIdaysAU
APIdays Australia 2017 TOI #APIdaysAU
 
Introducing Ballerina
Introducing BallerinaIntroducing Ballerina
Introducing Ballerina
 

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

JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
Kiyotaka Oku
 
the next web now
the next web nowthe next web now
the next web now
zulin Gu
 
Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and Groovy
Kiyotaka Oku
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
Tino Isnich
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 

Similar a お題でGroovyプログラミング: Part A (20)

Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
Play!ng with scala
Play!ng with scalaPlay!ng with scala
Play!ng with scala
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
the next web now
the next web nowthe next web now
the next web now
 
Jenkins and Groovy
Jenkins and GroovyJenkins and Groovy
Jenkins and Groovy
 
前端概述
前端概述前端概述
前端概述
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
Presto anatomy
Presto anatomyPresto anatomy
Presto anatomy
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
PhpBB meets Symfony2
PhpBB meets Symfony2PhpBB meets Symfony2
PhpBB meets Symfony2
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Unfiltered Unveiled
Unfiltered UnveiledUnfiltered Unveiled
Unfiltered Unveiled
 
JS everywhere 2011
JS everywhere 2011JS everywhere 2011
JS everywhere 2011
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
REST with Eve and Python
REST with Eve and PythonREST with Eve and Python
REST with Eve and Python
 

Más de Kazuchika Sekiya

「プログラミングGroovy」発売予告
「プログラミングGroovy」発売予告「プログラミングGroovy」発売予告
「プログラミングGroovy」発売予告
Kazuchika Sekiya
 

Más de Kazuchika Sekiya (10)

10分でわかるOpenAPI V3
10分でわかるOpenAPI V310分でわかるOpenAPI V3
10分でわかるOpenAPI V3
 
Apigee x Drupal: APIエコノミーを支える開発者ポータル
Apigee x Drupal: APIエコノミーを支える開発者ポータルApigee x Drupal: APIエコノミーを支える開発者ポータル
Apigee x Drupal: APIエコノミーを支える開発者ポータル
 
[JavaOne Tokyo 2012] JavaFX and Web Integration
[JavaOne Tokyo 2012] JavaFX and Web Integration[JavaOne Tokyo 2012] JavaFX and Web Integration
[JavaOne Tokyo 2012] JavaFX and Web Integration
 
GroovyFX
GroovyFXGroovyFX
GroovyFX
 
GDK48
GDK48GDK48
GDK48
 
「プログラミングGroovy」発売予告
「プログラミングGroovy」発売予告「プログラミングGroovy」発売予告
「プログラミングGroovy」発売予告
 
「プログラミングGroovy」Groovyってなんだろ?編
「プログラミングGroovy」Groovyってなんだろ?編「プログラミングGroovy」Groovyってなんだろ?編
「プログラミングGroovy」Groovyってなんだろ?編
 
"G"はGrapeのG
"G"はGrapeのG"G"はGrapeのG
"G"はGrapeのG
 
GroovyなGAE/J Gaelykでかんたんbot工作
GroovyなGAE/J Gaelykでかんたんbot工作GroovyなGAE/J Gaelykでかんたんbot工作
GroovyなGAE/J Gaelykでかんたんbot工作
 
Groovy/Grails on Google App Engine <シンプル導入編>
Groovy/Grails on Google App Engine <シンプル導入編>Groovy/Grails on Google App Engine <シンプル導入編>
Groovy/Grails on Google App Engine <シンプル導入編>
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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

  • 1.
  • 2. ! !
  • 3. ! http://groups.google.com/group/jggug-summer-2009 ! ! jggug-summer-2009@googlegroups.com subject / ! !
  • 4. ! ! ! ! ! !
  • 5. ! ! JAVA_HOME GROOVY_HOME ! $GROOVY_HOME/bin ! % groovy -v Groovy Version: 1.6.4 JVM: 1.5.0_19
  • 6. ! ! ! ! – ! – ! –
  • 7.
  • 8. ! ! Input/OutputStream Reader/Writer % groovy filecopy <srcfile> <destfile>
  • 9. ! ! ! ! File#getText(), readBytes(), append(), leftShift()... ! ! String#execute() groovy.util.AntBuilder
  • 10. java.io.File src = new File(args[0]) dest = new File(args[1]) dest << src.text dest.leftShift(src.getText()) leftShift append GDK
  • 11. src = new File(args[0]) dest = new File(args[1]) dest << src.readBytes() OutOfMemoryError
  • 12. proc = "cp ${args[0]} ${args[1]}".execute() proc.waitFor() waitFor() cp OK UNIX cp
  • 13. ant = new AntBuilder() ant.copy(file:args[0], tofile:args[1]) Ant copy OK
  • 14. ! ! % groovy feedreader <URL>
  • 15. ! !
  • 16. <rdf:RDF> <channel> ... </channel> <item> <title>...</title> ... </item> <item> <title>...</title> ... </item> </rdf:RDF>
  • 17. <rss> <channel> ... <item> <title>...</title> ... </item> <item> <title>...</title> ... </item> </channel> </rss>
  • 18. <feed> ... <entry> <title>...</title> ... </entry> <entry> <title>...</title> ... </entry> </feed>
  • 19. 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 }
  • 20. ! ! % groovy -l 8080 httpserver
  • 21. ! -l <port> ! ! line ! return 'success'
  • 22. if (!line) { println 'HTTP/1.0 200 OK' println 'Content-Type: text/htmln' println new File('message.html').text return 'success' } If
  • 23. ! % groovy -l 8080 httpserver
  • 24. ! !
  • 25. 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' }
  • 26. ! ! ! http://ja.doukaku.org/205/ % groovy cmdopt <arguments...>
  • 27. 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'
  • 28. 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 }