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/ |
Kermit,
nice try, but let me humbly criticize For the newbie (ME) this code lacks lots of comments :-( Is it complete? (where does df come from? I imagine it's a debug flag) How does one install it in order to try it? In the 'compelling arguments' that I mentioned here yesterday I forgot SHORT(er) and that your example is not Regards Walter _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Kermit Kiser
I am working on making this snippet of code work as a simple example in preparation for incorporating it into my earlier project. I'll document it as best I can to make it useful in the new programmer's guide. If I can make it work, it should be learnable.
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/ |
In reply to this post by Kermit Kiser
pls send it to me for review/test
Walter ---- [hidden email] schrieb: > I am working on making this snippet of code work as a simple example in > preparation for incorporating it into my earlier project. > I'll document it as best I can to make it useful in the new programmer's > guide. If I can make it work, it should be learnable. _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Kermit Kiser
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
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/ |
Just add the static keyword to your copyjarentry method.
Rick On Thu, May 10, 2012 at 9:53 AM, <[hidden email]> wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by kenner
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
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]
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by kenner
You might want to know that, as far as I can remember, I did already
*integrate* JAR-File (and PDS-File, on IBM zOS system) into my RexxFile.class, part of org.netrexx.thsitc.runtime.compatibility. Rene, and all masters of the Netrexx Lanuage Board, please let me know asap where I should the downloadable JAR-file into: (a) on www.netrexx.org (b) on www.thsitc.com (c) any other suggestions ?? Please let me know your thoughts. I'm using the newést version of the run-time now for more than a half year, and thinks -- due to my own heavy usage -- it's bug-free. But who knows? My org.netrexx.thsitc.utils do contain quite simple ain programs showing the proper usage, which has been designed to show the various usages as well. Also, where should this utility jar be downloadable from (same choices as above) Please discuss within the board, and/or the upoming RexxLA meeting, and advse. Anyway, I did already donate those to packages to RexxLA a half year ago. or so, and am now ready for the next release (using SVN, of course, Mr. President :-). Thomas Schneider, from *lucky* and *sunny* Vienna, Austria (Europe, *no Kangoroohs* ,-)) ======================================================== Am 10.05.2012 15:53, schrieb [hidden email]:
--
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 |
In reply to this post by measel
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
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
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/ |
Kenneth, Rene,
As response to Kenneth's private mail I did send you a small private mail with an *attached* PP.nrx and small build.bat file to your business adress, but got the mail rejected (by Ttoyota (for Kenneth) as well as Google (forwarded by Rene's [hidden email]) Any ideas what causes this? Do Google &/ Toyota not permit .bat files for security reasons? Had same problem very long time ago, but cannot recall the reason(s). Kenneth, will send you same male and sample to your private address I should have somewhere in my Thunderbird Adress book .. . Thomas. ================================================== . Am 10.05.2012 17:56, schrieb [hidden email]:
--
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 |
In reply to this post by kenner
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]
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
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
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
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
|
Line 20 looks broken to me; the second argument to the pos
method should be a start position (number).
Mike
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by kenner
My_File_Separator is not defined.
On 5/10/2012 3:20 PM, [hidden email] wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In an earlier post you mentioned that the POS function was wrong and inserted a comma between 'NetRexx' and the file separator. I think this was a mistake. I think Kermit is concatenating the text 'NetRexx' to the file separator and then looking for the position of the text 'NetRexx/' (or NetRexx\' depending on platform) You're getting a NumberFormatException because the second argument for POS should be numeric; file separator will be a string; hence the exception.
Here's a little snippet I created to isolate the problem: /* NetRexx */ options replace format comments java crossref symbols utf8
My_File_Separator = System.getProperty("file.separator")
My_JarFile_Entry = 'slash/slash/slash/NetRexx/dot.dot.dotlib' say 'File Sep :' My_File_Separator say 'File Entry:' Rexx(My_JarFile_Entry).translate(My_File_Separator, '/')
say 'File Pos :' Rexx(My_JarFile_Entry).translate(My_File_Separator, '/').pos('NetRexx'My_File_Separator) Running it (on a UNIX-like system) I get: File Sep : / File Entry: slash/slash/slash/NetRexx/dot.dot.dotlib
File Pos : 19 Alan.
On 10 May 2012 12:29, Jeff Hennick <[hidden email]> wrote:
Can't tweet, won't tweet! _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Alan
-- Needs more cowbell. |
In reply to this post by Kermit Kiser
Hi Kermit,
thank you - I will include it. best regards, René. On 10 mei 2012, at 01:44, Kermit Kiser wrote: > 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/ |
In reply to this post by ThSITC
correct, you cannot send .bat through google. Please use dropbox or one of the other more modern mechanisms.
René. On 10 mei 2012, at 12:18, Thomas Schneider wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
On Thu, May 10, 2012 at 6:33 PM, René Jansen <[hidden email]> wrote:
I vouch for Pastebin.com... that's what it was designed for... avoid pasting code snippets on mailing lists, and just include a pointer to them. :) Just my $0.02 FC _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by kenner
I guess I should have done the rewrite before posting. The check for
"NetRexx/" in the name should not be there for a generic example.
That line should be rewritten like this:
copyjarentry(jf,je,setdir) No conditional unless you are looking for a specific file or directory name! -- Kermit On 5/10/2012 8:56 AM, [hidden email] wrote:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Fernando Cassia-2
Hi Rene, thanks for replying...
... already found out that he attahed .bat file was the reason (obviously for *security dangers*... Will try to *remember it* with my lonely 1 Gangl in my vacuum brain ,-) Have a nice day, Thomas. ======================================================= Am 10.05.2012 23:52, schrieb Fernando Cassia:
--
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 |
Free forum by Nabble | Edit this page |