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: (I do flush it after writing.)
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

Hi ejp! Thanks - here is the code!
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.*;
import java.util.*;
//call the class file with the input xml file to simulate
public class RunSim {
public static void main(String[] args) {
String[] xmlFiles = new String[] { "/home/senthil/Simulator/Dessa1.4/" args[0]};
Scanner input=null;
FileWriter ofw=null;
PrintWriter out=null;
for(String file:xmlFiles) {
try {
String[] command = {"java","Test",file, "10000"};
Process pr = Runtime.getRuntime().exec(command); // run the command
input = new Scanner(new InputStreamReader(pr.getInputStream()));
String line=null;
ofw=new FileWriter(file"_out.txt");
out=new PrintWriter(ofw);
while(input.hasNextLine()) {
line=input.nextLine();
System.out.println(line);
if(line.matches("[0-9.\\s]*")) { // I included this as I didn't want the '@^' character - but still, it is being produced.
out.println(line);
out.flush();
String[] str = line.split(" ");
if(!line.equals("Badly formatted XML file")){
if((Float.parseFloat(str[0]) >= 196)) //this is the limit upto which the process has to be run
pr.destroy();
else
continue;
out.close();
int exitVal = pr.waitFor();
System.out.println("Exited with error code "+exitVal);
} catch(Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}

Similar Messages

  • If i got incorrect characters in the output of sap script? HOW TO CORRECT I

    If i got incorrect characters in the output of sap script? HOW TO CORRECT IT?

    Hi Sunil,
    Debug the script and check where exactly those are getting populated. Definately you will get it. Check the conversion parts means character to numeric conversion.
    If your version is 4.7E then select unicode check box in the reports attributes. It will display the error message so that we can solve very easily.Hope this helps you, reply for queries, Shall post you the updates.
    Regards. 
    Kumar. .

  • Weird characters before the xml start tag on Host

    When we load xml generated in Biztalk into an OS/400 Host environment, they always have some weird characters before the declaration (<?xml) causing the host program to fail. The characters look like gibberish from another planet (not really..look like
    some binary encoding). Can one of the experts please point me to what must be changed?

    If you look at the message using a hex editor, the UTF-8 BOM (Byte Order Mark) is EF BB BF, if you are using Unicode, the BOM is FE FF or FF FE (depending on little or big Endian encoding).
    If you "Stop" your send port and run a test, you can view the suspended message body in hex and determine if these characters are a BOM.
    David Downing... If this answers your question, please Mark as the Answer. If this post is helpful, please vote as helpful.

  • Weird characters in g++ output

    When using Arch and ssh/xterm to remotely logging into an Ubuntu machine (university lab computer)  to run g++, the complier output (when there's a compile error) has an accented character "a hat" (i.e. the character "a" with a caret symbol above it) in place of all function and variable names .
    For instance, it will output:
    file.cc : In function <a-hat symbol>
    file.cc:19: error: <a-hat> was not declared in this scope.
    when it should have outputted:
    file.cc : In function main
    file.cc:19: error: idx was not declared in this scope.
    NOTE:  I don't know how to enter special characters in a post, so I entered <a-hat> instead of the actual special character.
    Now, it doesn't happen when I log into the Ubuntu machine from another Ubuntu machine.  It only happens when the client is Arch.  I am 99% certain that this is a problem with Ubuntu and not Arch.  But, I don't have root on the Ubuntu machine because it's the school's computer, so I can't fix it.
    Does anyone know if there's something I can try on the Arch box that will fix this display problem?
    EDIT:  Sorry, I should've posted this in the Workstation thread maybe.  Admins, please kindly move it if you see fit.
    Last edited by battra (2007-06-06 03:55:20)

    grepper and Tucos in #conky solved the issue for me.  Apparently, the "weird characters" was a color code.  I had to pipe:
    sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"
    in conkyrc to remove color codes.

  • Junk Characters in the output XML file after Parsing

    Hi
    I am using DOM parser to parse an XML file.
    After parsing the input XML file, i am fetching some contents
    from the same and also putting the same contents in the parsed output file which is also an XML file.
    The problem here is that the after putting the contents to the output XML file from the input XML file,
    some junk character appears at the end of each and every tag in the outputfile.
    The junk character is some thing like this : " ampersand hash thirteen and a semicolon "
    (*THE MESSAGE DID NOT ACCEPT THE SYMBOLS KINDLY TRANSLATE THE ABOVE WORDINGS*
    INTO SYMBOLS)
    This character gets appended at the end of each and every tag in the output file due to which the output file
    is not recognised as an XML file.
    Please let me know as to why is this character appearing and also please suggest some solution
    for the same.
    -Thanks in Advance.
    Edited by: itskarthik on Oct 10, 2008 7:16 AM
    Edited by: itskarthik on Oct 10, 2008 7:18 AM
    Edited by: itskarthik on Oct 10, 2008 7:19 AM
    Edited by: itskarthik on Oct 10, 2008 7:19 AM
    Edited by: itskarthik on Oct 10, 2008 7:23 AM
    Edited by: itskarthik on Oct 10, 2008 7:23 AM

    Wierd.
    Try this piece of code. (You can always change it to use input file and output file instead of string if you want)
    What is your output?
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.Result;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.w3c.dom.Document;
    public class XMLTest {
         public static void main(String[] args) throws Exception {
              String input = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" +
                                  "<test>\r\n" +
                                  "</test>";
              System.out.println("Input:");
              lookForCR(input);
              DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
              Document doc = factory.newDocumentBuilder().parse( new ByteArrayInputStream(input.getBytes()) );
              Source source = new DOMSource(doc);
              ByteArrayOutputStream bArrOut = new ByteArrayOutputStream();
              Result result = new StreamResult( new StripOutputStream( bArrOut ) );
              Transformer xformer = TransformerFactory.newInstance().newTransformer();
              xformer.transform(source, result);     
              System.out.println("\nResult:");
              lookForCR(bArrOut.toString());
              System.out.println("\nDone");
         public static void lookForCR(String input) throws Exception {
              char[] chars =input.toCharArray();
              for ( char chr : chars ) {
                   if (chr == 13 ) {
                        System.out.println("Has 0x0D character!!");
    class StripOutputStream extends OutputStream {
         OutputStream out = null;
         public StripOutputStream(OutputStream out) {
              this.out = out;
         @Override
         public void write(int b) throws IOException {
              if ( b != 13 )
                   out.write(b);
    }- Roy

  • Junk Characters in the Output of  Reports2.5

    I have created Report in Reports2.5 which is giving good output display
    But when I Register the Report in Oracle Apps & see output
    it shows Junk Characters in the place of Labels
    e.g. Revenue Report
    will come like sg0Revenue o7Report
    Can any-one give me the solution for this
    Regards / Shailesh ( [email protected] )

    This is probably due to the prt file that's being used to format the output. I'm willing to bet that the headings are in bold, and the prt file being used has includes some control characters to tell the printer to switch on and off bold - when you view the output file those are the characters you're seeing.
    To switch this off simply remove the control characters from the prt file being used.
    Hope this helps,
    Danny

  • Receiver SFTP adapter giving spaces between characters in the Output file

    Hi PI Experts,
    My Scenario is: Paymul (EDI file ) ECC -> PI -> SFTP server.
    Source Sender File adapter able to pickup this Paymul D96A file and able to send messages to target SFTP server using SFTP receiver adapter.
    But, Generated Output file having single space between each character. I am not using any content conversion modules in Receiver SFTP adapter.
    Also not having any mappings to transform the messages. it is just pass through interface.
    I have attached example Output file. I have changed the .Dat file to .txt just to attach here.
    Could any one try to help me on this. Please let me know incase need any more details.
    Thanks,
    Govindu.

    Hi Govindu,
    Please see if the below Endcoding settings wont resolve your issue.
    File Type - Text
    File Encoding - ISO-8859-1
    Regards,
    Jannus Botha

  • How to convert the output of Applescript which is in object format to text or string format??

    Hi All,
    I want to convert the output of Applescript which is in object format to string or text format, am running Applescript with Java, I need to display the output of applescript in Eclipse Java Console, since its object format the output is not properly displayed..
    Pls suggest.. I used the below code
    repeat with i in allContents
                if class of i is button then set the end of allStaticText to contents of i
            end repeat
    Applscript ouptput
    {button 1 of window "Player Installer" of application process "Install  Player" of application "System Events", button 2 of window "Player Installer" of application process "Install  Player" of application "System Events", button 3 of window "Player Installer" of application process "Install  Player" of application "System Events", button "Finish" of UI element 1 of scroll area 1 of window "Player Installer" of application process "Install  Player" of application "System Events"}
    Java output
    <NSAppleEventDescriptor: 'obj '{ 'form':'indx', 'want':'butT', 'seld':1, 'from':'obj '{ 'form':'name', 'want':'cwin', 'seld':'utxt'(" Player Installer"), 'from':'obj '{ 'form':'name', 'want':'pcap', 'seld':'utxt'("Install  Player"), 'from':'null'() } } }>

    Here's an improved version of the previous script, where the handler now returns "button 2 of window \"Untitled\" of application process \"TextEdit\" of application \"System Events\"" instead of "button \"2\" of window \"Untitled\" of application process \"TextEdit\" of application \"System Events\"":
    tell application "System Events"
        get button 2 of window 1 of process "TextEdit"
        my objectToText(result) --> "button 2 of window \"Untitled\" of application process \"TextEdit\" of application \"System Events\""
    end tell
    on objectToText(UI_element)
        set theText to ""
        tell application "System Events"
            repeat
                if exists attribute "AXParent" of UI_element then
                    set theParent to value of attribute "AXParent" of UI_element
                    set theClass to class of UI_element
                    if name of UI_element exists then
                        set theName to name of UI_element
                        set theText to theText & (theClass as text) & " \"" & theName & "\" of "
                    else
                        set k to 0
                        get UI elements of theParent whose class is theClass
                        repeat with thisItem in result
                            set k to k + 1
                            if contents of thisItem is UI_element then exit repeat
                        end repeat
                        set theIndex to k
                        set theText to theText & (theClass as text) & " " & theIndex & " of "
                    end if
                    set UI_element to theParent
                else
                    set theClass to class of UI_element
                    set theName to name of UI_element
                    set theText to theText & (theClass as text) & " \"" & theName & "\" of application \"System Events\""
                    exit repeat
                end if
            end repeat
        end tell
        return theText
    end objectToText
    Message was edited by: Pierre L.

  • Offline approval - weird characters in Outlook

    Hi all,
    We're on SRM 5.0, Server 550, SP12.
    Scenario: offline approval of Shopping Carts
    After running report RBBP_NOTIFICATION_OFFAPP, approver is getting an e-mail in Outlook 2003 with some weird characters:
    **START**
    Â
        The following requires processing:
    Â
        1 . Approve shopping cart of Shopper with value 64,78 USD
       
    Â
    Â
        Use the following link to log on to the system and carry out the approval online:
        Log on
    Â
    Â
        To approve or reject directly from this e-mail, select one of the following links:
    Approve by E-mail   Reject by E-mail   Â
    **END**
    When I look at the same message in , these characters are not visible; but there seem to be spaces/blanks in those spots. Looks like Outlook is substituting spaces for some other character.
    Also, there're some extra blank lines, which we would like removed.
    Any ideas how to get rid of the unwanted characters and unnecessary lines, besides BAdI implementation?
    Cheers,
    Serguei

    Hi,
    Please check the foll note:
    Note 1100912 - E-mail messages for work items with incorrect line break
    Also,sometimes some junk characters are inserted into the offline mail if the required services(for the generation of mail ) are not active in transaction SICF.
    Please see whether the following path is active in SICF:
    SAP/BC/BSP/SAP/SMART_FORMS/DEFAULT.CSS
    If the above service is not activated,then activate that and re-test.
    Last option would be to implement the BADI BBP_OFFLINE_APP_BADI (method ~MAIL_DATA_GET) to remove the unwanted characters.
    BR,
    Disha.

  • My Mac won't read cyrillic in certain files and displays instead weird characters like this: "–í–µ-Ç–µ-Ä –ø-Ä–æ–¥–∏-Ä–∞–µ-Ç –¥–æ –∫–æ-Å-Ç–µ–π." Any ideas why this might be or how I can solve it?

    Yesterday I extracted the subtitles of an MKV file to try and print them. Unfortunately, when I open the .srt file with any text processor, it displays weird characters like the ones included in the title:
    "–û–±—ã–≤–∞—Ç–µ–ª–∏ –ø–µ—á–∞–ª—å–Ω—ã.
    –í–µ—Ç–µ—Ä –ø—Ä–æ–¥–∏—Ä–∞–µ—Ç –¥–æ –∫–æ—Å—Ç–µ–π."
    I thought this had to do with it being an .srt file, but just now I encountered the same problem with an Excel file.
    Any ideas why this might be or suggestions as to how to solve it?
    Thanks in advance,
    Mario

    It looks like an encoding problem.  You should try opening the file in a text editor where you can choose one of the various possible cyrillic encodings (utf-8, koi8-r, iso-8859-5, win-1251, MacCyrillic)

  • Square boxes instead of Japanese characters in pdf output of a crystal rep

    Hi All,
    Did anyone of you ever faced such an issue, where the pdf output of a crystal report shows square boxes instead of Japanese characters when the output is saved in pdf. However the crystal report output looks perfect. I have saved the ouput in xls and rtf formats the characters look perfect as required, the issue we have is when the output is saved as pdf.
    I have language pack installed on my machine.
    My guess is that the few Character's width is not sufficient and few Characters in other fields appear perfect in pdf. I have to test this, it might take few days before I can access this report. Before that I want to gather information. If anyone has solution to this issue please let me know.
    Thanks,
    Ravi

    Hi,
    Could you please answer the following questions
    1.What version of Crystal Reports are you using?
    Go to Help-> About to find out.
    2.What is the font you are using on the report?
    Try to change the font style to MS Gothic or Arial Unicode MS, most preferably MS Gothic.
    And export the report to PDF format.
    This may help you
    Thanks,
    Praveen G

  • The output of sql loader displays '?' for the chinese character

    I'm run the sql loader to import the data. The following is the ctl script:
    LOAD DATA
    CHARACTERSET ZHS16CGB231280
    APPEND
    INTO TABLE xxabc_gti_feedback
    when (5:6) ='~~' and (8:9)='~~'
    FIELDS TERMINATED BY "~~"
    TRAILING NULLCOLS
    absoluted
    ,exist_lists
    ,invoice_type
    ,invoice_category_code
    ,invoice_number
    ,line_count
    ,invoice_date DATE "YYYYMMDD"
    ,invoice_month
    ,trx_number
    ,amount_without_tax
    ,tax_rate
    ,tax_amount
    ,gti_feedback_id "xxban_gti_feedback_s.nextval"
    ,creation_date sysdate
    ,last_update_date sysdate
    EBS version: R12(12.0.4)
    The characterset of database is UTF-8
    The file characterset is GB2312
    The following is the example of data file.
    SJJK0201~~已开发票传出
    39~~20110413~~20110413
    //发票1
    0~~0~~0~~325676740~~11085979~~3~~20110413~~04~~~~3336.71~~0.17~~567.24~~珠海XX机电设备有限公司~~440407897878~~珠海市香洲区XXX 0756-3666666~~建行前山支行777777~~XX电子(苏州)有限公司~~32170078678890~~苏州工业园区 6267565~~中国银行园区支行25456672~~1653\n31263\n67126~~XXX~~XXX~~XXX
    0~~aaa~~P83782~~个~~2~~6854.70~~0.17~~1165.30~~4010~~1~~1601
    1~~bbb~~~~~~~~-4065.00~~0.17~~-691.05~~~~1~~1601
    0~~ccc~~P80792~~个~~4~~547.01~~0.17~~92.99~~160~~1~~1601
    I create a sql*loader concurrent program to load the data. the data can be loaded into the table successfully(The chinese customer name is correct). Only for the aborted lines, it will be listed in the outtput of the concurrent request, but out of my expect, the chinese characters in the output are displayed as '?'.
    How to solve the issue? Thanks.
    Edited by: 852938 on 2011-4-17 下午10:41

    like the following:
    SJJK0201~~??????????
    39~~20110413~~20110413
    //???1
    0~~aaa~~P83782~~??~~2~~6854.70~~0.17~~1165.30~~4010~~1~~1601
    1~~bbb~~~~~~~~-4065.00~~0.17~~-691.05~~~~1~~1601
    0~~ccc~~P80792~~??~~4~~547.01~~0.17~~92.99~~160~~1~~1601
    You can find that any chinese characters are became '?'. The loaded line(Line 4th) is not listed in the output.
    Thanks for your quick answer! :)

  • Weird characters in Ultrabeat

    Sorry if this has been posted elsewhere but I've recently started to get some weird characters when opening an Ultrabeat instrument (see attached screenshots).
    /Users/neilmorgan/Desktop/Screen shot 2010-12-27 at 16.53.59.png
    /Users/neilmorgan/Desktop/Screen shot 2010-12-27 at 16.54.56.png
    They're different each time and they seem not to affect the sound, but does anyone have any ideas of how to rid my system of them?
    Message was edited by: SwiftyM
    Message was edited by: SwiftyM
    Message was edited by: SwiftyM

    For instance, did you mean something like this:
    https://skitch.com/yorick75/rx46f/characters
    I've been getting those kind of 'weird characters' in the Ultrabeat pattern menu as well, but only recently. If that is the same case as yours, yes, it doesn't affect the sound or functionality of anything in Ultrabeat; however, it is annoying and a bit confusing when you want to choose a sample pattern or if you want to create a new one because the whole menu window looks 'jumbled up' with those odd characters. I have no idea what causes the display of these 'weird characters'. I would like to know if there's some way to fix this. Hopefully someone else has come upon this and might read this post too. By the way, in my case, this happens in Logic 8. So I don't know if anyone using Logic 9 has encountered a similar problem.

  • Weird characters in Hex viewer when i check a xml

    Hi,
    We are in the test phase sending messages to a customer of us. But when we send test messages the customer tells me that there are weird characters in the xml. It happens when we check the xml in a hexadecimal viewer. In the normal viewer of in a webbrowser
    we dont see these characters. He is a example of the situation:
    Look at the characters before the <?XML 
    So my question is how can i get rid of these characters?
    PS: these characters arent in the source files. 

    These characters are called the Byte Order Mark (BOM) and provided by/to the file system to indicate the encoding to be used when opening the file. You can read about it @http://en.wikipedia.org/wiki/Byte_order_mark
    And as Sumit has already mentioned, you can switch these ON/OFF based on the Pipeline Component properties. Even if you're using the default XMLTransmit, you can edit this property on the Specific Port.
    Regards.

  • Displaying the output from a java class executed from W/I another class

    I have compiled a java class, but I have run into a problem executing the class. I have read the posts and still have not solved the solution. I have tried to get the output of the Process by using "proc.getOutputStream().toString()", however it displays it in binary (ex. java.io.BufferOutputStream@48eb2067). If anyone can provide any assistance I would greatly appreciate it. Or if you could tell me if I'm on the right track or not. Thanks ALL. Here is a code segment:
    int truncStart = s.indexOf(".java");
                   s = s.substring(0,truncStart);
                   String[] command2 = {"java","c:/"+s};
                   try
                   //JOptionPane.showMessageDialog(null,"Exec. File "+s, "Exec. File : ",JOptionPane.ERROR_MESSAGE);
                   proc = Runtime.getRuntime().exec(command2);
                   JOptionPane.showMessageDialog(null,"Output: "+proc.getOutputStream().toString(),"Output"
    ,JOptionPane.ERROR_MESSAGE);
                   }

    You have to read the stream, like:
    InputStream stream = proc.getOutputStream();
    // now use methods on stream, such as read() to read the characters/lines - or wrap it in another line-friendly stream - see the java.io.* classes - keep reading until you get an end-of-stream indicator, depending on the API you end up using.

Maybe you are looking for

  • What is the appropriate data expiration / eviction scheme for the following scenario

    We currently have an expiration scheme through which data entries in cache-A get expired after the cache hits a certain size. The LRU entries are expired after the max threshold is reached. But the issue is that certain entries in the cache are rende

  • Update long text in notification

    Hi experts, I try to update (add next entry) to the long text in notification header. I tried with BAPI 'BAPI_ALM_NOTIF_DATA_ADD' to fill table NOTFULLTXT, but it seems that it can only add an entry and not append another one (one entry already exist

  • How do I hide a windows icon

    in Oracle 10g I want to hide the icon image of the windows. I want the windows shows only the title bar not the icon. Anyone can help me. Yeahia

  • Activate Add Row Menu

    Dear Experts, How to activate the Data->Add Row, Delete Row for User matrix in user form Regards, Mathi

  • Area range for particular area

    Hi all, Is it possible in ospf to generate summary address using area range command destined only for 1 particular area. Let say R1 is connected to 3 areas. Area 1 , 2 and 0. I want to summarize routes coming from area 1 and advertise them only in Ar