Blank Lines with File Factory

General discussion on the JZOS batch launcher and toolkit
Post Reply
TomPhillips
Posts: 1
Joined: Tue Mar 18, 2008 11:25 am
Location: Des Moines, IA USA

Blank Lines with File Factory

Post by TomPhillips »

We’re seeing some portability issues when using JZOS and we were wondering if you could give us some advice. We are using the same input file on both the Intel platform and the z/Series platform and trying to use the same Java code on both. We are running under z/OS 1.8 with the 1.5 SDK (at a build level of SR6b).


We open the file using FileFactory.newBufferedReader. We then use the readLine method to read the records in the file. There are some blank lines (all spaces) in the file. When we hit the blank line on the Intel platform, we get the full line returned. However, when we read the line on z/Series, we are only getting a newline character returned and the length of the line is 0.


Looking at the C/C++ documentation, we see the following: “For files opened in fixed text format, rightmost blanks are stripped off a record at input, and a new-line character is placed in the logical record. This means that a record consisting of a single new-line character is represented by a fixed-length record made entirely of blanks.” While this appears to be working as designed, it creates some portability issues between platforms.


What is your recommendation on reading files that contain blank lines? Should we use the readLine method, or is there a preferred method that would create code that is portable?

Thanks,
Tom
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

This is a very good question, I wish I had a better answer.

Unfortunately, there isn't an option in the C library for fopen() that preserves trailing spaces for fixed records. So, the FileFactory which relies on the underlying library doesn't seem to meet your requirement of preserving trailing spaces (for fixed-length record datasets).

I would encourage you to resubmit your problem/question to the IBM JZOS alphaWorks forum so that it has a little more visibility:

http://www.alphaworks.ibm.com/tech/zosjavabatchtk/forum

The official support channel, if you are using the SDK version (fully IBM supported) version of JZOS is to submit a problem or requirement to the IBM support center. Re-posting your question to the IBM alphaWorks JZOS forum is good starting place in the mean time.
mwilliam
Posts: 37
Joined: Mon Oct 11, 2004 3:21 pm

Post by mwilliam »

Well,
first of all, I wouldn’t recommend using the “FileFactory” methods directly, because of the lack of control specifying open mode.

Such as in the following C/C++ “fopen” function:
infile = fopen("file name","r")

The input file obtained is opened in the “text format” as you have indicated.

However, the following is a least portable version of the C/C++ “fopen” function:

infile = fopen("file name","rb,type=record")
As such, the input file is opened in “binary, record” mode, of which the i/o occurs at the record level. As indicated, in the “IBM C/C++” documentation, the “fread” and “fwrite” are the only I/O functions that work in while open in this mode.

Since, the ZFile Classes are wrappers to C/C++ functions, I suggest creating an instance a ZFile such in the following:

//open up in “MVS” binary record mode
ZFile inZfile = ZFile(“file name”, "rb,type=record")

java.io.InputStream inStream = inZfile.getInputStream() ;

//then following up with building your BufferReader if you like
… = new BufferedReader(new InputStreamReader(inStream) [, encoding mode]);

//This should return, the full blank lines, if not I got the LONG version using JRIO :wink:
dovetail
Site Admin
Posts: 2022
Joined: Thu Jul 29, 2004 12:12 pm

Post by dovetail »

If you are going to use an InputStream on a ZFile, it is best not to use record mode ("type=record"). Opening with "rb" will get you the same stream of data, but will result in fewer C library calls.
Post Reply