Author |
Message
|
DP1234 |
Posted: Mon Jun 02, 2014 11:17 am Post subject: File Size Calculation in Java Compute Node |
|
|
Apprentice
Joined: 25 May 2014 Posts: 40
|
Hi.,
I have to calculate the file size in Java Compute Node.,How can i do this
My flow has FileInput Node>> Java Compute Node>>File output Node
Please Help me out
Thanks |
|
Back to top |
|
 |
Vitor |
Posted: Mon Jun 02, 2014 11:37 am Post subject: Re: File Size Calculation in Java Compute Node |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
DP1234 wrote: |
I have to calculate the file size in Java Compute Node |
Why? What value does this information have? What use can you put it to?
Certainly you don't need to know it to process the file's contents. So if you explain why you think you need it, we can suggest alternative.
Better information, better advice. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
DP1234 |
Posted: Mon Jun 02, 2014 9:37 pm Post subject: Re: File Size Calculation in Java Compute Node |
|
|
Apprentice
Joined: 25 May 2014 Posts: 40
|
Vitor wrote: |
DP1234 wrote: |
I have to calculate the file size in Java Compute Node |
Why? What value does this information have? What use can you put it to?
Certainly you don't need to know it to process the file's contents. So if you explain why you think you need it, we can suggest alternative.
Better information, better advice. |
Basically i need to cross check the actual file size with the file size value mentioned in the header of my XML input file..to analyse the integrity of file.,
In java file size can checked by
File file =new File("c:\\xyz.txt");
double bytes = file.length();
But once file input node fetches my input file it no more occurs in directory so i cant use above logic...Please do suggest is there any alternate solution to calculate file size in JCN upon getting from File input node |
|
Back to top |
|
 |
Tibor |
Posted: Tue Jun 03, 2014 1:10 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
If your message parser was BLOB you could easily get the file length because it is as same as the structure length. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 03, 2014 4:44 am Post subject: Re: File Size Calculation in Java Compute Node |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
DP1234 wrote: |
Basically i need to cross check the actual file size with the file size value mentioned in the header of my XML input file..to analyse the integrity of file. |
So you're getting an XML input file, which contains the name of an actual file which you're then reading? Why not just read the file directly?
But then:
DP1234 wrote: |
But once file input node fetches my input file it no more occurs in directory so i cant use above logic |
If you're using the FileInput node to read a file where does this XML file fit in? If you're trying to analyse the integrity of the input XML file then file size is not an accurate method; an XML file can be a variety of different sizes (depending on the amount of whitespace) and still have integrity.
Validate XML with a schema; WMB will do this for you. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
paustin_ours |
Posted: Tue Jun 03, 2014 5:20 am Post subject: |
|
|
Yatiri
Joined: 19 May 2004 Posts: 667 Location: columbus,oh
|
I agree with Vitor this is not the way to check the integrity of the file. If the file is coming from remote machine secure the way you put the file on your machine. length check doesn't guarantee the file is not tampered with. |
|
Back to top |
|
 |
zpat |
Posted: Tue Jun 03, 2014 5:28 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
If the XML was truncated then it would fail validation? _________________ Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error. |
|
Back to top |
|
 |
Tibor |
Posted: Tue Jun 03, 2014 5:35 am Post subject: |
|
|
 Grand Master
Joined: 20 May 2001 Posts: 1033 Location: Hungary
|
Perhaps this is a double-check on their side... |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 03, 2014 5:51 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
zpat wrote: |
If the XML was truncated then it would fail validation? |
Yes - the closing root tag would be missing even if the truncation occured in whitespace between 2 child tags, rendering the document misformed. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 03, 2014 5:52 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Tibor wrote: |
Perhaps this is a double-check on their side... |
This sounds like a "double check" that has you logging message ids or consuming COD/COA messages "just in case WMQ loses a message".
Valid check, wrong method. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
DP1234 |
Posted: Tue Jun 03, 2014 11:26 am Post subject: Re: File Size Calculation in Java Compute Node |
|
|
Apprentice
Joined: 25 May 2014 Posts: 40
|
Vitor wrote: |
DP1234 wrote: |
Basically i need to cross check the actual file size with the file size value mentioned in the header of my XML input file..to analyse the integrity of file. |
So you're getting an XML input file, which contains the name of an actual file which you're then reading? Why not just read the file directly?
But then:
DP1234 wrote: |
But once file input node fetches my input file it no more occurs in directory so i cant use above logic |
If you're using the FileInput node to read a file where does this XML file fit in? If you're trying to analyse the integrity of the input XML file then file size is not an accurate method; an XML file can be a variety of different sizes (depending on the amount of whitespace) and still have integrity.
Validate XML with a schema; WMB will do this for you. |
No,Am reading the actual file only..,the XML file itself is the actual file whose size has to calculated and then cross checked with the size value in header..
I did placing the duplicate copy of XML input file in an directory an then apply
File file =new File("c:\\xyz.txt");
double bytes = file.length();
Logic
It works fine..,But i want size to be calculated in JCN directly..,Validation using XML schema is done..,This is also one of the requirement. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jun 03, 2014 11:41 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Ok.
Once you read it from FileInput, it's *not* a file any more. It's a message tree.
If you are pathologically sure that you need to confirm that the count of the bytes in the file is the same as the number put into an element in the file, then read the file as BLOB. Then get the LENGTH of the blob. Then parse the BLOB into XML.
But this is a terrible checksum notion, there are a thousand ways the file could be bad that still pass this test. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 03, 2014 12:30 pm Post subject: Re: File Size Calculation in Java Compute Node |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
DP1234 wrote: |
No,Am reading the actual file only..,the XML file itself is the actual file whose size has to calculated and then cross checked with the size value in header.. |
This is ridiculous. Utterly. As I indicated above, the file could be any number of sizes.
DP1234 wrote: |
Validation using XML schema is done..,This is also one of the requirement. |
One of what requirements? What is the technical reason for this additional validation? What action is your flow expected to take if the XML document passes the schema validation but has a different size (and it could)? More importantly, what is the expected action if the file size matches but the schema validation fails (and that's even more likely!)???
What value does this size check give that the schema validation does not? What exactly are you checking for? What failure scenario is this check intended to catch? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jun 03, 2014 12:44 pm Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqjeff wrote: |
If you are pathologically sure that you need to confirm that the count of the bytes in the file is the same as the number put into an element in the file, then read the file as BLOB. Then get the LENGTH of the blob. Then parse the BLOB into XML. |
That's just contact admin.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jun 03, 2014 12:47 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
mqjeff wrote: |
If you are pathologically sure that you need to confirm that the count of the bytes in the file is the same as the number put into an element in the file, then read the file as BLOB. Then get the LENGTH of the blob. Then parse the BLOB into XML. |
That's just contact admin.  |
The whole notion is mucked up.
But this is the closest thing that could possibly match
Quote: |
the file size value mentioned in the header of my XML input file |
I mean, assuming for example that the file hasn't been moved over FTP using ASCII mode. |
|
Back to top |
|
 |
|