Java - InputStream - Weird Characters in the Output!
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Java - InputStream - Weird Characters in the Output!
Hi,
I have a software which outputs lines of numbers one by one. In another java program, I use BufferedReader as follows:
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"US-ASCII"));
where pr is the process which runs the software. For each line in the output stream, I try to check whether the first number in the line is greater than a certain value and if it is, I write to another file.
The problem is, when I run the software repeatedly (in a linux cluster) like 10 simulations simultaneously, one of them have got @^@^.... characters followed by some huge numbers. So, I tried eliminating that line alone by using String.matches command but now, it seems even after that I get the error - so, I think it might mean that it is actually during the writing process that the problem occurs. I use BufferedWriter like the following to write it:
BufferedWriter out=new BufferedWriter(new FileWriter(tmp_file));
I would greatly appreciate if someone can help. This thing really seems to be a huge bottleneck!
I have a software which outputs lines of numbers one by one. In another java program, I use BufferedReader as follows:
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream(),"US-ASCII"));
where pr is the process which runs the software. For each line in the output stream, I try to check whether the first number in the line is greater than a certain value and if it is, I write to another file.
The problem is, when I run the software repeatedly (in a linux cluster) like 10 simulations simultaneously, one of them have got @^@^.... characters followed by some huge numbers. So, I tried eliminating that line alone by using String.matches command but now, it seems even after that I get the error - so, I think it might mean that it is actually during the writing process that the problem occurs. I use BufferedWriter like the following to write it:
BufferedWriter out=new BufferedWriter(new FileWriter(tmp_file));
I would greatly appreciate if someone can help. This thing really seems to be a huge bottleneck!
Thanks,
Senthil
Without knowing how the data are created, I can only guess. The problem might be that you are specifying a character encoding that doesn't agree with the input, or the source is emitting raw binary data, or something else.
It's all guesswork without seeing the data and the code that created it.
Its just lines of numbers like the following:
0 7200 0 0 0 0 0 .....
2 7124 9 8 27 10 ....
When the simulator is run, it usually outputs these lines of numbers to the command line, which I am now reading using BufferedStream.
Does this help at all?
Thanks and looking forward to your post!
If the source data was a simple list of numerical text, you wouldn't be having a problem. But you are having a problem, so you need to look more closely at the input data and its source. Is it really just text, or is it numerical data that happens to be printed as text in your example?
One way to proceed is to capture the data in a text file and then examine it using hexdump:
Code:
$ (source of the data) > temp.txt
$ hexdump -C temp.txt
Anything outside the numerical range 0 - 127 (hex 00 - 7f) isn't plain ASCII and needs to be investigated further.
Thanks! I captured a part of the output and then, tried the command you have suggested. I am unable to discern anything out of it - I guess, they are all in the range of 00-7f - is there anyway you could help? Thanks, once again!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.