Out.flush

We have a servlet whose service method is along these lines
          PrintWriter out = response.getWriter();
          [or ServletOutputStream out = response.getOutputStream();]
          out.println(someStuff);
          out.flush();
          [lots of heavy processing]
          The aim of which is to send a message to the user's screen so they don't
          have to wait for the processing to be finished. From what (little) I
          understand the out.flush should ensure that this happens, but it doesn't -
          the server doesn't respond until after the processing. (This happens whether
          we use the printwriter or the servletoutputstream)
          Does anyone have any idea why this doesn't work, or, perhaps more
          importantly, what would work.
          

Even if you got it to work, a proxy server or firewall could/would break it
          (due to the cache and collect implementations that most proxies do).
          Better to break the processing in two:
          1) The work to be done is assigned a uid or something similar to prevent it
          from being done twice
          2) The user presses the button which passes the uid in a hidden field (for
          example)
          3) The serlvet responds by kicking off the big process with jms and sends
          back a page that displays a "processing..." message and uses javascript to
          redirect (with a place to click just in case javascript is turned off)
          4) The url redirected to includes the uid to identify the process for which
          the result is desired
          5) When the process is completed, the information is placed in some known
          location (e.g. HttpSession or database) and the pending request to find the
          result can return the result
          Cameron Purdy
          [email protected]
          http://www.tangosol.com
          WebLogic Consulting Available
          "Terry" <[email protected]> wrote in message
          news:[email protected]...
          > We have a servlet whose service method is along these lines
          >
          > PrintWriter out = response.getWriter();
          > [or ServletOutputStream out = response.getOutputStream();]
          >
          > out.println(someStuff);
          > out.flush();
          > [lots of heavy processing]
          >
          >
          > The aim of which is to send a message to the user's screen so they don't
          > have to wait for the processing to be finished. From what (little) I
          > understand the out.flush should ensure that this happens, but it doesn't -
          > the server doesn't respond until after the processing. (This happens
          whether
          > we use the printwriter or the servletoutputstream)
          >
          > Does anyone have any idea why this doesn't work, or, perhaps more
          > importantly, what would work.
          >
          >
          >
          

Similar Messages

  • JDK 1.6_07 with Windows: System.out.flush() does not work...

    I wonder if this is a known issue: Since I upgrade the jdk1.6 version to the _07 pack, text IO does not work anymore with WinXP cmd.exe window. Assuming a static import of System.out, I use:
    static void prompt()
      out.print(pr); //pr is a prompt string...
      out.flush();
    }works as usual with Unix/Linux, but with windows nothing will be written to the terminal, until I make at least one input. In that case a barrage of cached prompts appear all at once.
    Do we have a bug for it, can we work around somehow?
    Thomas

    Since this code works correctly in Java 6u10 on Windows XP
    System.out.print("This is the data");
    System.out.flush();You are apparently doing something unusual or wrong. What is "out"?
    Show a small sample program that compiles and exhibits the problem when executed.

  • Strange problem with out.flush

    Code:
    package com.test.servlets;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.IOException;
    import java.io.PrintWriter;
    public class MultiThreadTest extends HttpServlet {
      public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {
        doPost(req,resp);
      public synchronized void  doPost(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException {
        PrintWriter out = resp.getWriter();
        out.println("<p align=center><b>Multi Thread Test</b></p>");
        out.flush();
        try {
          Thread.currentThread().sleep(10000);
        catch(InterruptedException ie) {
          ie.printStackTrace(out);
        out.println("<a href=MultiThreadTest>Multi Thread Test</a><br/>");
    }When i shield the out.fulsh() with "//"
    The ie println all the text at one time after the sleep time,
    So i use out.flush() to fulsh the text which before the sleep().
    Then,ie show the "<p align=center><b>Multi Thread Test</b></p>" and then after 10 seconds ,show the ""Multi Thread Test
    But the strange thing is ,this time, the ie shows:
    <p align=center><b>Multi Thread Test</b></p>
    <a href=MultiThreadTest>Multi Thread Test</a><br/>
    It displays the HTML source code,why?

    G'day mate,
    To the best of my knowledge doGet() and doPost() are both already multi-thread enabled, unless your application explicitly implements the "SingleThreaded" interface, which your code doesn't appear to do. As it is the servlet containers 'job' to handle threading issues I wouldn't expect to be able to override the doPost() method without getting strange output.
    I reckon your best bet would be to create a javabean from within doPost(), pass it the request and response objects and let it handle the timing...... also set doPost() back to it's default, otherwise only one request will be serviced at a time. If that is what you want to happen then implement the affore mentioned interface.
    Hope this helps.
    Regards
    Davo

  • Weblogic 10.3 SocketException at out.flush

    I have a server/jsp where I am doing out.flush().
    This throws following exception:
    java.net.SocketException: Connection reset by peer: socket write error
         at java.net.SocketOutputStream.socketWrite0(Native Method)
         at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
         at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
         at weblogic.servlet.internal.ChunkOutput.writeChunkNoTransfer(ChunkOutput.java:548)
         at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:505)
         at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:382)
         at weblogic.servlet.internal.CharsetChunkOutput.flush(CharsetChunkOutput.java:249)
         at weblogic.servlet.internal.ChunkOutputWrapper.flush(ChunkOutputWrapper.java:171)
         at weblogic.servlet.jsp.JspWriterImpl.flush(JspWriterImpl.java:98)
         at jsp_servlet._xxx.__yyy._jspService(__yyy.java:146)
         at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
    1. the problem is always reproducible.
    2. Not seen on other App Server.
    3. Not Seen on Mozilla. Have seen the problem with IE only.
    There are no user actions to stop/cancel the operation.
    Most of the times, the page is rendered correctly but we see this error in log.
    I have seen several posts where people have experienced this problem but no solution for it.

    The time-out you are getting is that related to a transaction?
    You can set the transaction time-out in the WebLogic console go to the JTA page for the domain, and change the value in the Timeout Seconds field.
    When you are using EJBs, you can also set the time-out on a EJB basis, instead of configuring the time-out for the whole domain.
    For example, in weblogic-ejb-jar.xml, you can configure the time-out by using:
    <weblogic-ejb-jar ...>
        <weblogic-enterprise-bean>
            <ejb-name>YOUR_EJB_NAME</ejb-name>
            <enable-call-by-reference>True</enable-call-by-reference>
            <stateless-session-descriptor>
                <pool>
                    <initial-beans-in-free-pool>25</initial-beans-in-free-pool>
                    <max-beans-in-free-pool>50</max-beans-in-free-pool>
                </pool>
            </stateless-session-descriptor>
            <transaction-descriptor>
                <trans-timeout-seconds>600</trans-timeout-seconds>
            </transaction-descriptor>
        </weblogic-enterprise-bean>
    </weblogic-ejb-jar>The transactions this EJB spawns can last for 10 minutes.

  • Out.flush() not working

    I can't get the out.flush to work. The page is paused until all values are finished then it is displayed. Here is my example code.
    <pre>
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class MyTest extends HttpServlet {
         public void init(ServletConfig conf) throws ServletException {
    super.init(conf);
    public void service(HttpServletRequest req, HttpServletResponse res)
    throws IOException {
    // res.setContentType("text/html"); //this nor the one below works
    res.setContentType("multipart/x-mixed-replace;boundary=\"boundary\"");
    PrintWriter out = res.getWriter();
    for(int x=0;x<3;x++){            
         out.println("<br>x = "+x);
         out.flush();
              try{
                        Thread.sleep(1000); //in milliseconds - 1000 milliseconds = 1 second
                   catch(InterruptedException ie){}
    </pre>

    You were hoping that the output of the servlet would be sent piece by piece to the client browser as you generated it? That is not how it works. Nothing is sent until you return from the service method. It is possible to do what I think you were hoping, but you have to work with the browser and have it refresh periodically. I have seen examples of that but I am not competent to try to explain it.

  • Jsp using out.flush() with no effect on Windows 7 IE9

    I have several JSPs with long running java code inside. To inform the user about the progress I use this html code
    &lt;div id=&quot;working&quot;&gt;
    Current row number: &lt;span id=&quot;rowNumber&quot;&gt;0&lt;/span&gt;&lt;br /&gt;
    Current row data: &lt;span id=&quot;rowData&quot;&gt;n/a&lt;/span&gt;&lt;br /&gt;
    &lt;/div&gt;
    and within my loop the js snippet to update the counter
    %>
              <script language=javascript>
                   document.getElementById("rowNumber").firstChild.nodeValue="<%=rowNumber%>";
                   document.getElementById("rowData").firstChild.nodeValue="<%=firstValue%>";
              </script>
    <%          out.flush();
    This works fine in IE8 on a Windows XP while the JSP is running on a Tomcat 6.0.10 on java 1.6. The user gets the counter updated after each flush(). This could be seen easily in the source code and the progress of the snippets coming from the JSP back to the client.
    Now we change to Windows 7 IE9 on the client (same server setup) and this behaviour doesn't work at all. The counter is never displayed, the browser source code is never updated on the out.flush(). For the user it looks like having no counter behaviour at all!
    It looks like the Win7 TCP/IP stack (or Java?) buffer the javascript snippets and therefore the browser could not render the counter.
    Has anybody an idea why this happens? And is there another trick to get a "counter" working with a long running jsp on Win 7?
    Best regards
    Edited by: 936263 on May 23, 2012 8:53 AM

    Hi,
    Does this driver apply to Windows 7? Maybe there is some compatibility issue, could you get a updated driver?
    Alex Zhao
    TechNet Community Support

  • Out.flush() inside f:view

    Hello all!
    On my JSF page I would like to post the page so far to the client (browser) on a specific point.
    The problem: calling out.flush() inside <f:view> results in Illegal to flush within a custom tagany idea?
    Marcus

    why do you call
    <% out.flush(); %> ?
    If you want just to send the page to the client you don't need to do this...
    This is enough...
    <html>
    <head><title>test</title></head>
    <body>
    <f:view>
    some content
    some other content
    </f:view>
    </body>
    </html>

  • Does out.flush() work in a JSP page without buffering?

              All:
              I am using WLS 4.51 and have found that it is not possible to flush the contents
              of the ServletOutputStream. I have seen this behavior in JSPs and Servlets.
              What I am trying to achieve is a simple status message that is displayed on the
              client for a long running transaction.
              TIA
              Brian
              

    Hi.
    You can use JSTL perfectly in ADF. I don't share the opinion of Oracle not recommends... there are a lot of official pages saying how to use JSTL in ADF.
    <af:outputText value="#{fn:length(yourList)}"/>Yannick is saying that you can't mix lifecycles. Take care using $ or # operators :).
    For example if you are using a JSTL c:forEach. Next code is going to crash:
    <c:forEach var="..." value="${list}">
       <af:outputText value="#{list.item}"/>
    </c:forEach>Because # is evaluated in prepareModel phase and $ while rendering.
    I hope this help you.

  • What does out.flush(); do?

    I can't find it in the API.

    what does toilet.flush(); do? same thingTo extend the analogy, is
    [url=http://java.sun.com/j2se/1.4.2/docs/api/java/io/Pr
    >
    ntWriter.html#PrintWriter(java.io.Writer,%20boolean)]Pr
    ntWriter's autoFlush like those smart toiletsthat sense when to flush?And are there any output streams or writers that have
    to be flushed twice like our toilet here at work?
    Well, fortunately, Java (and the TCP/IP stack) hide the plumbing from you, so no. Internally, there could be a reflush (packet loss resend).

  • System.out will not flush before input

    Hello everyone,
    I am using Netbeans 5.5, JDK6, and J2EE. I am new to the environment so I wrote a test application that would prompt a user to enter a string and then echo it. I have:
    String str = "";
    BufferedReader br = new BufferedReader(new nputStreamReader(System.in));
    System.out.print("Enter a string: ");
    System.out.flush();
    try
    str = br.readLine();
    catch(IOException ex)
    System.out.print(ex.toString());
    System.out.print(str);
    What is really bizarre is that System.out will NOT flush no matter what. My application will always ask for input before it even prompts the user for the string. This is what the output looks like when running:
    init:
    deps-jar:
    compile:
    run:
    hello
    Enter an string: hello
    BUILD SUCCESSFUL (total time: 5 seconds)
    Notice how I had to enter the string first? The only way that I have seen that it flushes is if I used println() instead of print. But what if I don't want the prompt to have an end line in it. This just seems like weird behavior. Also, I have tried using a Scanner for input and the results are the same. Not really sure what to do. Any help would be most appreciated. Thanks.

    are you running this inside netbeans as well? the "console" view in netbeans (and eclipse, and probably other IDEs) is not a real console, it's a GUI component that the IDE writes to. it's behaviour isn't guaranteed to act like a real console. I've seen this sort of thing on eclipse before, but never used netbeans. but it still stands that an IDE's console view isn't an actual console/terminal window. that may well be the root of the problem

  • Is there a way to flush out a socket's output stream without...

    ...having to close it (the stream)?
    I'm trying to implement a keep-alive feature in a simple HTTP Server application. This is a draft of the code I have trouble with:
    ==========
    //'clientSocket' is the socket obtained by the 'serverSocket.accept()' method
    OutputStream out = clientSocket.getOutputStream();
    //'message' is a string to be sent to the client
    InputStream data = new ByteArrayInputStream(message.getBytes());
    byte[] buff = new byte[2048];
    while (true)
    int read = data.read(buff, 0, 2048);
    if (read <= 0)
    break;
    out.write(buff, 0, read);
    out.flush();
    ==========
    If I don't call 'out.close()', the data will not be sent to the client.
    If I call 'out.close()', the data will be sent, but the socket will be closed too, which I don't want to. I need to be able to reuse that socket .
    Is there any way to properly push out the data to the client without having to close the output stream?

    ...having to close it (the stream)?Yes. OutputStream.flush(). But if you're not using any kind of buffered writer/output stream you don't even have to do that.
    If I don't call 'out.close()', the data will not be sent to the client.Untrue. The client will read everything that has been written If you don't close the output stream, the client will never get the EOS indication (e.g. read() returning -1). So if your client is looping until that happens it will loop forever ...
    Your problem at the moment is at the reading end.

  • I can't seem to Print out the Object I made in this Map. Any ideas?

    Well here's my problem I'm trying to print out the Key's and Value's associated in the following MutliMap.
    The code formating seems to screw up < and >. My datastructure is a Multi Map, the Key is a String Object and
    the Value associated with that String Key is an ArrayList of an object of type Message I defined below.
    Map<String,List<Message>> = new HashMap<String,List<Message>>();
    Here's my code for where I try to Print everything (in the function print() ) .
    The Print just either prints out the KEY and no value, if I take out my ((Message)value) cast, it will print the Message class, like
    43343@Message because I'm assuming its wondering how to Print something that is an object I defined.
    Thats why I defined my own print function and I also override the toString() function but both don't work it seems.
    package parser;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.io.*;
    //this class should store all the Messages or "Events" and
    //you can access them based on their Serial key.
    public class MessageDB
         //database to hold the information
         //     holds the Alerts/messages
         Map<String, List<Message>> AlertMap;
         //Constructor
         MessageDB()
              AlertMap = new HashMap<String, List<Message>>();
         //print, outputs the contents of the hashMap
         public void print()
            //want to print out the Key and all the Messages
              //associated with that key
              Set keys = AlertMap.keySet();          // The set of keys in the map.
              Iterator keyIter = keys.iterator();
              System.out.println("The map contains the following associations:");
              while (keyIter.hasNext()) {
                    Object key = keyIter.next();  // Get the next key.
                    Object value = AlertMap.get(key);  // Get the value for that key.
                    System.out.println( "Serial (key): " + key + "\n");
                    System.out.println("value: " + ((Message)value).toString() + "\n");
                    //((Message)value).print();
         //overloaded print to print to user screen.
         public  void print(PrintWriter out)
              //want to print out the Key and all the Messages
              //associated with that key
              Set keys = AlertMap.keySet();          // The set of keys in the map.
              Iterator keyIter = keys.iterator();
              out.println("The map contains the following associations:");
              out.flush();
              while (keyIter.hasNext()) {
                    Object key = keyIter.next();  // Get the next key.
                    Object value = AlertMap.get(key);  // Get the value for that key.
                   //out.flush();
                   /* out.println( "   (" + key + "," + value + ")" );
                   out.flush();*/
                   // out.println("------------------\n");
                   out.println("EntityID: " + key + "\n"
                                 + "Message: " + value + "\n");
                   //out.println("------------------\n");
                   out.flush();
         void add(Message msg)
              //getting the position of the List by EntityID if avaiable
              List<Message> AlertList = AlertMap.get(msg.Serial);
              //checking to see if there is a unique Key already in the Map.
              if (AlertList == null)
                   //if there isnt a key in the map, add a new key, and a new List mapping
                   //to the key EntityID;
                     AlertList = new ArrayList<Message>();
                     AlertMap.put(msg.Serial, AlertList);
                     AlertList.add(msg);
              else
              //adding message to List
                   AlertList.add(msg);
    }Here's my message class:
    package parser;
    //this class will hold the Event/Message
    import java.util.List;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.ArrayList;
    import java.util.Set;
    import java.util.Iterator;
    public class Message {
         String Identifer;
         String Serial;
         String Node;
         String NodeAlias;
         String Manager;
         String Agent;
         String AlertGroup;
         String AlertKey;
         String Severity;
         String Summary;
         String StateChange;
         String FirstOccurance;
         String LastOccurance;
         String InternalLast;
         String EventId;
         String LocalNodeAlias;
         Message()
               Identifer = "";
               Serial = "";
               Node = "";
               NodeAlias = "";
               Manager = "";
               Agent = "";
               AlertGroup = "";
               AlertKey = "";
               Severity = "";
               Summary = "";
               StateChange = "";
               FirstOccurance = "";
               LastOccurance = "";
               InternalLast = "";
               EventId = "";
               LocalNodeAlias = "";
         void print()
              System.out.println("Identifer: " + this.Identifer + '\n'
                        + "Serial: " + this.Serial + '\n'
                        + "Node: " + this.Node + '\n'
                        + "NodeAlias: " + this.NodeAlias + '\n'
                        + "Manager: "  + this.Manager + '\n'
                        + "Agent: " + this.Agent + '\n'
                        + "AlertGroup: " + this.AlertGroup + '\n'
                        + "AlertKey: " + this.AlertKey + '\n'
                        + "Severity: " + this.Severity + '\n'
                        + "Summary: " + this.Summary + '\n'
                        + "StateChange: " + this.StateChange + '\n'
                        + "FirstOccurance: " + this.FirstOccurance + '\n'
                        + "LastOccurance: " +      this.LastOccurance + '\n'
                        + "InternalLast: " + this.InternalLast + '\n'
                        + "EventId: " + this.EventId + '\n'
                        + "LocalNodeAlias: " + this.LocalNodeAlias + '\n');
         public String toString()
              return ("Identifer: " + this.Identifer + '\n'
                        + "Serial: " + this.Serial + '\n'
                        + "Node: " + this.Node + '\n'
                        + "NodeAlias: " + this.NodeAlias + '\n'
                        + "Manager: "  + this.Manager + '\n'
                        + "Agent: " + this.Agent + '\n'
                        + "AlertGroup: " + this.AlertGroup + '\n'
                        + "AlertKey: " + this.AlertKey + '\n'
                        + "Severity: " + this.Severity + '\n'
                        + "Summary: " + this.Summary + '\n'
                        + "StateChange: " + this.StateChange + '\n'
                        + "FirstOccurance: " + this.FirstOccurance + '\n'
                        + "LastOccurance: " +      this.LastOccurance + '\n'
                        + "InternalLast: " + this.InternalLast + '\n'
                        + "EventId: " + this.EventId + '\n'
                        + "LocalNodeAlias: " + this.LocalNodeAlias + '\n');
    }I'm correctly populating my Messages sent to me from the client, I tested it and it works but iterating over them once the messages are inserted into the map is my issue.
    I'm not getting an error, just no output for the values
    here's how I'm adding the Messages to the MessageDB
    //This string is coming from a client
    String str = in.readLine();
    // creating a scanner to parse
    Scanner scanner = new Scanner(str);
    Scanner scannerPop = new Scanner(str);
    //Creating a new message to hold information
    Message msg = new Message();
    //place Scanner object here:
    MessageParser.printTokens(scanner);
    MessageParser.populateMessage(scannerPop, msg);
    System.out.println("-------PRINTING MESSAGE------\n");
    msg.print();
    System.out.println("----------END PRINT----------\n");
    System.out.println("-------Accessing data from Map----\n");
    MessageDB testDB = new MessageDB();
    testDB.add(msg);
    testDB.print();I know this code is ugly, I should make accessor and modifer functions for my Message class but for now I'm just trying to see if I this method is even going to work then I'm going to go about making it more protected.
    Also here is my output:
    that long mess is the incoming string from the client, and im parsing it up into tokens and assigning my message object certain values.
    Address of server: 0.0.0.0/0.0.0.0
    Server is bound to port: 2222
    Echo :UPDATE: "GATEWAY:@barneyfifedisconnectedMon Jun 11 16:46:12
    2007",446,"barneyfife","","ConnectionWatch","","Gateway","GATEWAY:",0,"A
    GATEWAY process  running on barneyfife has disconnected as username
    gateway",06/11/07 16:50:12,06/11/07 16:46:12,06/11/07 16:46:12,06/11/07 16:46:12,0,1,1,0,0,"",65534,0,0,0,"",0,0,0,"","",0,0,"",0,"",0,0,"","","","","","","","",0,
    0,"","","NCOMS",446,""
    Token [0]UPDATE: "GATEWAY:@barneyfifedisconnectedMon Jun 11 16:46:12 2007"
    Token [1]446
    Token [2]"barneyfife"
    Token [3]""
    Token [4]"ConnectionWatch"
    Token [5]""
    Token [6]"Gateway"
    Token [7]"GATEWAY:"
    Token [8]0
    Token [9]"A GATEWAY process  running on barneyfife has disconnected as username gateway"
    Token [10]06/11/07 16:50:12
    Token [11]06/11/07 16:46:12
    Token [12]06/11/07 16:46:12
    Token [13]06/11/07 16:46:12
    Token [14]0
    Token [15]1
    Token [16]1
    Token [17]0
    Token [18]0
    Token [19]""
    Token [20]65534
    Token [21]0
    Token [22]0
    Token [23]0
    Token [24]""
    Token [25]0
    Token [26]0
    Token [27]0
    Token [28]""
    Token [29]""
    Token [30]0
    Token [31]0
    Token [32]""
    Token [33]0
    Token [34]""
    Token [35]0
    Token [36]0
    Token [37]""
    Token [38]""
    Token [39]""
    Token [40]""
    Token [41]""
    Token [42]""
    Token [43]""
    Token [44]""
    Token [45]0
    Token [46]0
    Token [47]""
    Token [48]""
    Token [49]"NCOMS"
    Token [50]446
    Token [51]""
    Entering populate mssage inside case 0
    case 0: UPDATE: "GATEWAY:@barneyfifedisconnectedMon Jun 11 16:46:12 2007"
    case 1: 446
    case 2: "barneyfife"
    case 3: ""
    case 4: "ConnectionWatch"
    case 5: ""
    case 6: "Gateway"
    case 7: "GATEWAY:"
    case 8: 0
    case 9: "A GATEWAY process  running on barneyfife has disconnected as username gateway"
    case 10: 06/11/07 16:50:12
    case 11: 06/11/07 16:46:12
    case 12: 06/11/07 16:46:12
    case 13: 06/11/07 16:46:12
    DEFAULT: 0
    DEFAULT: 1
    DEFAULT: 1
    DEFAULT: 0
    DEFAULT: 0
    DEFAULT: ""
    DEFAULT: 65534
    DEFAULT: 0
    DEFAULT: 0
    DEFAULT: 0
    case 24: ""
    DEFAULT: 0
    DEFAULT: 0
    DEFAULT: 0
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: 0
    DEFAULT: 0
    DEFAULT: ""
    DEFAULT: 0
    DEFAULT: ""
    DEFAULT: 0
    DEFAULT: 0
    case 37: ""
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: 0
    DEFAULT: 0
    DEFAULT: ""
    DEFAULT: ""
    DEFAULT: "NCOMS"
    DEFAULT: 446
    DEFAULT: ""
    -------PRINTING MESSAGE------
    Identifer: UPDATE: "GATEWAY:@barneyfifedisconnectedMon Jun 11 16:46:12 2007"
    Serial: 446
    Node: "barneyfife"
    NodeAlias: ""
    Manager: "ConnectionWatch"
    Agent: ""
    AlertGroup: "Gateway"
    AlertKey: "GATEWAY:"
    Severity: 0
    Summary: "A GATEWAY process  running on barneyfife has disconnected as username gateway"
    StateChange: 06/11/07 16:50:12
    FirstOccurance: 06/11/07 16:46:12
    LastOccurance: 06/11/07 16:46:12
    InternalLast: 06/11/07 16:46:12
    EventId: ""
    LocalNodeAlias: ""
    ----------END PRINT----------
    -------Accessing data from Map----
    The map contains the following associations:
    Serial (key): 446As you see it is printing the correct Serial, but it seems like it isn't even entering into the printing the value associated with that key.
    NOTE: if you need more code I can supply my parsing functions as well.
    Thanks!
    Message was edited by:
    lokie
    NOTE: the code formating screws up the < >
    it should be HashMap<String,List<Message>>();
    Message was edited by:
    lokie
    Message was edited by:
    lokie
    Message was edited by:
    lokie

    Thanks Good Idea :)
    Heres a small version of the same problem:
    MainTest
    package ds;
    public class MainTest {
         public static void main(String []args)
              //create a new message object, assign it some values.
              //note: Serial is the key to the map.
              Message m1 = new Message();
              m1.Identifer = "Test Message";
              m1.Serial = "222";
              m1.Agent = "AgentTest";
              m1.Identifer = "IdentiferTest";
              //test to see if it assigned right.
              m1.print();
              //insert into a map
              MessageDB dbTest = new MessageDB();
              dbTest.add(m1);
              //print key/values
              dbTest.print();
    }Here is the 2 classes that I use, Message and MessageDB.
    The problem is in the MesesageDB i'm getting the following error:
    Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to ds.Message
         at ds.MessageDB.print(MessageDB.java:43)
         at ds.MainTest.main(MainTest.java:28)
    package ds;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.Set;
    import java.io.*;
    //this class should store all the Messages or "Events" and
    //you can access them based on their Serial key.
    public class MessageDB
         //database to hold the information
         //     holds the Alerts/messages
         Map<String, List<Message>> AlertMap;
         //Constructor
         MessageDB()
              AlertMap = new HashMap<String, List<Message>>();
         //print, outputs the contents of the hashMap
         public void print()
            //want to print out the Key and all the Messages
              //associated with that key
              Set keys = AlertMap.keySet();          // The set of keys in the map.
              Iterator keyIter = keys.iterator();
              System.out.println("The map contains the following associations:");
              while (keyIter.hasNext()) {
                    Object key = keyIter.next();  // Get the next key.
                    Object value = AlertMap.get(key);  // Get the value for that key.
                    System.out.println( "Serial (key): " + key + "\n");
                    System.out.println("value: " + ((Message)value) + "\n");
                    //((Message)value).print();
         ///adds a message (value) to the map, along with the key.
         void add(Message msg)
              //getting the position of the List by EntityID if avaiable
              List<Message> AlertList = AlertMap.get(msg.Serial);
              //checking to see if there is a unique Key already in the Map.
              if (AlertList == null)
                   //if there isnt a key in the map, add a new key, and a new List mapping
                   //to the key EntityID;
                     AlertList = new ArrayList<Message>();
                     AlertMap.put(msg.Serial, AlertList);
                     AlertList.add(msg);
              else
              //adding message to List
                   AlertList.add(msg);
    }Here is the message class you'll need to use to compile:
    package ds;
         public class Message {
              String Identifer;
              String Serial;
              String Node;
              String NodeAlias;
              String Manager;
              String Agent;
              Message()
                    Identifer = "";
                    Serial = "";
                    Node = "";
                    NodeAlias = "";
                    Manager = "";
                    Agent = "";
              void print()
                   System.out.println("Identifer: " + this.Identifer + '\n'
                             + "Serial: " + this.Serial + '\n'
                             + "Node: " + this.Node + '\n'
                             + "NodeAlias: " + this.NodeAlias + '\n'
                             + "Manager: "  + this.Manager + '\n'
                             + "Agent: " + this.Agent + '\n');
              public String toString()
                   return ("Identifer: " + this.Identifer + '\n'
                             + "Serial: " + this.Serial + '\n'
                             + "Node: " + this.Node + '\n'
                             + "NodeAlias: " + this.NodeAlias + '\n'
                             + "Manager: "  + this.Manager + '\n'
                             + "Agent: " + this.Agent + '\n');
         }It doesn't like this line as I suspected:
    System.out.println("value: " + ((Message)value) + "\n");

  • A simple networking program, I can't figure out what's gone wrong

    hi, dear all, I programmed a simple server and client, I try to type some in client and see it on the server side, but the server doesn't show the input from client. Please help me out, thanks a lot.
    there are two classes, server and client.
    server class:
    import java.net.*;
    import java.io.*;
    public class test3 {
    /** Creates a new instance of test3 */
    public test3() {
    public static void main(String[] args) {
    try {
    ServerSocket server = new ServerSocket(5555);
    while (true) {
    Socket connection = server.accept( );
    try{
    // OutputStreamWriter out
    // = new OutputStreamWriter(connection.getOutputStream( ));
    // out.write("You've connected to this server.\r\n");
    // out.flush();
    InputStream in = connection.getInputStream( );
    StringBuffer input = new StringBuffer( );
    int c;
    // connection.close( );
    int i = 0;
    while(i < 10){
    while ((c = in.read( )) != -1) input.append((char) c);
    String inString = input.toString().trim( );
    System.out.println(inString);
    i++;
    catch (IOException e) {
    // This tends to be a transitory error for this one connection;
    // e.g. the client broke the connection early. Consequently,
    // we don't want to break the loop or print an error message.
    // However, you might choose to log this exception in an error log.
    /* finally {
    // Most servers will want to guarantee that sockets are closed
    // when complete.
    try {
    if (connection != null) connection.close( );
    catch (IOException e) {}
    catch (IOException e) {
    System.err.println(e);
    client class:
    import java.net.*;
    import java.io.*;
    public class test4{
    public static void main(String[] args){
    try{
    Socket theSocket = new Socket("192.168.1.102", 5555);
    OutputStream theOutputStream = theSocket.getOutputStream();
    OutputStreamWriter out = new OutputStreamWriter(theOutputStream);
    BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
    while (true) {
    String theLine = userIn.readLine( );
    if (theLine.equals(".")) break;
    System.out.println(theLine);
    out.write(theLine + "\r\n");
    out.flush( );
    // System.out.println(networkIn.readLine( ));
    }// end of while
    }// end of try
    catch (IOException e) {
    System.err.println(e);
    }// end of catch
    } // end of main
    } // end of test4
    Thanks again

    Well, i don't get the error to, but I use the DataOutputStream and DataInputStream or ObjectOutputStream and ObjectInputStream with the I/O connection.
    the basic steps at the server are:
    1) create new ServerSocket
    2) Waiting for a connection
    3) Create a I/O Stream
    4) Process the job
    5) close the connection
    at the client are:
    1) connect to the server
    2) Create a I/o stream
    3) process the job
    4) close the connection
    Maybe you can send what the specify error you get in your code

  • Out.println() problems with large amount of data in jsp page

    I have this kind of code in my jsp page:
    out.clearBuffer();
    out.println(myText); // size of myText is about 300 kbThe problem is that I manage to print the whole text only sometimes. Very often happens such that the receiving page gets only the first 40 kb and then the printing stops.
    I have made such tests that I split the myText to smaller parts and out.print() them one by one:
    Vector texts = splitTextToSmallerParts(myText);
    for(int i = 0; i < texts.size(); i++) {
      out.print(text.get(i));
      out.flush();
    }This produces the same kind of result. Sometimes all parts are printed but mostly only the first parts.
    I have tried to increase the buffer size but neither that makes the printing reliable. Also I have tried with autoFlush="false" so that I flush before the buffer size gets overflowed; again same result, sometimes works sometimes don't.
    Originally I use such a system where Visual Basic in Excel calls a jsp page. However, I don't think that this matters since the same problems occur if I use a browser.
    If anyone knows something about problems with large jsp pages, I would appreciate that.

    Well, there are many ways you could do this, but it depends on what you are looking for.
    For instance, generating an Excel Spreadsheet could be quite easy:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class TableTest extends HttpServlet{
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
              response.setContentType("application/xls");
              PrintWriter out = new PrintWriter(response.getOutputStream());
                    out.println("Col1\tCol2\tCol3\tCol4");
                    out.println("1\t2\t3\t4");
                    out.println("3\t1\t5\t7");
                    out.println("2\t9\t3\t3");
              out.flush();
              out.close();
    }Just try this simple code, it works just fine... I used the same approach to generate a report of 30000 rows and 40 cols (more or less 5MB), so it should do the job for you.
    Regards

  • Writing out to file - and it seems to overwrite data

    I have written a program that reads in a file and then writes out XML. It works fine with small files but with files that are 1,310 kb it, seems to overwrite itself and i end up with a file that is missing its begining and middle pieces. I suspect that I am blowing out some buffer and a java component is reseting itself and overwriting the file, but i am scratching my head. Code below, please excuse the unformatted nature of the code.
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.*;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class dl414image {
    public static String all = "";
    public static String fname = "";
    public static String lname = "";
    public static String mname = "";
    public static boolean aflag = false;
    public static boolean endofrec = false;
    public static boolean bflag = false;
    public static boolean cflag = false;
    public static boolean dflag = false;
    public static String xmldl;
    public static String xmlreq;
    public static String xml_issue_date;
    public static String xml_first_name;
    public static String xml_middle_name;
    public static String xml_last_name;
    public static String xml_dmvinfo;
    public static String xmlbday;
    public static String xmlsex;
    public static String xmlheight;
    public static String xmlweight;
    public static String xmleyecolor;
    public static String xmlhaircolor;
    public static String xml_licenseclass;
    public static String xml_licenseclassname;
    public static String xml_licenseissuedate;
    public static String xml_licenseexpiresdate;
    public static String dlstart = "<dlnumber>";
    public static String dlend = "</dlnumber>";
    public static String xmlreqstart = "<requestor_code>";
    public static String xmlreqend = "</requestor_code>";     
    public static String issue_date_start = "<issue_date>";
    public static String xml_issue_date_end = "</issue_date>";
    public static int count = 0;
    public static List<String> xml_abstractline = new ArrayList<String>();
    public static List<String> xml_cline = new ArrayList<String>();
    public static List<String> xml_dline = new ArrayList<String>();
    public static List<String> xml_acontinuedline = new ArrayList<String>();
    public static String dlold; // holds the previous DL number
    public static final String HEX_EXP = "[\\xFF]";
    public static final String CDATASTART = " <![CDATA[";
    public static final String CDATAEND = "]]>";
    public static String xmlfobates = "";
    public static String xmltypeappdate = "";
    public static String xml_licenseext;
    public static String xml_licenserestrict;
    public static String xml_licensedup;
    public static String xml_licenseheld;
    public static String xml_licenseseq;
    public static List<String> xml_abstract_item = new ArrayList<String>();
    public static List<String> xml_abstract_violationdate = new ArrayList<String>();
    public static List<String> xml_abstract_convictdate = new ArrayList<String>();
    public static List<String> xml_abstract_sectviolated = new ArrayList<String>();
    public static List<String> xml_abstract_statute = new ArrayList<String>();
    public static List<String> xml_abstract_file_number = new ArrayList<String>();
    public static List<String> xml_abstract_location_or_arn = new ArrayList<String>();
    public static List<String> xml_abstract_vehicle_license = new ArrayList<String>();
    public static final String ABST = "ABST";
    public static List<String> xml_reqNameAddress = new ArrayList<String>();
         /**<p>
         * This code reads in a file line by line
         * with BufferedReader and processes each
         * line.
         * @author Toren Valone
         public static void main(String[] args) {
              read("U:\\dlbig.txt"); //read this file
    //     convenience method to encapsulate
    //     the work of reading data.
         public static void read(String fileName) {
              xmlwriter("<?xml version=\"1.0\"?>");
              xmlwriter("<?xml-stylesheet type=\"text/xsl\" href=\"dl414.xsl\"?>" );
              xmlwriter("<dl_records>"); //write base element start tag
         try {
         BufferedReader in = new BufferedReader(
         new FileReader(fileName));
         String line;
         while ((line = in.readLine()) != null) {
              String cleanline = stripNonValidXMLCharacters(line);
         //our own method to do something
         handle(cleanline);
         //count each line
         count++;
         in.close();
         //show total at the end of file
         log("Lines read: " + count);
         } catch (IOException e) {
         log(e.getMessage());
         dlxmlwriter(); //final write for process
              xmlwriter("</dl_records>"); //write base element end tag
    //     does the work on every line as it is
    //     read in by our read method
         private static void handle(String line){
              if(line.length()> 0) {
              char fbyte = line.charAt(0);
              if(fbyte == 'A') {
              //just grab the very first dl
              if(count == 0) {
              dlold = line.substring(3,11);
              aflag = true;
              cflag = false;
              dflag = false;
              if(dlold.equalsIgnoreCase(line.substring(3,11))) {
              } else {
                   dlxmlwriter();
              //create Drivers License XML
                   xmldl = dlstart + line.substring(3,11) + dlend;
                   //grab f.o bates no only if its there otherwise write empty xml
              xmlfobates = "<fobates>" + line.substring(12,19) + "</fobates>";
              //grab type app and date
              xmltypeappdate = "<typeappdate>" + line.substring(20,28) + "</typeappdate>";
                   //Create Requestor code XML
              xmlreq = xmlreqstart + line.substring(51,56) + xmlreqend;
              //Create issue date XML
              xml_issue_date = issue_date_start + line.substring(57,63) + xml_issue_date_end;
              // clear name values, for now too stupid to figure out
              fname = "";
              mname = "";
              lname = "";     
              //Pulls the whole name string and sends it to namer function
              //to break up
              String name = line.substring(72);
              namer(name);
              //Create a string array and call get_Names which returns a
              //string array
              xml_first_name = "<first_name>" + fname + "</first_name>";
              xml_middle_name = "<middle_name>" + mname + "</middle_name>";
              xml_last_name = "<last_name>" + lname + "</last_name>";
                   //store Dl for comparison
                   store_old_dl(line);
              //Accent a and a length of 59 or 102 contains
              //the dmv info line
              if((fbyte == '?')& (line.length() == 59)){
                   String cleandmvinfo = regexReplacer(line.substring(38,58),"//","");
                   xml_dmvinfo = "<dmv_info_line>" + cleandmvinfo + "</dmv_info_line>";
              //Line length of 33 Birthdate, Sex, Height, Weight
              //Eye color hair color
              if ((line.length() == 33 ) & (aflag == true)) {
                   xmlbday = "<birth_date>" + line.substring(3, 9) + "</birth_date>";
                   xmlsex = "<sex>" + line.substring(11,12) + "</sex>";
                   xmlheight = "<height>" + line.substring(14,17) + "</height>";
                   xmlweight = "<weight>" + line.substring(18,21) + "</weight>";
                   xmleyecolor = "<eye_color>" + line.substring(22,27) + "</eye_color>";
                   xmlhaircolor = "<hair_color>" + line.substring(28,line.length()) + "</hair_color>";
    //Line length of 35 Birthdate, Sex, Height, Weight
              //Eye color hair color
              if ((line.length() == 31     ) & (aflag == true)) {
                   xmlbday = "<birth_date>" + line.substring(3, 9) + "</birth_date>";
                   xmlsex = "<sex>" + line.substring(11,12) + "</sex>";
                   xmlheight = "<height>" + line.substring(14,17) + "</height>";
                   xmlweight = "<weight>" + line.substring(18,21) + "</weight>";
                   xmleyecolor = "<eye_color>" + line.substring(22,27) + "</eye_color>";
                   xmlhaircolor = "<hair_color>" + line.substring(28,31) + "</hair_color>";
    // Line length of 56 Birthdate, Sex, Height, Weight
              //Eye color hair color for Annual reports
              if ((line.length() == 56     ) & (aflag == true)) {
                   xmlbday = "<birth_date>" + line.substring(3, 9) + "</birth_date>";
                   xmlsex = "<sex>" + line.substring(11,12) + "</sex>";
                   xmlheight = "<height>" + line.substring(14,17) + "</height>";
                   xmlweight = "<weight>" + line.substring(18,21) + "</weight>";
                   xmleyecolor = "<eye_color>" + line.substring(22,27) + "</eye_color>";
                   xmlhaircolor = "<hair_color>" + line.substring(28,31) + "</hair_color>";
              //If the line has an accent a and a length of 6
              if ((fbyte == '?')& (line.length() == 6)) {
              xml_licenseclass = "<license_class>" + line.substring(5,6) + "</license_class>";
              if ((fbyte == '?')& (line.length() == 8)) {
                   String cleanlc = regexReplacer(line.substring(4,8),"&","&");
                   xml_licenseclass = "<license_class>" + cleanlc + "</license_class>";
              if((line.length() == 61) & aflag==true) {
                   xml_licenseclassname = "<license_class_name>" + line.substring(3,9) + "</license_class_name>";
                   xml_licenseissuedate = "<license_issue_date>" + line.substring(9,16) + "</license_issue_date>";
                   xml_licenseexpiresdate = "<license_expires_date>" + line.substring(16,23) + "</license_expires_date>";
                   xml_licenseext = "<license_ext>" + line.substring(23,26) + "</license_ext>";
                   xml_licenserestrict = "<license_restrict>" + line.substring(26,37) + "</license_restrict>";          
                   xml_licensedup = "<license_dup>" + line.substring(38,43) + "</license_dup>";
                   xml_licenseheld = "<license_held>" + line.substring(44,44) + "</license_held>";
                   xml_licenseseq = "<license_seq>" + line.substring(57,61) + "</license_seq>";
              if(fbyte == 'B') {
                   bflag = true;
                   aflag = false; //ok got the a now turn switch off
                   String cleanabstract = regexReplacer(line.substring(1,line.length()),HEX_EXP,"");
                   cleanabstract = regexReplacer(cleanabstract,"&","&");
                   cleanabstract = regexReplacer(cleanabstract,"&","&apos;");
              if(cleanabstract.substring(3, 7).equalsIgnoreCase("ABST")){
                   if(cleanabstract.length() == 107) {               
                        xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,8) + "</abstract_item>");
                   xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                   xml_abstract_convictdate.add("<abs_convict_date>" + cleanabstract.substring(15,21) + "</abs_convict_date>");
                   xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                   xml_abstract_statute.add("<abs_statute>" + cleanabstract.substring(42,46) + "</abs_statute>");
                   xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,79) + "</abs_file_number>");
                   xml_abstract_location_or_arn.add("<abs_location_or_arn>" + cleanabstract.substring(79,99) + "</abs_location_or_arn>");
                   xml_abstract_vehicle_license.add("<abs_vehicle_license>" + cleanabstract.substring(100,107) + "</abs_vehicle_license>");               
                   if(cleanabstract.length() > 80 & cleanabstract.length() < 107) {               
                        xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,8) + "</abstract_item>");
                   xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                   xml_abstract_convictdate.add("<abs_convict_date>" + cleanabstract.substring(15,21) + "</abs_convict_date>");
                   xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                   xml_abstract_statute.add("<abs_statute>" + cleanabstract.substring(42,51) + "</abs_statute>");
                   xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,79) + "</abs_file_number>");
                   xml_abstract_location_or_arn.add("<abs_location_or_arn>" + cleanabstract.substring(79,cleanabstract.length()) + "</abs_location_or_arn>");
                   if(cleanabstract.length() < 80) {
                   System.out.println("****Change your assumtions about length*********");     
                        xml_abstractline.add("<abstract>" + cleanabstract + "</abstract>");
              if(cleanabstract.substring(3, 6).equalsIgnoreCase("ACC")){
                   if(cleanabstract.length() < 107) {
                        System.out.println("Acc looks like!!!" + cleanabstract);
                        System.out.println("Acc length=" + cleanabstract.length());
                   if(cleanabstract.length() > 102) {               
                             xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,6) + "</abstract_item>");
                        xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                        xml_abstract_convictdate.add("<abs_convict_date>" + " " + "</abs_convict_date>");
                        xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                        xml_abstract_statute.add("<abs_statute>" + " " + "</abs_statute>");
                        xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,79) + "</abs_file_number>");
                        xml_abstract_location_or_arn.add("<abs_location_or_arn>" + cleanabstract.substring(79,99) + "</abs_location_or_arn>");
                        xml_abstract_vehicle_license.add("<abs_vehicle_license>" + cleanabstract.substring(100,cleanabstract.length()) + "</abs_vehicle_license>");               
                   if((cleanabstract.length() > 77 ) & cleanabstract.length() < 102) {               
                             xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,6) + "</abstract_item>");
                        xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                        xml_abstract_convictdate.add("<abs_convict_date>" + " " + "</abs_convict_date>");
                        xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                        xml_abstract_statute.add("<abs_statute>" + " " + "</abs_statute>");
                        xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,cleanabstract.length()) + "</abs_file_number>");
                        xml_abstract_location_or_arn.add("<abs_location_or_arn>" + "</abs_location_or_arn>");
                        xml_abstract_vehicle_license.add("<abs_vehicle_license>" + "</abs_vehicle_license>");               
              if((fbyte == ' ') & (bflag == true)) {
                   String cleanabstract = regexReplacer(line.substring(1,line.length()),HEX_EXP,".");
                   cleanabstract = regexReplacer(cleanabstract,"&","&");
                   cleanabstract = regexReplacer(cleanabstract,"'","&apos;");
                   if(cleanabstract.substring(3, 7).equalsIgnoreCase("ABST")){
                             if(cleanabstract.length() == 107) {               
                                  xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,8) + "</abstract_item>");
                             xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                             xml_abstract_convictdate.add("<abs_convict_date>" + cleanabstract.substring(15,21) + "</abs_convict_date>");
                             xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                             xml_abstract_statute.add("<abs_statute>" + cleanabstract.substring(42,51) + "</abs_statute>");
                             xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,79) + "</abs_file_number>");
                             xml_abstract_location_or_arn.add("<abs_location_or_arn>" + cleanabstract.substring(79,99) + "</abs_location_or_arn>");
                             xml_abstract_vehicle_license.add("<abs_vehicle_license>" + cleanabstract.substring(100,107) + "</abs_vehicle_license>");               
                             if(cleanabstract.length() > 93 & cleanabstract.length() < 107) {               
                                  xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,8) + "</abstract_item>");
                             xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                             xml_abstract_convictdate.add("<abs_convict_date>" + cleanabstract.substring(15,21) + "</abs_convict_date>");
                             xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                             xml_abstract_statute.add("<abs_statute>" + cleanabstract.substring(42,51) + "</abs_statute>");
                             xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,79) + "</abs_file_number>");
                             xml_abstract_location_or_arn.add("<abs_location_or_arn>" + cleanabstract.substring(79,cleanabstract.length()) + "</abs_location_or_arn>");
                             xml_abstract_vehicle_license.add("<abs_vehicle_license>" + "</abs_vehicle_license>");               
                   if(cleanabstract.substring(3, 6).equalsIgnoreCase("ACC")){
                             if(cleanabstract.length() > 102) {               
                                       xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,6) + "</abstract_item>");
                                  xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                                  xml_abstract_convictdate.add("<abs_convict_date>" + " " + "</abs_convict_date>");
                                  xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                                  xml_abstract_statute.add("<abs_statute>" + " " + "</abs_statute>");
                                  xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,79) + "</abs_file_number>");
                                  xml_abstract_location_or_arn.add("<abs_location_or_arn>" + cleanabstract.substring(79,99) + "</abs_location_or_arn>");
                                  xml_abstract_vehicle_license.add("<abs_vehicle_license>" + cleanabstract.substring(100,cleanabstract.length()) + "</abs_vehicle_license>");               
                             if((cleanabstract.length() > 77 ) & cleanabstract.length() < 102) {               
                                       xml_abstract_item.add("<abstract_item>" + cleanabstract.substring(3,6) + "</abstract_item>");
                                  xml_abstract_violationdate.add("<abs_violation_date>" + cleanabstract.substring(8,14) + "</abs_violation_date>");
                                  xml_abstract_convictdate.add("<abs_convict_date>" + " " + "</abs_convict_date>");
                                  xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                                  xml_abstract_statute.add("<abs_statute>" + " " + "</abs_statute>");
                                  xml_abstract_file_number.add("<abs_file_number>" + cleanabstract.substring(67     ,cleanabstract.length()) + "</abs_file_number>");
                                  xml_abstract_location_or_arn.add("<abs_location_or_arn>" + "</abs_location_or_arn>");
                                  xml_abstract_vehicle_license.add("<abs_vehicle_license>" + "</abs_vehicle_license>");               
                   if(cleanabstract.length() == 46) {
                   if(cleanabstract.substring(22, 25).equalsIgnoreCase("CDL") & cleanabstract.length() == 46) {
                   xml_abstract_item.add("<abstract_item>" + "</abstract_item>");
                        xml_abstract_violationdate.add("<abs_violation_date>" + "</abs_violation_date>");
                        xml_abstract_convictdate.add("<abs_convict_date>" + "</abs_convict_date>");
                        xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,43) + "</abs_section_violated>");
                        xml_abstract_statute.add("<abs_statute>" + cleanabstract.substring(42,cleanabstract.length()) + "</abs_statute>");
                        xml_abstract_file_number.add("<abs_file_number>" + "</abs_file_number>");
                        xml_abstract_location_or_arn.add("<abs_location_or_arn>" + "</abs_location_or_arn>");
                        xml_abstract_vehicle_license.add("<abs_vehicle_license>" + "</abs_vehicle_license>");               
                   if(cleanabstract.length()> 39 & cleanabstract.length() < 43     ) {
                   if(cleanabstract.substring(22, 25).equalsIgnoreCase("DMV")) {
                        System.out.println("DMV length=" + cleanabstract.length());
                        xml_abstract_item.add("<abstract_item>" + "</abstract_item>");
                        xml_abstract_violationdate.add("<abs_violation_date>" + "</abs_violation_date>");
                        xml_abstract_convictdate.add("<abs_convict_date>" + "</abs_convict_date>");
                        xml_abstract_sectviolated.add("<abs_section_violated>" + cleanabstract.substring(22,cleanabstract.length()) + "</abs_section_violated>");
                        xml_abstract_statute.add("<abs_statute>" + "</abs_statute>");
                        xml_abstract_file_number.add("<abs_file_number>" + "</abs_file_number>");
                        xml_abstract_location_or_arn.add("<abs_location_or_arn>" + "</abs_location_or_arn>");
                        xml_abstract_vehicle_license.add("<abs_vehicle_license>" + "</abs_vehicle_license>");               
                   xml_abstractline.add("<abstract>" + cleanabstract + "</abstract>");
              if(fbyte == 'C') {
                   //turn b flag off
                   aflag = false;
                   bflag = false;
                   cflag = true;
                   String cleancomment = regexReplacer(line.substring(1,line.length()),HEX_EXP,"");     
                   cleancomment = regexReplacer(cleancomment,"&","&");
                   cleancomment = regexReplacer(cleancomment,"'","&apos;");
                   xml_cline.add("<comment_line>" + cleancomment.substring(1,63) + "</comment_line>");
                   xml_reqNameAddress.add("<requestor_name_or_address>" + cleancomment.substring(63,cleancomment.length()) + "</requestor_name_or_address>");
                   System.out.println("In C code dl=" + xmldl + "aflag=" + aflag +"bflag=" + bflag + "cflag=" + cflag);           
              if((fbyte == ' ') & (cflag == true)){
                   String cleancomment = regexReplacer(line.substring(1,line.length()),HEX_EXP,"");     
                   cleancomment = regexReplacer(cleancomment,"&","&");
                   if(cleancomment.length() > 63) {
              xml_reqNameAddress.add("<requestor_name_or_address>" + cleancomment.substring(63,cleancomment.length()) + "</requestor_name_or_address>");
              xml_cline.add("<comment_line>" + cleancomment.substring(1, 63) + "</comment_line>");
                   } else {
                        xml_cline.add("<comment_line>" + cleancomment.substring(1, cleancomment.length()) + "</comment_line>");
              if(fbyte == 'D') {
                   xml_dline.add("<action>" + line.substring(1, line.length()) + "</action>");
                   dflag = true;
                   cflag = false;
                   System.out.println("In d code dl=" + xmldl + "aflag=" + aflag +"bflag=" + bflag + "cflag=" + cflag + "dflag=" + dflag);
              } // ends d if
              //If D line sets it to true then this will never run
              if((fbyte == ' ') & (dflag == true)) {
                   xml_dline.add("<action>" + line.substring(1, line.length()) + "</action>");
              }     //end if line length greater than zero
         }// ends handle     
         public static void store_old_dl(String line) {
              dlold = line.substring(3,11);
         public static void dlxmlwriter(){
    xmlwriter("<dl_record>");
         xmlwriter(xmldl);
         xmlwriter(xmlfobates);
         xmlwriter(xmltypeappdate);
         xmlwriter(xmlreq);
         xmlwriter(xml_issue_date);
         xmlwriter(xml_first_name);
         xmlwriter(xml_middle_name);
         xmlwriter(xml_last_name);
         xmlwriter(xml_dmvinfo);
         xmlwriter(xmlbday);
         xmlwriter(xmlsex);
         xmlwriter(xmlheight);     
         xmlwriter(xmlweight);
         xmlwriter(xmleyecolor);
         xmlwriter(xmlhaircolor);
         xmlwriter(xml_licenseclass);
         xmlwriter(xml_licenseclassname);
         xmlwriter(xml_licenseissuedate);
         xmlwriter(xml_licenseexpiresdate);
         xmlwriter(xml_licenseext);
         xmlwriter(xml_licenserestrict);
         xmlwriter(xml_licensedup);
         xmlwriter(xml_licenseheld);
         xmlwriter(xml_licenseseq);
         int a = 0;
         while (a < xml_abstractline.size()) {
              xmlwriter(xml_abstractline.get(a).toString());
              a++;
         int a1 = 0;
         while (a1 < xml_abstract_item.size()) {
              xmlwriter(xml_abstract_item.get(a1).toString());
              a1++;
         int a2 = 0;
         while (a2 < xml_abstract_violationdate.size()) {
              xmlwriter(xml_abstract_violationdate.get(a2).toString());
              a2++;
         int a3 = 0;
         while (a3 < xml_abstract_convictdate.size()) {
              xmlwriter(xml_abstract_convictdate.get(a3).toString());
              a3++;
         int a4 = 0;
         while (a4 < xml_abstract_sectviolated.size()) {
              xmlwriter(xml_abstract_sectviolated.get(a4).toString());
              a4++;
         int a5 = 0;
         while (a5 < xml_abstract_statute.size()) {
              xmlwriter(xml_abstract_statute.get(a5).toString());
              a5++;
         int a6 = 0;
         while (a6 < xml_abstract_file_number.size()) {
              xmlwriter(xml_abstract_file_number.get(a6).toString());
              a6++;
         int a7 = 0;
         while (a7 < xml_abstract_location_or_arn.size()) {
              xmlwriter(xml_abstract_location_or_arn.get(a7).toString());
              a7++;
         int a8 = 0;
         while (a8 < xml_abstract_vehicle_license.size()) {
              xmlwriter(xml_abstract_vehicle_license.get(a8).toString());
              a8++;
         int d = 0;
         while (d < xml_cline.size()) {
              xmlwriter(xml_cline.get(d).toString());
              d++;
         int e = 0;
         while (e < xml_dline.size()) {
              xmlwriter(xml_dline.get(e).toString());
              e++;
         int f = 0;
         while (f < xml_reqNameAddress.size()) {
              xmlwriter(xml_reqNameAddress.get(f).toString());
              f++;
         dflag = false;
         //writes the entag for dlnumber and dl record
    xmlwriter("</dl_record>");
         xml_abstractline.clear();
         xml_cline.clear();
         xml_dline.clear();
         xml_abstract_item.clear();
         xml_abstract_violationdate.clear();
         xml_abstract_convictdate.clear();
         xml_abstract_sectviolated.clear();
         xml_abstract_statute.clear();
         xml_abstract_file_number.clear();
         xml_abstract_location_or_arn.clear();
         xml_abstract_vehicle_license.clear();
         xml_reqNameAddress.clear();
         public static void xmlwriter(String writestring){     
              String filename = "U:\\dl.xml";
                   try {
                        FileWriter myFW = new FileWriter(filename, true);
                        BufferedWriter out = new BufferedWriter(myFW);     
    out.flush();
                        out.write(writestring);
                        out.newLine();
                        out.close();
                   } catch (IOException f) {
                        System.out.println("Error -- " + f.toString());
                   }// ends catch
    //     convenience to save typing, keep focus
         private static

    Ok, here is the snippet that I think is having problems
    static void xmlwriter(String writestring){
    String filename = "U:dl.xml";
    try {
    FileWriter myFW = new FileWriter(filename, true);
    BufferedWriter out = new BufferedWriter(myFW);
    out.flush();
    out.write(writestring);
    out.newLine();
    out.close();
    } catch (IOException f) {
    System.out.println("Error -- " + f.toString());
    }// ends catch
    I call this for everyline written, and as I watch the file bytes count up, I then see it reset to zero and start over. Could this be something to do with creating a new buffer for every line?

Maybe you are looking for

  • Moving avergae price updation in material master for project stock

    Dear All, My query is pertaining to updation of MAP( moving average price) for project specific procurement ( as project stock) for valuated project stock. As  definelty the cost of procurement gets consumed by project .but i want to know does the pr

  • [SOLVED] No sound in Flash Plugins - Xonar D2X

    There is no sound at all when I play any flash content, but my sound works for other applications no problem. I'm running Google Chrome's built-in flash plugin I'm running Pulse Audio with ALSA. I have installed pulseaudio and pulseaudio-alsa I'm usi

  • Warning when trying to open BI integration wizard

    Hi, when i try to open the BI integration wizard, i get a warning " warning 2003 : zoom to the current diagram to a level of an ivew or source " and then the wizard closes. Haradev

  • Report with long column cell value

    Hi, we have report with some number of columns and some columns cells have value with a lot of chars (more than 100). We would like to trim this column cell value to for example 20 chars and put all chars of column cell value to HTML TD title value a

  • Receiver file with 2 extensions

    Hi, I had once come across a blog for placing the file in the FTP folder with 2 extensions (say .txt and .xml). Not able to find it now, can any one help me in finding the same? or say how can it be done. PS: I do not need michael's blog of sender an