Possible extention for ZFile class

General discussion on the JZOS batch launcher and toolkit
Post Reply
JohnMcKown
Posts: 39
Joined: Sat Nov 21, 2009 2:59 pm

Possible extention for ZFile class

Post by JohnMcKown »

Me again, doing weird and "wonderful" things <grin>

I've run into a case where I think that I could use an extension to the ZFile class. Or maybe I'm once again missing something. The easiest way to explain may be to show you some Java code which I would like to be able to do:

Code: Select all

int fileType=ZFile.FileType(string);
switch (fileType) {
    case ZFile.DDNAME: // string is a DD name
             break;
    case ZFile.DSNAME: // string is a DSN
             break;
    case ZFile.UNIXNAME:   // string is a UNIX filename
             break;
}
Yes, I could do something like:

Code: Select all

if (string.startsWith("//")) {
    if (string.startsWith("DD:", 2)) {
        // DD name
    } else {
        // DSN
    }
} else {
    // UNIX name
}

But I think the switch just "looks better". ZFile.DDNAME, ZFile.DSNAME, and ZFile.UNIXNAME would all be static final int definitions.

What brought this on is that ZFile.exists() only works on z/OS files and not UNIX files. So I need to use ZFile.exists(input_name) if input_name is a DD or DSN, but for a UNIX file, I must use java.io.exists like:

if (java.io.File.exists(new java.io.File(input_name))

but my actual desire is actually different. I want to make sure the DD name exists if it is specified, but that the DSNAME and/or UNIX file does NOT exist if that is what is passed to my routine. The first is to avoid the ZFileException, the latter two to make sure that my output does not overwrite an existing file. Doing this make my code much more difficult to read. Although, I could just encapsulate the functions myself in a method of my own writing. I guess I'm a bit lazy. And, I will grant, that the tests are not atomic with the actual creation of the output file. At present, I restrict my output to a UNIX file and use java.io.File.createNewFile() .

Or, really nice would be a ZFile.createNewFile() functionality. Of course,that would not work with a DD name. Well,unless in the case of a DD name being passed, the code would see if the DISP on the DD was NEW. Or maybe check to see if an existing file has no data in it at all.

Just some thoughts.
mwilliam
Posts: 37
Joined: Mon Oct 11, 2004 3:21 pm

Post by mwilliam »

Sorry, but I'm not understanding what you attempting to achieve with dual purpose “ZFile.exists()” function? :(
Are you checking the existence of the file prior to writing to it?

However, if you wanting a UNIX file of having the look and file of an z/OS file, thereby having the ZFile.exist() function to work, I suppose you could supply the JCL parm: PATH=’???’ in place of the DSN parm. That way, the JCL references the UNIX file directly.
*MVS JCL ref* http://www.axe-man.org/res%5Cherc%5Cjcl ... 0guide.pdf

Also, though I dare not mention, the “com.ibm.recordio.RecordFile” class which also has the “exists()” function. I suppose, this variation is more complicated. :twisted:
http://www.ibm.com/developerworks/java/ ... dFile.html
JohnMcKown
Posts: 39
Joined: Sat Nov 21, 2009 2:59 pm

Post by JohnMcKown »

Basically what I'm trying to do is to make sure that I don't overwrite an existing file. java.io.File.exists() tells me TRUE or FALSE if the specified UNIX file exists or not, respectively. I'd like a similar function for a z/OS legacy dataset. The reason I'd like it in FileFactory is so that I can simply do a single function call and it will determine, from the name, whether the argument is a UNIX file or a z/OS dataset. As I said, I'm lazy!

What I may actually want is the equivalent to java.io.File.createNewFile() function, which will create a new file or, if the file (dataset) already exists, it will fail. Again, this is to guarantee that I don't overwrite an existing file.

com.ibm.recordio.RecordFile seems to only support UNIX files, not z/OS legacy datasets, so I don't know how this applies.
mwilliam
Posts: 37
Joined: Mon Oct 11, 2004 3:21 pm

Post by mwilliam »

Well,
technically, “com.ibm.recordio.RecordFile” does support z/OS files,
however the file name following the “//” has to be a fully qualified (physical sequential) dataset without the quotes. Though, this class does have other quirks. (I've used com.ibm.recordio.* classes back when I didn't have access to the jzos classes. :cry: )

Yes, I would agree a single function to work with both unix and z/OS files would be great.
Post Reply