How to accept Unicode escape sequences from the command line

General discussion on the JZOS batch launcher and toolkit
Post Reply
StevenHComstock
Posts: 9
Joined: Sun Jan 13, 2008 10:43 pm

How to accept Unicode escape sequences from the command line

Post by StevenHComstock »

What method(s) can I use to read string data from
the command line such that if the string contains
a Unicode escape sequence (e.g.: \u305f) the
reading method will convert that into a single
Unicode character (た) instead of the literal string
\u305f ?
[/img]
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

Steve,

What command line are you referring to?

I am not aware of a public Java method to do this, but there is code
that does it in the private method: java.util.Properties.loadConvert().

Kirk Wolf
StevenHComstock
Posts: 9
Joined: Sun Jan 13, 2008 10:43 pm

How to accept Unicode escape sequences from the command line

Post by StevenHComstock »

Steve,

What command line are you referring to?

I am not aware of a public Java method to do this, but there is code
that does it in the private method: java.util.Properties.loadConvert().

Kirk Wolf

--
From the z/OS UNIX (omvs) command line; when I run my
testing code, trying all the InputStream and Reader classes.

So if, for example, I issue

stringIn = brdr.readLine();

in my program, then when the program runs it prompts
the user to enter a string, so the user might enter a string
of keyboard characters and Unicode escape; is there a
method such that it will automatically build the input
buffer ("stringIn") above so that the Unicode escapes
will be converted to Unicode characters instead of the
literal Unicode escape sequence. So this is how you could
create a Java program to allow, say, product descriptions
or movie ratings, or literature analysis of texts with
non-Latin characters, to be entered.

I don't think the method you are referring to will accomplish
what I'm trying to accomplish. It looks like I'm going to have
to create my own method, but it seems to me that this is
how Java should treat string input that contains Unicode
escapes. [It should also display non-ASCII characters
as Unicode escapes, when using any of the print methods,
but that's a different battle.]
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

You can't use the Properties.loadConvert() method because it is private. But I think that the code does what you are asking for and a little more. You can "copy" the parts that you want to your own method, or use it as an example of how to write your own.
StevenHComstock
Posts: 9
Joined: Sun Jan 13, 2008 10:43 pm

Post by StevenHComstock »

You can't use the Properties.loadConvert() method because it is private. But I think that the code does what you are asking for and a little more. You can "copy" the parts that you want to your own method, or use it as an example of how to write your own.

--

Great! How do I look at the code? I went to my java15
directory, found src.jar, and issued:

jar xf src.jar java.util.Properties.java

the command completed with no errors, but an ls
does not show the file in the current directory.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

It usually comes with the JDK, in a file called src.zip.

FWIW - If you use Eclipse, it automatically finds and "attaches" the source to rt.jar, so that when you open the class the source pops up.
StevenHComstock
Posts: 9
Joined: Sun Jan 13, 2008 10:43 pm

Post by StevenHComstock »

It usually comes with the JDK, in a file called src.zip.

FWIW - If you use Eclipse, it automatically finds and "attaches" the source to rt.jar, so that when you open the class the source pops up.

--

Ah, OK. A little counter-intuitive, but there it is. But now, how do I read a zip file under z/OS? I can't seem to find it in the Java docs (which is why I was looking for src.jar, because the docs do tell how to look at .jar files).

As for your second point, I do have Eclipse (in the guise of V6 for WS4D), but I'm trying not to use it, but looking to create a pure z/OS Java course. Even so, I thought I'd try, but I'm afraid I'm really too much of a mainframe nerd to understand what you say: "If you use Eclipse," [OK...] "it automatically finds and attaches the source to rt.jar" [lost me.; what is rt.jar; how is it that Eclipse finds it; what is rt.jar attached to; what does it mean to "attach: something to something else?]

So let me start here: I've brought up Eclipse, started a new Java project, and started writing some code. Now how is it I can see the source for the method you mentioned?

Sorry to be such a bother, but I really feel the pain here for the Java novice; things really need to be carefully spelled out because the Java world on the workstation has such a different orientation than the ISPF world on z/OS.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

You can process zip files with the "jar" command.

Under Eclipse, you can use the Navigate/Open Type... and open the java.util.Properties class.

IMO, there is no good reason to ever deal with Java source on z/OS.
Just use an IDE like Eclipse and then Ant scripts to build jars and ftp upload to z/OS.

The advantage of an IDE that incrementally compiles and syntax-checks your Java code while you type is only way to go.
Putting source code on z/OS and trying to use ishell and oedit is like watching paint dry. Running javac on z/OS is too slow and expensive compared to the great incremental java compiler built into Eclipse.

See our "BatchSample" project on the JZOS downloads page for example code and Ant scripts.
(This is the project that we use in our SHARE Hands-on Lab: "z/OS Java Stand-alone applications".
StevenHComstock
Posts: 9
Joined: Sun Jan 13, 2008 10:43 pm

Post by StevenHComstock »

You can process zip files with the "jar" command.

--
Well, I thought I remembered trying it and failing, but I just tried again and it worked.

--

Under Eclipse, you can use the Navigate/Open Type... and open the java.util.Properties class.

--
Got it. There it is! Thanks.
--


IMO, there is no good reason to ever deal with Java source on z/OS.
Just use an IDE like Eclipse and then Ant scripts to build jars and ftp upload to z/OS.

--
I do not find Eclipse intuitive at all, despite what others may say. You need to build some experience with it. If a student is fighting learning Java and trying to figure out how to use Eclipse, I think they have a harder time. I could be wrong (it's been known to happen <vbg>).
--

The advantage of an IDE that incrementally compiles and syntax-checks your Java code while you type is only way to go.
Putting source code on z/OS and trying to use ishell and oedit is like watching paint dry.
--

Well I'm sure glad to hear you say that. I thought it was just us and our Thinkpad-based z/OS.

On the other hand, the course I'm writing is very z/OS-centric and is much more codepage-aware than other Java courses I've seen. I talk about, demo, and have in the lab: creating and reading files in EBCDIC, ASCII, and UTF-16; using oedit and obrowse; running programs from the z.OS UNIX command line (that is, ISPF/omvs). Also, I can't count on any customer having Eclipse or WS4z available, but they will always have ISPF avaiable.
--



Running javac on z/OS is too slow and expensive compared to the great incremental java compiler built into Eclipse.
--
I'm trying to go back a forth a bit, because it is useful to know how to use Eclipse, and I'm working on that personally. So if I teach my course in a place that has Eclipse, we can use that tool, at least for part of the work.
--

See our "BatchSample" project on the JZOS downloads page for example code and Ant scripts.
(This is the project that we use in our SHARE Hands-on Lab: "z/OS Java Stand-alone applications"

--

I'm planning to include some JZOS content in the course. Now that it's officially part of the Java distribution for z/OS, I can be sure it's always available and it looks like a great tool.

--

Thanks again for your help and patience. I think we can put this thread to rest.
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

IMO, any time spent learning Eclipse (or if you prefer NetBeans, Idea, etc) is payed back in the short term (with dividends) when you use it while learning Java.

Its free - so unless someone has another IDE, why not use it?
Post Reply