I keep thinking I have my head on straight regarding using java objects in RPG, 
then I confuse myself again.  Perhaps you can help?

In the following program I am playing with URLEncode.  I had the program 
working fine, until I wanted to convert back the new encoded URL string into 
AS400 characters.  I have my string "outstring" and all I need to do is execute 
"outstring.getBytes()".  I tried prototyping getBytes, but keep getting an 
error (shown in the text below).

How do I call getBytes on my nice string?

     D outstring       S               O    CLASS(*JAVA:'java.lang.String')
     D instring        S               O    CLASS(*JAVA:'java.lang.String')
     D utfstring       S               O    CLASS(*JAVA:'java.lang.String')
     D Text            S             30A

      * JAVA METHODS **********************
      *       EXTPROC(*JAVA:'Object Name':'Method Name')
      *        CLASS(*JAVA:'Return Object Class')
      *        Input Parameters Follow
      * encode method
     D  encode         PR              O    ExtProc(*JAVA:
     D                                      'java.net.URLEncoder':
     D                                      'encode')
     D                                      STATIC
     D                                      CLASS(*JAVA:'java.lang.String')
     D                                 O    CLASS(*JAVA:'java.lang.String')

      * Constructor for a string
     D makestring      PR              O    EXTPROC(*JAVA:
     D                                       'java.lang.String':
     D                                       *CONSTRUCTOR)
     D    bytes                      30A    CONST VARYING

      * Get Bytes from a string for conversion to AS400 Characters
     D getbytes        PR           256A    ExtProc(*JAVA:
     D                                      'java.lang.String':
     D                                      'getBytes')

       utfstring = makestring('UTF-8');
       instring  = makestring('The String @foo-bar');
       outstring =   encode(instring);
       *inLR = *on;

No banners. No pop-ups. No kidding.
Make My Way  your home on the Web - http://www.myway.com

Return to Archive home page | Return to MIDRANGE.COM home page