Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem to get the zos file size #5

Open
matmass opened this issue Mar 9, 2021 · 3 comments
Open

problem to get the zos file size #5

matmass opened this issue Mar 9, 2021 · 3 comments

Comments

@matmass
Copy link

matmass commented Mar 9, 2021

Hi,

I don't find the way to get the file size for a Z/os sequential file in bytes or even in tracks.

How can I do that?

Regards,
Mathias.

@fjeremic
Copy link

fjeremic commented Mar 9, 2021

To get a dataset size you can use the getLrecl API from the com.ibm.jzos package. You can find full documentation here:
https://www.ibm.com/support/knowledgecenter/SSYKE2_7.0.0/com.ibm.java.zsecurity.api.70.doc/com.ibm.jzos/com/ibm/jzos/ZFile.html#getLrecl()

There is an example of using the API to read entire contents of a dataset into a byte[] here:
https://www.ibm.com/support/knowledgecenter/en/SSYKE2_7.1.0/com.ibm.java.zsecurity.api.71.doc/com.ibm.jzos/com/ibm/jzos/RecordReader.html

@matmass
Copy link
Author

matmass commented Mar 10, 2021

Thanks for the reply.

So if I understand, we need to read the file and to count the bytes.

It means that we can't get directly the file size as a property.

Is-there any other way to get it?

Regards,
Mathias.

@fjeremic
Copy link

You do not need to read the whole dataset to get it's length. The example in the second link above does that, but if all you want is the length of the dataset you can just use getLrecl. What the second example does is it creates a RecordReader and uses getLrecl to get the size of the dataset, then it allocates a byte[] using the size and reads the entire dataset into the byte[].

This is not what you need. You can just directly create a ZFile and use the API in my first link.

Here is how the constructor of ZFile looks (with examples):
https://www.ibm.com/support/knowledgecenter/SSYKE2_7.0.0/com.ibm.java.zsecurity.api.70.doc/com.ibm.jzos/com/ibm/jzos/ZFile.html#ZFile(java.lang.String,%20java.lang.String)

So if your dataset is SYS1.HELP(ACCOUNT) as in the example, you can do:

ZFile dsn = new ZFile("//'SYS1.HELP(ACCOUNT)'", "rt");
int datasetSizeInBytes = dsn.getLrecl();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants