Keeps printing done...

I know why this code keeps printing done, its one my for loops. Currently this code does percisily what I want it to with a few hiccups that will be fixed. The current problem is that it keeps printing done for each row or record it places in the csv file. I need it to print to the file and then when it is truly done - print done. Also this is really slow....there are 1500+ records to pull from the cdata section, convert to comma delaminated and then place into the csv. the ripping and converting takes seconds. the writing's to the file takes .....well i never let it finish, every time I press stop its up to the 600th record and that's after a couple minutes.
I know I am missing something. I just need some eyes to look at it. its not the most efficient way to do this, I get that. All i care about right now is making it print done ONLY when it is truly DONE writing to the file - and it shouldn't take so long to write to a file. 600 records in 2 minutes? something is wrong.
Code is bellow. - prepare for a long read.
package xmlcsv;
import java.io.File;
import java.io.FileWriter;
import java.util.StringTokenizer;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.CDATASection;
import org.w3c.dom.CharacterData;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
* Essentially we take a xml file, find its cdata section and then
* process the information in there to then spit out to a csv file.
public class XmlCSV {
      * We need to process the data in the Cdata section and spit it out in a csv file.
      * This is the "main" part of the program which is run.
      * @param args
     public static void main(String[] args) throws Exception
          File file = new File("Data.xml");
          DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
          Document doc = db.parse(file);
          doc.getDocumentElement().normalize();
          NodeList nodes = doc.getElementsByTagName("TransmissionWrapper");
          for (int i = 0; i< nodes.getLength(); i++)
               Element element = (Element) nodes.item(i);
               NodeList cData = element.getElementsByTagName("TransmissionData");
               Element line = (Element) cData.item(0);
               //test
               getInfo(getCData(line));
      * We want to get all the data out of the CData Section.
      * Pass it into the getInfo() method to then get the
      * the data which will be parsed and thrown into a csv file.
      * @param e
      * @return
     private static final String getCData(Element e)
          NodeList child = e.getChildNodes();
          if (child != null)
               for (int i = 0; i< child.getLength(); i++)
                    Node childNode = child.item(i);
                    if (childNode.getNodeType() == Node.CDATA_SECTION_NODE)
                         CDATASection cdata = (CDATASection) childNode;
                         String data = cdata.getData();
                         return data;
          return "Theres nothing there";
      * We want to remove all pipes then replace all those pipes with commas
      * the simple .replace() does not work. so we pass all the data into a string array and
      * pass it to a method that reforms the data and replaces pipes with commas
      * TODO: I didn't realize some information is comma deliminated so we have:
      * CHEVROLET,COBALT which may pose a problem later.
      * @throws Exception
     private static final String getInfo(String str) throws Exception
          StringTokenizer st = new StringTokenizer(str.trim());
          while (st.hasMoreTokens())
               String[] info = str.split("\\|", -1);
               for(int i = 0; i<info.length; i++)
                    returnComma(info);
          return "Nothing to return";
      * We take the String array of data and reform it back into
      * a comma deliminated peice of data that we can then use with CSV
      * @param str
      * @return
      * @throws Exception
     private static final String returnComma(String[] str) throws Exception
          StringBuffer sb = new StringBuffer();
          for (int i =0; str != null && i < str.length; i++)
               sb.append(str);
               if(i < str.length - 1)
                    sb.append(",");
          writeToFile(sb.toString(), "data2.csv");
          return null;
     * Write the data to a csv file.
     * @param st
     * @param filename
     * @throws Exception
     private static final void writeToFile(String st, String filename) throws Exception
          FileWriter fw = new FileWriter(filename);
          fw.append(st);
          fw.flush();
          fw.close();
          System.out.println("done");

The question(s) is: +"How do I make it write to the file and print done only when done?"+Move the print statement out of the loop?
+"Why is it taking up to 5-10 minutes to write 600 records to a file when it takes 30 seconds to parse the pipes, and put commas in and spit it out to the page"?+Because you are writing to the file every time you call returnComma(), and you are calling returnComma() lots of times. Most probably your entire file writing scheme is up the pole. You can't really want the file just to contain whatever the last invocation of returnComma() printed, and if you do why do all the preceding writes at all?
Also returnComma() doesn't return a comma. Poor naming. Fix its name to describe what it really does.

Similar Messages

  • My printer keeps printing things on only 1/4 of the page

    I can not figure out how to print something correctly I guess. It keeps printing things only taking up 1/4 of the page..and it's driving me nuts! I can't figure out how to fix it. Help please?! =)

    This same thing is happening to me, I wish someone knew the answer to this problem.  I am only getting 1/4 of my documents printed.  Please help.. What will fix this?

  • HP laserjet 1536dnf MFP keeps Printing

    Hi Admin,
    I currently work as an IT Entry Level Support, and I have a problem with HP laserjet 1536dnf MFP  that I cannot give time to figure out why.
    Here's what I have:
    System: WXP Pro v2002 SP2
    Hardware: HP laserjet 1536dnf MFP
    Device Manager Driver: HP LJ M1530 Series Scan ; Driver Date: Nov 16, 2009
    HP laserjet 1536dnf MFP keeps printing JZJZL() and different Random Garbled characters, I can only print properly if I switch it on and Turn it on again.
    One more question: Is there a way to stop whatever is printing from the HP Toolbox.
    Thank you..
    This question was solved.
    View Solution.

    Hi @Claude-Antoine, 
    I understand that the printer is printing garbled print and something keeps printing off from the Toolbox. I can help you with this.
    Most likely the driver is corrupted and you will have to uninstall and reinstall the printer software.
    If you can print the hardware self test page properly, then it would be a software issue.
    Printing a Configuration Report.
    I have provided a document with some steps to try to see if that will resolve the issue.
    Resolving Strange, Garbled or Illogical Text, Incomplete Printouts, or Missing Text or Graphics.
    Here is the link for the newest drivers. HP LaserJet Full Feature Software and Driver.
    How is the printer connected? (USB/Ethernet)
    If your networked, do you have a Static IP setup and what kind of router are you using?
    If you need further assistance, just let me know.
    Have a nice day!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • HP Deskjet 710c printer don't work on a Mac Mini

    I have a Mac Mini with OSX 10.9 but my HP Deskjet 710c printer don't work. I install the HP driver package from Apple but I don't see my printer in the list. Who can help me out? Thanks.

    Hi,
    The printer is not supported on Mac OS X 10.9, you my find any supported printer listed in the following document:
    http://support.apple.com/kb/HT3669#HP
    As well no Mac supported is offered for the specific model within its driver download pages:
    http://h10025.www1.hp.com/ewfrf/wc/softwareCategor​y?cc=us&dlc=en&lc=en&product=59307&task=&
    I afraid you will not be able to use the specific model with Mavericks, those are not compatible.
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • Printer don't work at all "

    Hola! Hello! My first time here  ,so sorry if i not so good in inglish,My problem is the printer don't work at all ,and I have everything new in, the catrige, i also try every step that the screen show in Diagnose, and the last thin is help in cumunity .The light still flashing and the catrige is new ! I will thanks for you help ..Gary....

    There are two ways to go back to Leopard in your circumstances: Archive and install and erase and install. The best way to do it is the second, but your files will have to be backed up somewhere else. Archive and install is a good technique, in concept, but it goes against Apple's advice under your circumstances. If you do the first, then your files will end up in the proper place. Still, they should be backed up somewhere else. Something that should facilitate your choice is whether or not you have an external drive where you could create a bootable clone of your internal. Let me know about this matter specifically and what you think about the alternatives.

  • HP PSC 1510XI ALL IN ONE. ALIGNMENT PAPER KEEPS PRINTING AFTER I SCAN IT FOR A NEW CARTRIDGE

    ALIGNMENT PAPER KEEPS PRINTING WHEN I INSTALL A NEW CARTRIDGE..I SCAN THE PAPER AND EVERYTIME I TURN ON THE PRINTER, IT PRINTS AGAIN. I'M WASTING INK. HELP.

    I have the same printer with the same problem since I hooked it up to my HP G62 Laptop and installed the HP Scan Center (which replaced the old program console (name escapes me at the moment)).
    Every time I turn on the Laptop or switch users that irritating message to align the print cartridges comes up.
    I've tried immediately scanning the alignment page once it was printed and the program STILL wants me to align the cartridges. 
    What really gets me is that on the very same page that tells me to align the cartridges it says that the printer automatically aligns the cartridges when it's turned on - so why should it need to do so again when switching users?
    I never had this problem with the old console/software that the Scan Center replaced.
    Frustrating!

  • My photosmart C5280 keeps printing out blank photos

    Every time I try to print a colour photo on my Photosmart C5280 it comes out blank
    Jackser

    Hi @jackstrax,
    Welcome to the HP Forums!
    I understand that your HP Photosmart c5280 keeps printing blank photos. I am happy to help!
    Please see this post, Re: colour photos from my photosmart C5280 printer come out blank, by my colleague @Sunshyn2005.
    If the post does not resolve your issue, please call our phone support at 800-474-6836. If you live outside the US/Canada Region, please click the link below to get the support number for your region. Country-language selector.  
    Best of luck!
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • Prints don't match display - photosmart b8550 - skin tones have reddish tin

    when printing to photosmart b8550, the prints don't "color match" the display.
    skin tones especially have reddish tint. should the printer or iphoto control
    the colors?

    Welcome to the Apple Discussions. First I have to ask the obvious question: have you checked the levels in the various ink cartridges?
    Color control is very difficult. Unless you print from an application like Photoshop or Photoshop Elements where you can set the preferences to have the application control color the printer will usually have the control.
    What I would do is find a color image like this color image or this one and use it to run tests on regular paper, changing the various settings in the Print window till you get what you like. Then save those settings as a new preset.
    Do not use a color image file that has the Adobe RGB color profile. You want one with the standard sRGB or sRGB IEC1966-2.1.
    Also calibrate your monitor via the System/Displays preference pane. In the Print window menus there are a couple of panes for color management. Take a look at both, and others, to fine tune your setup.

  • HP Color LaserJet CP3525n keeps printing blank pages without stopping

    Hi, I'm having trouble with this printer, it keeps printing blank pages one after anotther as soon as it is turned on. Some pages are completely blank others have smiley faces and other characters on it. And it keeps doing this even after it has been restarted. Any idea how to fix this problem?

    1. take out all of the ink cartriges and look at the big black roller on the door for streaking, if streaking, clean with a lint free cloth dampened with windex (window cleaner) then close the door.
    2. let it run to initializing.
    3. open the door and look and the black roller on the door to see if you have streaking. If no streaking put one cartridge in and close the door and repeat the steps until you find what cartridge is causing the problem.
    I did this and found that my cyan was creating the lines on my paper. I cleaned the cyan roller with a Qtip and some rubbing alcohol and it works fine now, no more lines on the paper.
    Cheers

  • Color LaserJet 2605dn for wireless printing, it keeps printing the first page over & over

    When I use my Color LaserJet 2605dn for wireless printing, it keeps printing the first page over & over again.  I have to cancel print job on the printer in order to stop it.   It works properly on the computer that is directly wired to it, but won't on any other computer that I try to print from.   I have had this problem for some time, but now have certain thing that I must print from this printer & can't do it wirelessly.  It doesn't seem to be my network, because I can print from all of the other computers onto other wireless printers I have in the office.
    Any advice would be appreciated!

    Hello,
    Thanks for the post.  I've attached a link below that may assist.  Good Luck!
    http://h20000.www2.hp.com/bizsupport/TechSupport/Document.jsp?lang=en&cc=us&taskId=110&prodSeriesId=...
    I worked for HP but my posts and replies are my own....Thank you!
    *Say thanks by clicking the *Kudos!* which is on the left*
    *Make it easier for other people to find solutions, by marking my answer with (Accept as Solution) if it solves your issue.*

  • Windows 7 PC connected to HP printer via time capsule. Printer keeps printing the same page over and over

    I am using time capusle and have my husbands Windows 7 PC and my MacBook Pro connected to it. I just purchased a HP LaserJet P1606dn and have connected and printed to it succesfully using Bonjour on my MacBook.
    I have connected through Bonjour to the printer on the PC, but when I print a page, it keeps printing the page over an over. It stays in the que. I also set up my dual boot MacBook/Vista laptop and agai, I have no issues on the MacBook part, but it does the same thing on the Vista Machine as on the Windows 7.
    Does anyone have any ideas how to fix this?
    Thanks!

    Located a solution:
    Go to Control Panel - Printers ---  right click the printer and select Printer Properties.
    Select the PORTS tab and disable Bi-Directional Printer Support.    Seems to work whether the printer is installed either via USB or Cat5 to the Airport Extreme network.
    For HP printers, if that first fix doesn't work, download and install the HP Install Network Printer Wizard  - allow it to replace your 'newer' driver, but check hp.com for step by step instructions.
    Third suggested fix is to download a PCL6 driver, or a different model-driver altogether that is more generic than model specific.

  • Hp deskjet keeps printing alignment page

    Hi:
    Since i changed operating systems from WindowsXP32bit to Windows7 64bit, my printer keeps printing alignment pages. It will do it when i power on the printer, and it will do it after each printout. So far ive looked at HP's deskjet page. The HP Toolbox software isnt supported by Windows7, meaning that the handy print alignment and cartridge ink level software cant be used. I went to Hp's print alignment page ,they give you steps on what buttons to press on the printer to print an alignment page, to clean the printheads,print a print quality diagnostic page [which didnt work] ,and also to calibrate linefeed. I also cleaned the ink cartridges and removed any dry ink on them.
    None of that seemed to help. Does anyone know a solution to this? [this printer does not have a scanner by the way].
    I like this printer, and since theres no "windows7 compatible" HP inkjet printers available at this time, id like to keep this one.
    Thanking you

    The driver for the Deskjet 5150 is delivered though Windows Update as described here.  The Deskjet 5550  driver would also be compatible, I would recommend the HP version rather than the earlier Microsoft version.
    Bob Headrick,  HP Expert
    I am not an employee of HP, I am a volunteer posting here on my own time.
    If your problem is solved please click the "Accept as Solution" button ------------V
    If my answer was helpful please click the "Thumbs Up" to say "Thank You"--V

  • How to not keep printed documents

    I am basically trying to print some coupons from bricks.coupons and when I start to print it says that my preferences for my printer need to not save/keep printed documents.  I can't figure out how to change these preferences.  Help!!!

    I've never seen such a dialog with my printer or Mac OS, so it has to be either a feature of whatever software you installed for the coupon printing and/or your printer settings. You'll need to check both of those and look through all the possible options.

  • HP Officejet 4630 keeps printing a calender

    So my printer keeps printing weekly calenders and I can't stop it. Help!

    Hankthegreat wrote:
    So my printer keeps printing weekly calenders and I can't stop it. Help!
    Hi,
    Please use the first option first:
       http://support.hp.com/us-en/document/c03181888
    otherwise you have to try other option(s).
    Regards.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Safari keeps printing that I cannot use it to get and upgrade for OX 10.9.3

    Safari keeps printing that I cannot use it to get and upgrade OX 10.9.3?
    Yet nothing but Safari shows up on the upper left hand "Safari" word just next to an Apple logo.
    I have no way to do anything else as nothing else has or will come up on my screen.
    Just getting here involved a great deal of flickering of any images on each screen.
    What can I do next?
    Or what can you do to help my iMac upgrade to OX Mavericks or better?

    First, save and close any active documents, then all active applications you have started. If Safari will not close, find "Force Quit" under your Apple menu and close Safari that way.
    Now restart the computer.See if Safari is behaving.
    I just joined this community because Aplle screen demanded I show some group.
    Have no idea what that means either! These forums have been wacky since a major format change (I can;t call it and upgrade) about three weeks ago. You posted just fine--we can work with that.
    Another thought. Navigate this path: Macintosh HD > Applications. Find Safari and highlight it (single-click). Now press teh SPACE bar. What does it show for your version of Safari? If is says version 7.1, that is another issue we need to address.

Maybe you are looking for

  • Problem in this FM :SO_NEW_DOCUMENT_ATT_SEND_API1

    HI. I am doing a code for mail sending from ABAP to SOST and SBWP(SAP Inbox).Using the function module is SO_NEW_DOCUMENT_ATT_SEND_API1.mail is sending only for SBWP but it is not received in SOST,could you tell me how to find solution for this. Than

  • Sync error on apps

    Can anyone tell me what error OXE8003FFE is ? I am now all of a sudden unable to sync any of my apps ? every single one has this error. The usage bar at the bottom indicates they have all been synced and I have 125 apps on my iTouch but I only have t

  • How can I get my Blue Tooth Plantronics to see my IPad 1st Gen.

    Can someone pls tell me how to get my Plantronics Blue tooth to work with my IPad. I am having a difficult time getting it sync

  • Web Analysis rename utility

    "The Rename Utility is a stand-alone application designed to update objects in a Web Analysis repository based on the data source metadata changes." Where I can find this utility? Thanks all!

  • Hiding echo in sqlplus

    I am sorry to ask this trivial question but i need some help on this. I need to hide some displays from sqlplus so that the values echoed are not displayed. For example I want this ENTER USERNAME TO CHANGE TUNDE old 2: WHERE USERNAME ='&USER1' new 2: