JAR file access from NetRexx

classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

ThSITC
As far as I do remember, NetRexx *does NOT* support the FUNCTION oriented notation you quote, Mike Measel !

The notation you quoted is the classic Rexx/ooRexx notation only.

In Netrexx you'll have to use the Object oriented notation only !

That's the advantage of a Family: Every child does what it wants <grin>

Thomas
========================================================.

Am 10.05.2012 18:29, schrieb Measel, Mike:

The syntax on .pos(‘NetRexx’fs) is incorrect.  Pos(needle,haystack)  so you’re missing a comma.

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Thursday, May 10, 2012 10:57 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JAR file access from NetRexx

 


Thanks, Mike,

    That is exactly what I have done and I have the program running now. But it never finds a true condition on this if statement.

 if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je,setdir)




class ReadFromAJarFile
        properties inheritable static
                fs = System.getProperty("file.separator")
        myjar = String("frontend2.jar")
        setdir="output.directory"
        Debug_Level = int 6
method main(s=String[]) static
        ReadFromAJarFile(myjar)
       
method ReadFromAJarFile(Name_of_Jarfile=String)
        if Debug_Level > 5 then trace results
        do label get_next_entry
                jf = JarFile(Name_of_Jarfile)
                entries = jf.entries()
        loop while entries.hasMoreElements()
            je=JarEntry entries.nextElement()
            if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je,setdir)
-- another Java "gotcha": jar entries have unix file separators thus requireing the translate above
         end
             catch err=Exception
                 say "NetRexxScript.jar ==>" err
     end get_next_entry
return this




"Measel, Mike" [hidden email]
Sent by: [hidden email]

05/10/2012 10:58 AM

Please respond to
IBM Netrexx [hidden email]

To

IBM Netrexx [hidden email]

cc


Subject

Re: [Ibm-netrexx] JAR file access from NetRexx

 






Kenneth, take the “logic” out of your main.  You neeeed to understand static but we will save that for another day.
 
Change this:
 
method main(s=String[]) static
       do


to this:
 
class readFromAJarFile
   inputString = Rexx ‘empty’
 
method main(s=String[])
      inputString = s
     doSomething()
 
method doSomething
   
  /* move your logic here  */
/* inputString contains your arguments */
From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent:
Thursday, May 10, 2012 8:54 AM
To:
IBM Netrexx
Subject:
Re: [Ibm-netrexx] JAR file access from NetRexx

 

I'll take this offlist if someone cares to correspond with me directly.


Here you see clearly the level of my understanding after having read almost all of the available doc, and some of it a dozen times. The concept of "static" eludes my grasp.


I've taken KK's snippet and done with it what I think it needs to be executable as a simple example, but...


NetRexx portable processor, version NetRexx 3.01RC2, build 1-20110925-2337

Copyright (c) RexxLA, 2011.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ReadFromAJarFile.nrx

 === class ReadFromAJarFile ===

   function main(String[])

13 +++             if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je

,setdir)

   +++                                                                           ^^^^^^^^^^^^

   +++ Error: Cannot refer to a non-static method directly from a static instruction

   method copyjarentry(JarFile,JarEntry,String)

   method copyjarentrytofile(JarFile,JarEntry,File)

   method copyfile(BufferedReader,BufferedWriter)

   method copybin(InputStream,OutputStream)

Compilation of 'ReadFromAJarFile.nrx' failed [one error]



C:\Documents and Settings\keklein\REXX\NetRexx\bjcp6+  Thu 05/10/2012  9:31

> cat ReadFromAJarFile.nrx

class ReadFromAJarFile

       properties inheritable static

               fs = System.getProperty("file.separator")

       myjar = File("frontend2.jar")

       setdir="output.directory"

       df = int 1

method main(s=String[]) static

       do

               jf=JarFile(myjar)

       entries = jf.entries()

       loop while entries.hasMoreElements()

           je=JarEntry entries.nextElement()

           if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je,setdir


-- another Java "gotcha": jar entries have unix file separators thus requireing the translate above

        end

            catch err=Exception

                say "NetRexxScript.jar ==>" err

        end

-- Here is the nitty gritty code that makes it work. Probably not the best

-- way to do it but I used an unbuffered byte copy for my binary files and

-- buffered for the rest:

-- general purpose routines

-- method to copy a jarfile entry to a directory:

method copyjarentry(jf=JarFile,je=JarEntry,scriptdir=String)

    if df then trace results

    nrscript=scriptdir||fs||je.getName

    nrs=File(nrscript)

    if \nrs.exists then do

        rc=copyjarentrytofile(jf,je,nrs)

        if rc=1 then say je.getName "copied to:" scriptdir

        end


method copyjarentrytofile(jf=JarFile,je=JarEntry,nrs=File)

    if df then trace results

    do

        scriptstream=jf.getInputStream(je)

        if Rexx(je.getName).pos(".class")=0 then do

                scriptreader=BufferedReader(InputStreamReader(scriptstream))

            scriptwriter=BufferedWriter(FileWriter(nrs))

            copyfile(scriptreader,scriptwriter)

            scriptwriter.close

            end

        else do

            outstream=FileOutputStream(nrs)

            copybin(scriptstream,outstream)

            outstream.close

            end

        catch badguy=Exception

            say je.getName "copy error =" badguy

            return 0

        end

    return 1


/* methods to copy a file:   */


method copyfile(ifq=java.io.BufferedReader,ofq=java.io.BufferedWriter) signals IOException

    if df then trace results

    line=ifq.readline

    if line = null then return

    ofq.write(string line,0,line.length)

    trace off

  loop forever

    line=ifq.readline

    if line = null then leave

    ofq.newline()

    ofq.write(string line,0,line.length)

    end


method copybin(ifq=InputStream,ofq=OutputStream) binary signals IOException


    bite=ifq.read

  loop while bite \= -1

    ofq.write(bite)

    bite=ifq.read

    end



Kermit Kiser [hidden email]
Sent by: [hidden email]

05/10/2012 01:44 AM

 

Please respond to
IBM Netrexx [hidden email]

 

To

IBM Netrexx [hidden email]

cc


Subject

[Ibm-netrexx] JAR file access from NetRexx


 

 







This example of JAR file access was posted to the list about a year ago.
The code is extracted from the NetRexxScript.jar plugin for jEdit and
was designed to copy some binary and text files from "NetRexx"
sub-directories in a JAR file with correct translation of line end
characters for different systems.

It seems like this might be a good item for the new programer's guide.
Someone could rewrite it as a general example. If there is much
interest, I could be persuaded!

-- Kermit

Get a File object for the JAR and use it to create a JarFile object,
then you can read from it by creating a Stream from the JarEntry elements.

Here is a sample from code I used to process a JAR and copy some of the
files to a directory:

       fs = System.getProperty("file.separator")
       myjar = File("my.jar")
       setdir="output.directory"

       do
           jf=JarFile(myjar)
           entries = jf.entries()
           loop while entries.hasMoreElements()
               je=JarEntry entries.nextElement()
               if
Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then
copyjarentry(jf,je,setdir)
--    another Java "gotcha" - jar entries have unix file separators thus
requireing the translate above
               end
           catch err=Exception
               say "NetRexxScript.jar ==>" err
       end


Here is the nitty gritty code that makes it work. Probably not the best
way to do it but I used an unbuffered byte copy for my binary files and
buffered for the rest:

------------------------------------------------------ general purpose
routines -------------------------------------------------------

method copyjarentry(jf=JarFile,je=JarEntry,scriptdir=String)    --    
method to copy a jarfile entry to a directory
   if df then trace results
   nrscript=scriptdir||fs||je.getName
   nrs=File(nrscript)
   if \nrs.exists then do
       rc=copyjarentrytofile(jf,je,nrs)
       if rc=1 then say je.getName "copied to:" scriptdir
       end

method copyjarentrytofile(jf=JarFile,je=JarEntry,nrs=File)
   if df then trace results
   do
       scriptstream=jf.getInputStream(je)
       if Rexx(je.getName).pos(".class")=0 then do
               
scriptreader=BufferedReader(InputStreamReader(scriptstream))
               scriptwriter=BufferedWriter(FileWriter(nrs))
               copyfile(scriptreader,scriptwriter)
               scriptwriter.close
               end
           else do
               outstream=FileOutputStream(nrs)
               copybin(scriptstream,outstream)
               outstream.close
               end
       catch badguy=Exception
           say je.getName "copy error =" badguy
           return 0
       end
   return 1

/* methods to copy a file:   */

method copyfile(ifq=java.io.BufferedReader,ofq=java.io.BufferedWriter)
signals IOException
   if df then trace results
   line=ifq.readline
   if line = null then return
   ofq.write(string line,0,line.length)
   trace off
 loop forever
   line=ifq.readline
   if line = null then leave
   ofq.newline()
   ofq.write(string line,0,line.length)
   end

method copybin(ifq=InputStream,ofq=OutputStream) binary signals IOException

   bite=ifq.read
 loop while bite \= -1
   ofq.write(bite)
   bite=ifq.read
   end

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

christel.u.w.pachl christel.u.w.pachl
NO
the quote reads object.pos(argument) /' classic pos(argument,object) */
The other hint (suggesting the comma) was incorrect as someone explained already

---- Thomas Schneider <[hidden email]> schrieb:

> As far as I do remember, NetRexx *does NOT* support the FUNCTION
> oriented notation you quote, Mike Measel !
>
> The notation you quoted is the classic Rexx/ooRexx notation only.
>
> In Netrexx you'll have to use the Object oriented notation only !
>
> That's the advantage of a Family: Every child does what it wants <grin>
>
> Thomas
> ========================================================.
>
> Am 10.05.2012 18:29, schrieb Measel, Mike:
> >
> > The syntax on .pos('NetRexx'fs) is incorrect.  Pos(needle,haystack)  
> > so you're missing a comma.
> >
> > *From:*[hidden email]
> > [mailto:[hidden email]] *On Behalf Of
> > *[hidden email]
> > *Sent:* Thursday, May 10, 2012 10:57 AM
> > *To:* IBM Netrexx
> > *Subject:* Re: [Ibm-netrexx] JAR file access from NetRexx
> >
> >
> > Thanks, Mike,
> >
> >     That is exactly what I have done and I have the program running
> > now. But it never finds a true condition on this if statement.
> >
> >  if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then
> > copyjarentry(jf,je,setdir)
> >
> >
> >
> >
> > class ReadFromAJarFile
> >         properties inheritable static
> >                 fs = System.getProperty("file.separator")
> >         myjar = String("frontend2.jar")
> >         setdir="output.directory"
> >         Debug_Level = int 6
> > method main(s=String[]) static
> >         ReadFromAJarFile(myjar)
> >
> > method ReadFromAJarFile(Name_of_Jarfile=String)
> >         if Debug_Level > 5 then trace results
> >         do label get_next_entry
> >                 jf = JarFile(Name_of_Jarfile)
> >                 entries = jf.entries()
> >         loop while entries.hasMoreElements()
> >             je=JarEntry entries.nextElement()
> >             if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0
> > then copyjarentry(jf,je,setdir)
> > -- another Java "gotcha": jar entries have unix file separators thus
> > requireing the translate above
> >          end
> >              catch err=Exception
> >                  say "NetRexxScript.jar ==>" err
> >      end get_next_entry
> > return this
> >
> >
> >
> >
> > *"Measel, Mike" <[hidden email]>*
> > Sent by: [hidden email]
> >
> > 05/10/2012 10:58 AM
> >
> > Please respond to
> > IBM Netrexx <[hidden email]>
> >
> >
> >
> > To
> >
> >
> >
> > IBM Netrexx <[hidden email]>
> >
> > cc
> >
> >
> >
> > Subject
> >
> >
> >
> > Re: [Ibm-netrexx] JAR file access from NetRexx
> >
> >
> >
> >
> >
> >
> >
> > Kenneth, take the "logic" out of your main.  You neeeed to understand
> > static but we will save that for another day.
> >
> > Change this:
> >
> > method main(s=String[]) static
> >        do
> >
> > to this:
> >
> > class readFromAJarFile
> >    inputString = Rexx 'empty'
> >
> > method main(s=String[])
> >       inputString = s
> >      doSomething()
> >
> > method doSomething
> >
> >   /* move your logic here  */
> > /* inputString contains your arguments */
> > *From:*[hidden email]
> > [mailto:[hidden email]] *On Behalf Of
> > *[hidden email]*
> > Sent:* Thursday, May 10, 2012 8:54 AM*
> > To:* IBM Netrexx*
> > Subject:* Re: [Ibm-netrexx] JAR file access from NetRexx
> >
> >
> > I'll take this offlist if someone cares to correspond with me directly.
> >
> > Here you see clearly the level of my understanding after having read
> > almost all of the available doc, and some of it a dozen times. The
> > concept of "static" eludes my grasp.
> >
> > I've taken KK's snippet and done with it what I think it needs to be
> > executable as a simple example, but...
> >
> > NetRexx portable processor, version NetRexx 3.01RC2, build
> > 1-20110925-2337
> > Copyright (c) RexxLA, 2011.  All rights reserved.
> > Parts Copyright (c) IBM Corporation, 1995,2008.
> > Program ReadFromAJarFile.nrx
> >  === class ReadFromAJarFile ===
> >    function main(String[])
> > 13 +++             if
> > Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then
> > copyjarentry(jf,je
> > ,setdir)
> >    +++                                                                
> >           ^^^^^^^^^^^^
> >    +++ Error: Cannot refer to a non-static method directly from a
> > static instruction
> >    method copyjarentry(JarFile,JarEntry,String)
> >    method copyjarentrytofile(JarFile,JarEntry,File)
> >    method copyfile(BufferedReader,BufferedWriter)
> >    method copybin(InputStream,OutputStream)
> > Compilation of 'ReadFromAJarFile.nrx' failed [one error]
> >
> >
> > C:\Documents and Settings\keklein\REXX\NetRexx\bjcp6+  Thu 05/10/2012
> >  9:31
> > > cat ReadFromAJarFile.nrx
> > class ReadFromAJarFile
> >        properties inheritable static
> >                fs = System.getProperty("file.separator")
> >        myjar = File("frontend2.jar")
> >        setdir="output.directory"
> >        df = int 1
> > method main(s=String[]) static
> >        do
> >                jf=JarFile(myjar)
> >        entries = jf.entries()
> >        loop while entries.hasMoreElements()
> >            je=JarEntry entries.nextElement()
> >            if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0
> > then copyjarentry(jf,je,setdir
> >
> > -- another Java "gotcha": jar entries have unix file separators thus
> > requireing the translate above
> >         end
> >             catch err=Exception
> >                 say "NetRexxScript.jar ==>" err
> >         end
> > -- Here is the nitty gritty code that makes it work. Probably not the
> > best
> > -- way to do it but I used an unbuffered byte copy for my binary files
> > and
> > -- buffered for the rest:
> > -- general purpose routines
> > -- method to copy a jarfile entry to a directory:
> > method copyjarentry(jf=JarFile,je=JarEntry,scriptdir=String)
> >     if df then trace results
> >     nrscript=scriptdir||fs||je.getName
> >     nrs=File(nrscript)
> >     if \nrs.exists then do
> >         rc=copyjarentrytofile(jf,je,nrs)
> >         if rc=1 then say je.getName "copied to:" scriptdir
> >         end
> >
> > method copyjarentrytofile(jf=JarFile,je=JarEntry,nrs=File)
> >     if df then trace results
> >     do
> >         scriptstream=jf.getInputStream(je)
> >         if Rexx(je.getName).pos(".class")=0 then do
> >                
> > scriptreader=BufferedReader(InputStreamReader(scriptstream))
> >             scriptwriter=BufferedWriter(FileWriter(nrs))
> >             copyfile(scriptreader,scriptwriter)
> >             scriptwriter.close
> >             end
> >         else do
> >             outstream=FileOutputStream(nrs)
> >             copybin(scriptstream,outstream)
> >             outstream.close
> >             end
> >         catch badguy=Exception
> >             say je.getName "copy error =" badguy
> >             return 0
> >         end
> >     return 1
> >
> > /* methods to copy a file:   */
> >
> > method copyfile(ifq=java.io.BufferedReader,ofq=java.io.BufferedWriter)
> > signals IOException
> >     if df then trace results
> >     line=ifq.readline
> >     if line = null then return
> >     ofq.write(string line,0,line.length)
> >     trace off
> >   loop forever
> >     line=ifq.readline
> >     if line = null then leave
> >     ofq.newline()
> >     ofq.write(string line,0,line.length)
> >     end
> >
> > method copybin(ifq=InputStream,ofq=OutputStream) binary signals
> > IOException
> >
> >     bite=ifq.read
> >   loop while bite \= -1
> >     ofq.write(bite)
> >     bite=ifq.read
> >     end
> >
> >
> > *Kermit Kiser <[hidden email]>*
> > Sent by: [hidden email]
> >
> > 05/10/2012 01:44 AM
> >
> > Please respond to
> > IBM Netrexx <[hidden email]>
> >
> >
> >
> > To
> >
> >
> >
> > IBM Netrexx <[hidden email]>
> >
> > cc
> >
> >
> >
> > Subject
> >
> >
> >
> > [Ibm-netrexx] JAR file access from NetRexx
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > This example of JAR file access was posted to the list about a year ago.
> > The code is extracted from the NetRexxScript.jar plugin for jEdit and
> > was designed to copy some binary and text files from "NetRexx"
> > sub-directories in a JAR file with correct translation of line end
> > characters for different systems.
> >
> > It seems like this might be a good item for the new programer's guide.
> > Someone could rewrite it as a general example. If there is much
> > interest, I could be persuaded!
> >
> > -- Kermit
> >
> > Get a File object for the JAR and use it to create a JarFile object,
> > then you can read from it by creating a Stream from the JarEntry elements.
> >
> > Here is a sample from code I used to process a JAR and copy some of the
> > files to a directory:
> >
> >        fs = System.getProperty("file.separator")
> >        myjar = File("my.jar")
> >        setdir="output.directory"
> >
> >        do
> >            jf=JarFile(myjar)
> >            entries = jf.entries()
> >            loop while entries.hasMoreElements()
> >                je=JarEntry entries.nextElement()
> >                if
> > Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then
> > copyjarentry(jf,je,setdir)
> > --    another Java "gotcha" - jar entries have unix file separators thus
> > requireing the translate above
> >                end
> >            catch err=Exception
> >                say "NetRexxScript.jar ==>" err
> >        end
> >
> >
> > Here is the nitty gritty code that makes it work. Probably not the best
> > way to do it but I used an unbuffered byte copy for my binary files and
> > buffered for the rest:
> >
> > ------------------------------------------------------ general purpose
> > routines -------------------------------------------------------
> >
> > method copyjarentry(jf=JarFile,je=JarEntry,scriptdir=String)    --
> > method to copy a jarfile entry to a directory
> >    if df then trace results
> >    nrscript=scriptdir||fs||je.getName
> >    nrs=File(nrscript)
> >    if \nrs.exists then do
> >        rc=copyjarentrytofile(jf,je,nrs)
> >        if rc=1 then say je.getName "copied to:" scriptdir
> >        end
> >
> > method copyjarentrytofile(jf=JarFile,je=JarEntry,nrs=File)
> >    if df then trace results
> >    do
> >        scriptstream=jf.getInputStream(je)
> >        if Rexx(je.getName).pos(".class")=0 then do
> >
> > scriptreader=BufferedReader(InputStreamReader(scriptstream))
> >                scriptwriter=BufferedWriter(FileWriter(nrs))
> >                copyfile(scriptreader,scriptwriter)
> >                scriptwriter.close
> >                end
> >            else do
> >                outstream=FileOutputStream(nrs)
> >                copybin(scriptstream,outstream)
> >                outstream.close
> >                end
> >        catch badguy=Exception
> >            say je.getName "copy error =" badguy
> >            return 0
> >        end
> >    return 1
> >
> > /* methods to copy a file:   */
> >
> > method copyfile(ifq=java.io.BufferedReader,ofq=java.io.BufferedWriter)
> > signals IOException
> >    if df then trace results
> >    line=ifq.readline
> >    if line = null then return
> >    ofq.write(string line,0,line.length)
> >    trace off
> >  loop forever
> >    line=ifq.readline
> >    if line = null then leave
> >    ofq.newline()
> >    ofq.write(string line,0,line.length)
> >    end
> >
> > method copybin(ifq=InputStream,ofq=OutputStream) binary signals
> > IOException
> >
> >    bite=ifq.read
> >  loop while bite \= -1
> >    ofq.write(bite)
> >    bite=ifq.read
> >    end
> >
> > _______________________________________________
> > Ibm-netrexx mailing list
> > [hidden email]
> > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> > _______________________________________________
> > Ibm-netrexx mailing list
> > [hidden email]
> > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> >
> >
> >
> > _______________________________________________
> > Ibm-netrexx mailing list
> > [hidden email]
> > Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
> >
>
>
> --
> Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge
> Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team
> (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

measel
In reply to this post by ThSITC

In this family metaphor, you’d be the crazy uncle I suppose. 

 

 

Mike (n = n + 1) Measel

 

From: Thomas Schneider [mailto:[hidden email]]
Sent: Friday, May 11, 2012 12:35 AM
To: IBM Netrexx
Cc: Measel, Mike
Subject: Re: [Ibm-netrexx] JAR file access from NetRexx

 

As far as I do remember, NetRexx *does NOT* support the FUNCTION oriented notation you quote, Mike Measel !

The notation you quoted is the classic Rexx/ooRexx notation only.

In Netrexx you'll have to use the Object oriented notation only !

That's the advantage of a Family: Every child does what it wants <grin>

Thomas
========================================================.

Am 10.05.2012 18:29, schrieb Measel, Mike:

The syntax on .pos(‘NetRexx’fs) is incorrect.  Pos(needle,haystack)  so you’re missing a comma.

 

From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent: Thursday, May 10, 2012 10:57 AM
To: IBM Netrexx
Subject: Re: [Ibm-netrexx] JAR file access from NetRexx

 


Thanks, Mike,

    That is exactly what I have done and I have the program running now. But it never finds a true condition on this if statement.

 if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je,setdir)




class ReadFromAJarFile
        properties inheritable static
                fs = System.getProperty("file.separator")
        myjar = String("frontend2.jar")
        setdir="output.directory"
        Debug_Level = int 6
method main(s=String[]) static
        ReadFromAJarFile(myjar)
       
method ReadFromAJarFile(Name_of_Jarfile=String)
        if Debug_Level > 5 then trace results
        do label get_next_entry
                jf = JarFile(Name_of_Jarfile)
                entries = jf.entries()
        loop while entries.hasMoreElements()
            je=JarEntry entries.nextElement()
            if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je,setdir)
-- another Java "gotcha": jar entries have unix file separators thus requireing the translate above
         end
             catch err=Exception
                 say "NetRexxScript.jar ==>" err
     end get_next_entry
return this





"Measel, Mike" [hidden email]
Sent by: [hidden email]

05/10/2012 10:58 AM

Please respond to
IBM Netrexx [hidden email]

To

IBM Netrexx [hidden email]

cc

Subject

Re: [Ibm-netrexx] JAR file access from NetRexx

 




Kenneth, take the “logic” out of your main.  You neeeed to understand static but we will save that for another day.
 
Change this:
 
method main(s=String[]) static
       do


to this:
 
class readFromAJarFile
   inputString = Rexx ‘empty’
 
method main(s=String[])
      inputString = s
     doSomething()
 
method doSomething
   
  /* move your logic here  */
/* inputString contains your arguments */
From: [hidden email] [[hidden email]] On Behalf Of [hidden email]
Sent:
Thursday, May 10, 2012 8:54 AM
To:
IBM Netrexx
Subject:
Re: [Ibm-netrexx] JAR file access from NetRexx

 

I'll take this offlist if someone cares to correspond with me directly.


Here you see clearly the level of my understanding after having read almost all of the available doc, and some of it a dozen times. The concept of "static" eludes my grasp.


I've taken KK's snippet and done with it what I think it needs to be executable as a simple example, but...


NetRexx portable processor, version NetRexx 3.01RC2, build 1-20110925-2337

Copyright (c) RexxLA, 2011.  All rights reserved.

Parts Copyright (c) IBM Corporation, 1995,2008.

Program ReadFromAJarFile.nrx

 === class ReadFromAJarFile ===

   function main(String[])

13 +++             if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je

,setdir)

   +++                                                                           ^^^^^^^^^^^^

   +++ Error: Cannot refer to a non-static method directly from a static instruction

   method copyjarentry(JarFile,JarEntry,String)

   method copyjarentrytofile(JarFile,JarEntry,File)

   method copyfile(BufferedReader,BufferedWriter)

   method copybin(InputStream,OutputStream)

Compilation of 'ReadFromAJarFile.nrx' failed [one error]



C:\Documents and Settings\keklein\REXX\NetRexx\bjcp6+  Thu 05/10/2012  9:31

> cat ReadFromAJarFile.nrx

class ReadFromAJarFile

       properties inheritable static

               fs = System.getProperty("file.separator")

       myjar = File("frontend2.jar")

       setdir="output.directory"

       df = int 1

method main(s=String[]) static

       do

               jf=JarFile(myjar)

       entries = jf.entries()

       loop while entries.hasMoreElements()

           je=JarEntry entries.nextElement()

           if Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then copyjarentry(jf,je,setdir


-- another Java "gotcha": jar entries have unix file separators thus requireing the translate above

        end

            catch err=Exception

                say "NetRexxScript.jar ==>" err

        end

-- Here is the nitty gritty code that makes it work. Probably not the best

-- way to do it but I used an unbuffered byte copy for my binary files and

-- buffered for the rest:

-- general purpose routines

-- method to copy a jarfile entry to a directory:

method copyjarentry(jf=JarFile,je=JarEntry,scriptdir=String)

    if df then trace results

    nrscript=scriptdir||fs||je.getName

    nrs=File(nrscript)

    if \nrs.exists then do

        rc=copyjarentrytofile(jf,je,nrs)

        if rc=1 then say je.getName "copied to:" scriptdir

        end


method copyjarentrytofile(jf=JarFile,je=JarEntry,nrs=File)

    if df then trace results

    do

        scriptstream=jf.getInputStream(je)

        if Rexx(je.getName).pos(".class")=0 then do

                scriptreader=BufferedReader(InputStreamReader(scriptstream))

            scriptwriter=BufferedWriter(FileWriter(nrs))

            copyfile(scriptreader,scriptwriter)

            scriptwriter.close

            end

        else do

            outstream=FileOutputStream(nrs)

            copybin(scriptstream,outstream)

            outstream.close

            end

        catch badguy=Exception

            say je.getName "copy error =" badguy

            return 0

        end

    return 1


/* methods to copy a file:   */


method copyfile(ifq=java.io.BufferedReader,ofq=java.io.BufferedWriter) signals IOException

    if df then trace results

    line=ifq.readline

    if line = null then return

    ofq.write(string line,0,line.length)

    trace off

  loop forever

    line=ifq.readline

    if line = null then leave

    ofq.newline()

    ofq.write(string line,0,line.length)

    end


method copybin(ifq=InputStream,ofq=OutputStream) binary signals IOException


    bite=ifq.read

  loop while bite \= -1

    ofq.write(bite)

    bite=ifq.read

    end




Kermit Kiser [hidden email]
Sent by: [hidden email]

05/10/2012 01:44 AM

 

Please respond to
IBM Netrexx [hidden email]

 

To

IBM Netrexx [hidden email]

cc

Subject

[Ibm-netrexx] JAR file access from NetRexx


 

 





This example of JAR file access was posted to the list about a year ago.
The code is extracted from the NetRexxScript.jar plugin for jEdit and
was designed to copy some binary and text files from "NetRexx"
sub-directories in a JAR file with correct translation of line end
characters for different systems.

It seems like this might be a good item for the new programer's guide.
Someone could rewrite it as a general example. If there is much
interest, I could be persuaded!

-- Kermit

Get a File object for the JAR and use it to create a JarFile object,
then you can read from it by creating a Stream from the JarEntry elements.

Here is a sample from code I used to process a JAR and copy some of the
files to a directory:

       fs = System.getProperty("file.separator")
       myjar = File("my.jar")
       setdir="output.directory"

       do
           jf=JarFile(myjar)
           entries = jf.entries()
           loop while entries.hasMoreElements()
               je=JarEntry entries.nextElement()
               if
Rexx(je.getName).translate(fs,'/').pos('NetRexx'fs)>0 then
copyjarentry(jf,je,setdir)
--    another Java "gotcha" - jar entries have unix file separators thus
requireing the translate above
               end
           catch err=Exception
               say "NetRexxScript.jar ==>" err
       end


Here is the nitty gritty code that makes it work. Probably not the best
way to do it but I used an unbuffered byte copy for my binary files and
buffered for the rest:

------------------------------------------------------ general purpose
routines -------------------------------------------------------

method copyjarentry(jf=JarFile,je=JarEntry,scriptdir=String)    --    
method to copy a jarfile entry to a directory
   if df then trace results
   nrscript=scriptdir||fs||je.getName
   nrs=File(nrscript)
   if \nrs.exists then do
       rc=copyjarentrytofile(jf,je,nrs)
       if rc=1 then say je.getName "copied to:" scriptdir
       end

method copyjarentrytofile(jf=JarFile,je=JarEntry,nrs=File)
   if df then trace results
   do
       scriptstream=jf.getInputStream(je)
       if Rexx(je.getName).pos(".class")=0 then do
               
scriptreader=BufferedReader(InputStreamReader(scriptstream))
               scriptwriter=BufferedWriter(FileWriter(nrs))
               copyfile(scriptreader,scriptwriter)
               scriptwriter.close
               end
           else do
               outstream=FileOutputStream(nrs)
               copybin(scriptstream,outstream)
               outstream.close
               end
       catch badguy=Exception
           say je.getName "copy error =" badguy
           return 0
       end
   return 1

/* methods to copy a file:   */

method copyfile(ifq=java.io.BufferedReader,ofq=java.io.BufferedWriter)
signals IOException
   if df then trace results
   line=ifq.readline
   if line = null then return
   ofq.write(string line,0,line.length)
   trace off
 loop forever
   line=ifq.readline
   if line = null then leave
   ofq.newline()
   ofq.write(string line,0,line.length)
   end

method copybin(ifq=InputStream,ofq=OutputStream) binary signals IOException

   bite=ifq.read
 loop while bite \= -1
   ofq.write(bite)
   bite=ifq.read
   end

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/





_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
 

 

--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org)


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

kenner
In reply to this post by Jeff Hennick

Alan, yes - his code was looking for  that string. My new code looks for the .txt files I have in the jar.

Mike, yes, that was a failing point.
Jeff, no, the variable was set up in properties and not included in the trace, but the trace output shows that it is the backslash "\".

 20 *=*             if Rexx( My_JarFile_Entry.getName ).translate( My_File_Separator, '/').pos('NetR
exx', My_File_Separator)>0

   >>> "META-INF/"

   >>> "\"
    <--- that one!
   >>> "/"

   >>> "NetRexx"

   >>> "\"


I now have the code selecting only files that end in ".txt" in the current directory and copying them to my new sub dir.

method ReadFromAJarFile(NameOfJarfile=String)
        if Debug_Level > 5 then trace all
        if Debug_Level > 9 then trace results
        do label get_next_entry
                My_JarFile_Object = JarFile(NameOfJarfile)
                My_Entries =  My_JarFile_Object.entries()
        loop while My_Entries.hasMoreElements()
             My_JarFile_Entry=JarEntry My_Entries.nextElement()
            if  (Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos('.txt') > 0 & -

                 Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(My_File_Separat
or) = 0) then do
                copyjarentry( My_JarFile_Object, My_JarFile_Entry,setdir)
            end
-- another Java "gotcha": jar entries have unix file separators thus requiring the translate above
         end
             catch err=Exception
                  say "Exception error ==>" err
     end get_next_entry
return this


Kenneth Klein



Jeff Hennick <[hidden email]>
Sent by: [hidden email]

05/10/2012 03:29 PM

Please respond to
IBM Netrexx <[hidden email]>

To
IBM Netrexx <[hidden email]>
cc
Subject
Re: [Ibm-netrexx] JAR file access from NetRexx





My_File_Separator is not defined.

On 5/10/2012 3:20 PM,
kenneth.klein@... wrote:

Let me know if I am wasting bandwidth with questions I should figure out on my own but I'm stuck on this piece now:


> java ReadFromAJarFile

   --- ReadFromAJarFile.nrx

 9 *=*  if Debug_Level > 9

   *=*                     then

   *=*                          trace results

10 *=*  ReadFromAJarFile(myjar)

11 *-*

10 >>> "frontend2.jar"

14 *=*  if Debug_Level > 9

   *=*                     then

   *=*                          trace results

15 *=*  do label get_next_entry

16 *=*   My_JarFile_Object = JarFile(NameOfJarfile)

   >>> "frontend2.jar"

   >v> My_JarFile_Object "java.util.jar.JarFile@ca0b6"

17 *=*   My_Entries =  My_JarFile_Object.entries()

   >v> My_Entries "java.util.jar.JarFile$1@10b30a7"

18 *=*         loop while My_Entries.hasMoreElements()

   >>> "1"

19 *=*              My_JarFile_Entry=JarEntry My_Entries.nextElement()

   >v> My_JarFile_Entry "META-INF/"

20 *=*             if Rexx( My_JarFile_Entry.getName ).translate( My_File_Separator, '/').pos('NetR

exx', My_File_Separator)>0

   >>> "META-INF/"

   >>> "\"

   >>> "/"

   >>> "NetRexx"

   >>> "\"

23 *=*              catch err=Exception

24 *=*                   say "Exception error ==>" err

   >>> "Exception error ==> java.lang.NumberFormatException: Not a number"

Exception error ==> java.lang.NumberFormatException: Not a number

25 *=*      end get_next_entry

26 *=* return this


I guess I just don't know what line 20 is trying to do, outside of translating the / to a  \. Seems to me it is looking for the string 'netrexx' (needle) in the file separator (haystack) ????




Kenneth Klein

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

Jeff Hennick
Great!

Now my contribution is to make it more generalized (in a way that would have eliminated some of the confusion too, I hope).  That is to make the [partial] filename(s) to be looked for a parameter of the method.  As 

method ReadFromAJarFile(PartNameOfFile=String, NameOfJarfile=String)
        if Debug_Level > 0 then do
                if Debug_Level > 5 then trace all
                if Debug_Level > 9 then trace results
                if Debug_Level > 99 then trace off
        end
        do label get_next_entry
                My_JarFile_Object = JarFile(NameOfJarfile)
                My_Entries =  My_JarFile_Object.entries()
        loop while My_Entries.hasMoreElements()
             My_JarFile_Entry=JarEntry My_Entries.nextElement()
            if  (Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(Part
NameOfFile) > 0 & -

                 Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(My_File_Separat
or) = 0) then do

                copyjarentry( My_JarFile_Object, My_JarFile_Entry,setdir)
            end
-- another Java "gotcha": jar entries have unix file separators thus requiring the translate above

         end
             catch err=Exception
                  say "Exception error ==>" err
     end get_next_entry
return this


I put the order PartNameOfFile, NameOfJarfile following Rexx's Pos(needle, haystack) notation.

I also added if Debug_Level > 0 then do ... end around the traces in the event it is not defined and to cover the collating order of various implementations. (I think I have that right, but have not tested it.)

On 5/11/2012 9:08 AM, [hidden email] wrote:

Alan, yes - his code was looking for  that string. My new code looks for the .txt files I have in the jar.

Mike, yes, that was a failing point.
Jeff, no, the variable was set up in properties and not included in the trace, but the trace output shows that it is the backslash "\".

 20 *=*             if Rexx( My_JarFile_Entry.getName ).translate( My_File_Separator, '/').pos('NetR
exx', My_File_Separator)>0

   >>> "META-INF/"

   >>> "\"
    <--- that one!
   >>> "/"

   >>> "NetRexx"

   >>> "\"


I now have the code selecting only files that end in ".txt" in the current directory and copying them to my new sub dir.

method ReadFromAJarFile(NameOfJarfile=String)
        if Debug_Level > 5 then trace all
        if Debug_Level > 9 then trace results
        do label get_next_entry
                My_JarFile_Object = JarFile(NameOfJarfile)
                My_Entries =  My_JarFile_Object.entries()
        loop while My_Entries.hasMoreElements()
             My_JarFile_Entry=JarEntry My_Entries.nextElement()
            if  (Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos('.txt') > 0 & -

                 Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(My_File_Separat
or) = 0) then do
                copyjarentry( My_JarFile_Object, My_JarFile_Entry,setdir)
            end
-- another Java "gotcha": jar entries have unix file separators thus requiring the translate above
         end
             catch err=Exception
                  say "Exception error ==>" err
     end get_next_entry
return this


Kenneth Klein


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

kenner

class ReadFromAJarFile
        properties inheritable static
                My_File_Separator = System.getProperty("file.separator")
        Debug_Level = int 60
method main(s=String[]) static        
        if Debug_Level > 5 then trace all
        if Debug_Level > 9 then trace results
        ReadFromAJarFile('frontend2.jar','txt')        -- sub dirs are set up for .txt and .class files

method ReadFromAJarFile(NameOfJarfile=String,Name_of_Type=string)
-- This method receives the name of the jar file, looks at names of files in it and sends some names to  be copied
        if Debug_Level > 5 then trace all
        if Debug_Level > 9 then trace results
-- Here we pick out all the files in the jar that contain the type we are seeking and are not in a subdirectory
        do label get_next_entry
                My_JarFile_Object = JarFile(NameOfJarfile)
                My_Entry_List =  My_JarFile_Object.entries()
        loop while My_Entry_List.hasMoreElements()
            My_JarFile_Entry=JarEntry My_Entry_List.nextElement()
            if Debug_Level > 5 then say "This files name = " My_JarFile_Entry.getName
            if         (Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos('.'||Name_of_Type) > 0 & -
                     Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(My_File_Separator) = 0) then do
                    copyjarentry(My_JarFile_Object,My_JarFile_Entry,Name_of_Type||'_files')
            end
-- another Java "gotcha": jar entries have unix file separators thus requiring the translate above
         end
             catch err=Exception
                  say "Exception error ==>" err
     end get_next_entry
return this
-- Here is the nitty gritty code that makes it work. Probably not the best
-- way to do it but I used an unbuffered byte copy for my binary files and
-- buffered for the rest:
-- general purpose routines
-- method to copy a jarfile entry to a directory:
method copyjarentry(My_JarFile_Object=JarFile,My_JarFile_Entry=JarEntry,To_Subdir=String)
     if Debug_Level > 5 then trace all
         if Debug_Level > 9 then trace results
-- receives the jarfile object, the entry name in process and the directory to put it into.
         Full_Path_and_Name=To_Subdir|| My_File_Separator|| My_JarFile_Entry.getName
     File_Object=File(Full_Path_and_Name)
     if Debug_Level > 5 then say "Full_Path_and_Name = " Full_Path_and_Name "File_Object = " File_Object
-- check if file exists already and only copy if it is not there yet
     if \File_Object.exists then do label File_Object_Exists
         rc=copyjarentrytofile(My_JarFile_Object,My_JarFile_Entry,File_Object)
         if rc=1 then say My_JarFile_Entry.getName "copied to:" To_Subdir
         end File_Object_Exists
     return 0

method copyjarentrytofile(My_JarFile_Object=JarFile,My_JarFile_Entry=JarEntry,File_Object=File)
     if Debug_Level > 5 then trace all
         if Debug_Level > 9 then trace results
-- receives the jarfile object, the entry name and a "File Object"
     do label copy_scripts
-- create the input stream for the particular entry in the jar file
         Input_Stream = My_JarFile_Object.getInputStream(My_JarFile_Entry)
         if Rexx(My_JarFile_Entry.getName).pos(".txt")>0 then do              
                  Input_Reader=BufferedReader(InputStreamReader(Input_Stream))
             Output_Writer=BufferedWriter(FileWriter(File_Object))
             copyfile(Input_Reader,Output_Writer)
             Output_Writer.close
             end
         else
         if Rexx(My_JarFile_Entry.getName).pos(".class")>0 then do
             Output_Stream=FileOutputStream(File_Object)
             copybin(Input_Stream,Output_Stream)
             Output_Stream.close
             end
                 catch badguy=Exception
                         say  My_JarFile_Entry.getName "copy error =" badguy
                         return 8
     end copy_scripts
return 0

/* methods to copy a file:   */

method copyfile(Buffed_Reader=java.io.BufferedReader,Buffed_Writer=java.io.BufferedWriter) signals IOException
        if Debug_Level > 5 then trace all
        if Debug_Level > 9 then trace results
    line=Buffed_Reader.readline
    if line = null then return 4
    Buffed_Writer.write(string line,0,line.length)
    trace off
    loop forever
        line=Buffed_Reader.readline
        if line = null then leave
        Buffed_Writer.newline()
        Buffed_Writer.write(string line,0,line.length)
        catch IO_Err=Exception
             say "copy error =" IO_Err
             return 8
        end
    return 0

method copybin(Byte_Input=InputStream,Byte_Writer=OutputStream) binary signals IOException
        if Debug_Level > 5 then trace all
        if Debug_Level > 9 then trace results
    A_Byte=Byte_Input.read
    trace off
    loop while A_Byte \= -1
            Byte_Writer.write(A_Byte)
            A_Byte=Byte_Input.read
                catch IO_Err=Exception
                        say "copy error =" IO_Err
                        return 8
    end
    return 0


Kenneth Klein

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

christel.u.w.pachl christel.u.w.pachl
Thank you for the complete program!
That saves the weekend

I had to add a string to the final return to make it compile correctly

It also works but I have to find out what it really does :-)
Walter

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Rosettacode

christel.u.w.pachl christel.u.w.pachl
In reply to this post by kenner

Fooling around with NetRexx (what ele can a fool do?) I found these:

nrc RCAbstractType compiles correctly
java RCAbstractType executes correctly
nrc RCAbstractType -exec    ends with al load (huge chain) of errors

There is no OoRexx solution to this task

RCLoopsContinue.nrx does not exactly solve the task, neither does PL/I, (I think, untested)

Interesting?
Spam??

Walter

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Rosettacode

ThSITC
*NO spam, Walter* :-)

I personally did always like *your style of testing*, and also the
*feedback* you are giving (very concise!).

My personal thanks:-)
Hope that the other members of this group do agree ;-)
Thomas.
======================================================
Am 13.05.2012 08:33, schrieb Walter Pachl:

> Fooling around with NetRexx (what ele can a fool do?) I found these:
>
> nrc RCAbstractType compiles correctly
> java RCAbstractType executes correctly
> nrc RCAbstractType -exec    ends with al load (huge chain) of errors
>
> There is no OoRexx solution to this task
>
> RCLoopsContinue.nrx does not exactly solve the task, neither does PL/I, (I think, untested)
>
> Interesting?
> Spam??
>
> Walter
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>
>


--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge
Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team
(www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
Reply | Threaded
Open this post in threaded view
|

Re: Rosettacode

rvjansen
In reply to this post by christel.u.w.pachl christel.u.w.pachl
Hi Walter,

you have found something that is either a bug, or a limitation of interpretative execution. Thank you for reporting it. I will enter an issue in our bug tracker.

best regards,

René.

On 13 mei 2012, at 02:33, Walter Pachl wrote:

>
> Fooling around with NetRexx (what ele can a fool do?) I found these:
>
> nrc RCAbstractType compiles correctly
> java RCAbstractType executes correctly
> nrc RCAbstractType -exec    ends with al load (huge chain) of errors
>
> There is no OoRexx solution to this task
>
> RCLoopsContinue.nrx does not exactly solve the task, neither does PL/I, (I think, untested)
>
> Interesting?
> Spam??
>
> Walter
>
> _______________________________________________
> Ibm-netrexx mailing list
> [hidden email]
> Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
>

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

kenner
In reply to this post by kenner

So should I be comfortable with using the jarfile, jarentry, getname and getnextentry like I did in my simple example in my last post (from the source snippet Kermit supplied), or should I look further into the getResourceasStream (as rvjansen supplied) approach?


Kenneth Klein



[hidden email]
Sent by: [hidden email]

05/11/2012 04:25 PM

Please respond to
IBM Netrexx <[hidden email]>

To
IBM Netrexx <[hidden email]>
cc
Subject
Re: [Ibm-netrexx] JAR file access from NetRexx






class ReadFromAJarFile

       properties inheritable static

               My_File_Separator = System.getProperty("file.separator")

       Debug_Level = int 60

method main(s=String[]) static        

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

       ReadFromAJarFile('frontend2.jar','txt')        -- sub dirs are set up for .txt and .class files


method ReadFromAJarFile(NameOfJarfile=String,Name_of_Type=string)

-- This method receives the name of the jar file, looks at names of files in it and sends some names to  be copied

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

-- Here we pick out all the files in the jar that contain the type we are seeking and are not in a subdirectory

       do label get_next_entry

               My_JarFile_Object = JarFile(NameOfJarfile)

               My_Entry_List =  My_JarFile_Object.entries()

       loop while My_Entry_List.hasMoreElements()

           My_JarFile_Entry=JarEntry My_Entry_List.nextElement()

           if Debug_Level > 5 then say "This files name = " My_JarFile_Entry.getName
           if         (Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos('.'||Name_of_Type) > 0 & -

                    Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(My_File_Separator) = 0) then do

                   copyjarentry(My_JarFile_Object,My_JarFile_Entry,Name_of_Type||'_files')

           end

-- another Java "gotcha": jar entries have unix file separators thus requiring the translate above

        end

            catch err=Exception

                 say "Exception error ==>" err

    end get_next_entry

return this

-- Here is the nitty gritty code that makes it work. Probably not the best
-- way to do it but I used an unbuffered byte copy for my binary files and
-- buffered for the rest:

-- general purpose routines

-- method to copy a jarfile entry to a directory:

method copyjarentry(My_JarFile_Object=JarFile,My_JarFile_Entry=JarEntry,To_Subdir=String)

    if Debug_Level > 5 then trace all

        if Debug_Level > 9 then trace results

-- receives the jarfile object, the entry name in process and the directory to put it into.

        Full_Path_and_Name=To_Subdir|| My_File_Separator|| My_JarFile_Entry.getName

    File_Object=File(Full_Path_and_Name)

    if Debug_Level > 5 then say "Full_Path_and_Name = " Full_Path_and_Name "File_Object = " File_Object

-- check if file exists already and only copy if it is not there yet

    if \File_Object.exists then do label File_Object_Exists

        rc=copyjarentrytofile(My_JarFile_Object,My_JarFile_Entry,File_Object)

        if rc=1 then say My_JarFile_Entry.getName "copied to:" To_Subdir

        end File_Object_Exists

    return 0


method copyjarentrytofile(My_JarFile_Object=JarFile,My_JarFile_Entry=JarEntry,File_Object=File)

    if Debug_Level > 5 then trace all

        if Debug_Level > 9 then trace results

-- receives the jarfile object, the entry name and a "File Object"

    do label copy_scripts

-- create the input stream for the particular entry in the jar file

        Input_Stream = My_JarFile_Object.getInputStream(My_JarFile_Entry)

        if Rexx(My_JarFile_Entry.getName).pos(".txt")>0 then do              

                 Input_Reader=BufferedReader(InputStreamReader(Input_Stream))

            Output_Writer=BufferedWriter(FileWriter(File_Object))

            copyfile(Input_Reader,Output_Writer)

            Output_Writer.close

            end

        else

        if Rexx(My_JarFile_Entry.getName).pos(".class")>0 then do

            Output_Stream=FileOutputStream(File_Object)

            copybin(Input_Stream,Output_Stream)

            Output_Stream.close

            end

                catch badguy=Exception

                        say  My_JarFile_Entry.getName "copy error =" badguy

                        return 8

    end copy_scripts

return 0


/* methods to copy a file:   */


method copyfile(Buffed_Reader=java.io.BufferedReader,Buffed_Writer=java.io.BufferedWriter) signals IOException

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

   line=Buffed_Reader.readline

   if line = null then return 4

   Buffed_Writer.write(string line,0,line.length)

   trace off

   loop forever

       line=Buffed_Reader.readline

       if line = null then leave

       Buffed_Writer.newline()

       Buffed_Writer.write(string line,0,line.length)

       catch IO_Err=Exception

            say "copy error =" IO_Err

            return 8

       end

   return 0


method copybin(Byte_Input=InputStream,Byte_Writer=OutputStream) binary signals IOException

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

   A_Byte=Byte_Input.read

   trace off

   loop while A_Byte \= -1

           Byte_Writer.write(A_Byte)

           A_Byte=Byte_Input.read

               catch IO_Err=Exception

                       say "copy error =" IO_Err

                       return 8

   end

   return 0



Kenneth Klein
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: JAR file access from NetRexx

ThSITC
Kenneth,

   as far as *I* did understand those concepts, you should  use 'getResourceasStream' for reading a so called resource-file (which is
actually a named ordinary line-sequential file in your JAR-library) ...

   .. . and the other way round when you are reading classes and/or
other entries in your Jar-Fle.

I (personally) use this decision, at least, as I'm also using .JAR files
to ZIP my sources, and resource files, thus beeing able to use the
same utilities, with a Manifest file, as well, for all distributions and
operating systems... :-)

Others in this group: Please correct me when i did say somethng wrong!

Thomas.
========================================================
Am 15.05.2012 21:27, schrieb [hidden email]:

So should I be comfortable with using the jarfile, jarentry, getname and getnextentry like I did in my simple example in my last post (from the source snippet Kermit supplied), or should I look further into the getResourceasStream (as rvjansen supplied) approach?


Kenneth Klein



[hidden email]
Sent by: [hidden email]

05/11/2012 04:25 PM

Please respond to
IBM Netrexx [hidden email]

To
IBM Netrexx [hidden email]
cc

Subject
Re: [Ibm-netrexx] JAR file access from NetRexx








class ReadFromAJarFile

       properties inheritable static

               My_File_Separator = System.getProperty("file.separator")

       Debug_Level = int 60

method main(s=String[]) static        

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

       ReadFromAJarFile('frontend2.jar','txt')        -- sub dirs are set up for .txt and .class files


method ReadFromAJarFile(NameOfJarfile=String,Name_of_Type=string)

-- This method receives the name of the jar file, looks at names of files in it and sends some names to  be copied

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

-- Here we pick out all the files in the jar that contain the type we are seeking and are not in a subdirectory

       do label get_next_entry

               My_JarFile_Object = JarFile(NameOfJarfile)

               My_Entry_List =  My_JarFile_Object.entries()

       loop while My_Entry_List.hasMoreElements()

           My_JarFile_Entry=JarEntry My_Entry_List.nextElement()

           if Debug_Level > 5 then say "This files name = " My_JarFile_Entry.getName
           if         (Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos('.'||Name_of_Type) > 0 & -

                    Rexx(My_JarFile_Entry.getName).translate(My_File_Separator,'/').pos(My_File_Separator) = 0) then do

                   copyjarentry(My_JarFile_Object,My_JarFile_Entry,Name_of_Type||'_files')

           end

-- another Java "gotcha": jar entries have unix file separators thus requiring the translate above

        end

            catch err=Exception

                 say "Exception error ==>" err

    end get_next_entry

return this

-- Here is the nitty gritty code that makes it work. Probably not the best
-- way to do it but I used an unbuffered byte copy for my binary files and
-- buffered for the rest:

-- general purpose routines

-- method to copy a jarfile entry to a directory:

method copyjarentry(My_JarFile_Object=JarFile,My_JarFile_Entry=JarEntry,To_Subdir=String)

    if Debug_Level > 5 then trace all

        if Debug_Level > 9 then trace results

-- receives the jarfile object, the entry name in process and the directory to put it into.

        Full_Path_and_Name=To_Subdir|| My_File_Separator|| My_JarFile_Entry.getName

    File_Object=File(Full_Path_and_Name)

    if Debug_Level > 5 then say "Full_Path_and_Name = " Full_Path_and_Name "File_Object = " File_Object

-- check if file exists already and only copy if it is not there yet

    if \File_Object.exists then do label File_Object_Exists

        rc=copyjarentrytofile(My_JarFile_Object,My_JarFile_Entry,File_Object)

        if rc=1 then say My_JarFile_Entry.getName "copied to:" To_Subdir

        end File_Object_Exists

    return 0


method copyjarentrytofile(My_JarFile_Object=JarFile,My_JarFile_Entry=JarEntry,File_Object=File)

    if Debug_Level > 5 then trace all

        if Debug_Level > 9 then trace results

-- receives the jarfile object, the entry name and a "File Object"

    do label copy_scripts

-- create the input stream for the particular entry in the jar file

        Input_Stream = My_JarFile_Object.getInputStream(My_JarFile_Entry)

        if Rexx(My_JarFile_Entry.getName).pos(".txt")>0 then do              

                 Input_Reader=BufferedReader(InputStreamReader(Input_Stream))

            Output_Writer=BufferedWriter(FileWriter(File_Object))

            copyfile(Input_Reader,Output_Writer)

            Output_Writer.close

            end

        else

        if Rexx(My_JarFile_Entry.getName).pos(".class")>0 then do

            Output_Stream=FileOutputStream(File_Object)

            copybin(Input_Stream,Output_Stream)

            Output_Stream.close

            end

                catch badguy=Exception

                        say  My_JarFile_Entry.getName "copy error =" badguy

                        return 8

    end copy_scripts

return 0


/* methods to copy a file:   */


method copyfile(Buffed_Reader=java.io.BufferedReader,Buffed_Writer=java.io.BufferedWriter) signals IOException

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

   line=Buffed_Reader.readline

   if line = null then return 4

   Buffed_Writer.write(string line,0,line.length)

   trace off

   loop forever

       line=Buffed_Reader.readline

       if line = null then leave

       Buffed_Writer.newline()

       Buffed_Writer.write(string line,0,line.length)

       catch IO_Err=Exception

            say "copy error =" IO_Err

            return 8

       end

   return 0


method copybin(Byte_Input=InputStream,Byte_Writer=OutputStream) binary signals IOException

       if Debug_Level > 5 then trace all

       if Debug_Level > 9 then trace results

   A_Byte=Byte_Input.read

   trace off

   loop while A_Byte \= -1

           Byte_Writer.write(A_Byte)

           A_Byte=Byte_Input.read

               catch IO_Err=Exception

                       say "copy error =" IO_Err

                       return 8

   end

   return 0



Kenneth Klein
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/




_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org)

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Thomas Schneider, Vienna, Austria (Europe) :-)

www.thsitc.com
www.db-123.com
12