Parsing from InputStream problem

I have a serious problem with parsing XML from an InputStream.
It is the exact same problem other people had before in those threads :
http://forum.java.sun.com/thread.jsp?forum=34&thread=343710
http://forum.java.sun.com/thread.jsp?forum=34&thread=68180
http://forum.java.sun.com/thread.jsp?forum=34&thread=68259
I have read the FAQ at http://www.jdom.org/docs/faq.html which suggest the following :
byte[] buf = new byte[length];
new DataInputStream(inputStream).readFully(buf);
InputStream in = new ByteArrayInputStream(buf);
(Contributed by Joseph Bowbeer)
But my problem still remains the same. What happens if more than 1 XML documents were writen in the InputStream because the writting took place very fast and the receiver could not parse the XML document fast enough so now the byte buffer 'buf' contains 2 XML documents one after the other ? What if it contains half XML document because the sender was temporarily blocked or something; and after some time it continues with the rest XML document ?
how could I overcome those problems ?
thanks

The root cause of the problems reported in this and other threads seems to be the SAX parsers are buffering the entire input stream before they commence parsing (which appears to be completely contrary to the spirit of SAX). This explains the parser hanging behaviour reported by some folk. It also explains why the parsers are awaiting for some sort of EOF marker before they begin parsing.
Maybe this buffering behaviour has been fixed in the newer releases of xerces and crimson et al, but there is a good discussion of this problem and a solution (albeit for xerces), at http://xml.apache.org.xerces-j/faq-write.html, under the section "how do I read data from a stream as it arrives?".

Similar Messages

  • Parse an InputStream!

    Hi I have a problem with parsing an InputStream from a host.
    I allways get the a error message (stated below).
    Is there anyone who know how to solve this problem?
    Is it possible to parse the InputStream and ignore <!DOC....../> line?
    //Ante
    Error-message:
    ERROR reading URI: www.wapforum.org
    CODE:
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    parser.setContentHandler(contentHandler);
    parser.setErrorHandler(errorHandler);
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
              parser.setFeature("http://xml.org/sax/features/validation", false);
    parser.parse(new InputSource(is));
    XML-Document:
    <?xml version="1.0"?>
    <!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN"
    "http://www.wapforum.org/DTD/pap_1.0.dtd">
    <pap>
    <push-response push-id="1"
         sender-address="http://"
         sender-name="HD"           reply-time="2001-08-08T11:41:06Z">
    <response-result code="1001" desc="The request accepted for processing"/>
    </push-response>
    </pap>

    If you have set the validation to false, then you do not need to reference a DTD to validate against. Try removing the DOCTYPE tag completely and see what happens.
    ML

  • How to create File object from InputStream

    Hi everybody
    Can I know a way to create a File object from InputStream object
    Here's my code:
    URL url = loader.getResource(xsdFile); //Thats a schema file..not to worry
    InputStream istream = url.openStream();
    Now from that 'istream' I need to build File object.
    Thank you all

    didn't know fileinputstream was made to read url objects ; in the doc, it just says "A FileInputStream obtains input bytes from a file in a file system." ; according to me, website is something outside the filesystem, but i could be wrong
    edit: thought from the beginning it was all about FILEinputstream whereas it just says "inputstream" in the post ; my bad, it's still early in the morning here X)

  • HT201210 nowadays have many user have problem with update to ios7 and need active with apple id maybe in the future in order escape from these problems must be stop use these products else. Because of simple user don't know about this technology and somet

    nowadays have many user have problem with update to ios7 and need active with apple id maybe in the future in order escape from these problems must be stop use these products else. Because of simple user don't know about this technology and sometime just hear from other user that it 's difficult to use then force they change phone that use to handle to another.

    It is a feature to discourage the theft of iPhones by making them useless if resold. It's not going anywhere. It's simple: just don't buy a phone until you make sure that the activation lock has been disabled.

  • Hello I suffer from a problem with your MacBook  There is a black line in screen

    Hello
    I suffer from a problem with your MacBook
    There is a black line in screen
    http://i48.tinypic.com/35apzz8.png

    Is the line always present? If you boot up the MacBook holding down the option key during startup so that you get to the startup manager, is the line still there?
    If so you have a hardware issue and it needs to be repaired. Contact Apple using their Express Lane if you live in a country where that is available, or call the appropriate phone number on this page if not. You can also take the MacBook in to an Apple store or service provider.
    Best of luck.

  • Solved restarting from sleep problem myself.

    Let me tell my case. i have had never problem on restart from sleep.
    because i always use my new octacore 2.8 with TIGER.
    there is some two major reason.
    1, performance is better than Leopard. Leopard is heavier when , mouse movement, some 3d application's rendering speed, and even drag n drop folder etc.
    2, some application i use still run well on Tiger. apple did not consider compatibility with older application at all.
    Because apple did not want user install tiger on new 2008 macpro, i must put out pre-installed tiger HDD from another mac and put into new mac. and it works well. any sleep from restart problem at all. problem is graphic card. i have 2600HD and 1900 XT. if i connect 2600HD, i can't accelerate GPU power in Tiger. it works only in Leopard.and even in sleep mode, but graphic cards fan always run.
    but when i boot use bootcamp to XP, i must connect to 2600HD. 1900XT did not display screen at all. like this i use 2 graphic card.
    I can't sure this problem due to hardware or OS problem, but obvious thing is tiger have never the problem. little problem is card's fan always run even in sleep mode. hope my case could be a clue.

    New firmware has come. and positive reply posting. good job
    i wonder if this new firmware destroy booting Tiger feature or not.
    i must use tiger now. hope apple do not disable tiger running in new macpro.
    any comment will be thanks.

  • Failed to read bytes from InputStream

    Hi,
    I get this excpetion log when I try to read a stream from weblogic. Can anyone help me out why this happens and what
    could be done to overcome this
    ####<Aug 8, 2007 4:48:37 PM EDT> <Error> <HTTP> <sundev01> <fhsserver> <[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1186606117277> <BEA-101019> <[weblogic.servlet.internal.WebAppServletContext@111f9b - name: 'FFMS', context-path: '/FFMS'] Servlet failed with IOException
    java.io.IOException: failed to read '2678' bytes from InputStream; clen: 58512 remaining: 44902 count: 1394
    at weblogic.servlet.internal.ChunkOutput.writeStream(ChunkOutput.java:411)
    at weblogic.servlet.internal.ChunkOutputWrapper.writeStream(ChunkOutputWrapper.java:168)
    at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:496)
    at weblogic.servlet.internal.ServletOutputStreamImpl.writeStream(ServletOutputStreamImpl.java:484)
    at weblogic.servlet.FileServlet.sendFile(FileServlet.java:400)
    at weblogic.servlet.FileServlet.doGetHeadPost(FileServlet.java:224)
    at weblogic.servlet.FileServlet.service(FileServlet.java:166)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:225)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:127)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:272)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:165)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3150)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:1973)
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1880)
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1310)
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:207)
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:179)
    >

    Hi Aravind,
    Which version of weblogic are u using?
    Cheers,
    Lakshmi

  • HT201442 Please let me install version 6.0.1 for 4g because I suffer from the problem of Wi-Fi

    Please let me install version 6.0.1 for 4g because I suffer from the problem of Wi-Fi
    im
    I am now I can not connect via Wi-Fi Remote
    i wish to respond as quickly as possible

    These are user to user support forums. No one here has the ability to allow installing of specific iOS versions.
    Apple has never allowed downgrading of iOS.
    Troubleshoot the issue using basic troubleshooting from the Users Guide. If the Wi-Fi still does not work then it is a hardware issue and no iOS version can correct that.

  • How to decode a base64 image that is parsed from an xml

    Hi everyone,
    I'm trying to decode a base64 image that is parsed from an XML. I was able to decode everything except for an image, and it resulted in weird characters such as
    ������?��������?��������f����������?
    I used sun.misc.BASE64Decoder()
    Thanks in advance,
    Squid

    Hi,
    I know that those are wierd characters because I have the correctly decoded data, and it looks different. Does any one know how to decode against the ASCII
    I know the following code would decode my base64 image correctly, but i dont know how to do the same in java for the follwing C# line of code:
    System.Web.HttpUtility.UrlDecode(sXMLString,
    System.Text.Encoding.GetEncoding(1252));
    Below is the entire C# code that successfully decode the base64 image from " test9.xml"
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Text;
    using System.Xml;
    using System.Web;
    namespace DecodeXML
    class Program
    static void Main(string[] args)
    string sFileName = "test9.xml";
    string sXMLString = File.ReadAllText(@"C:\NET 2.0 Projects\ThrowAways\SampleLabels\" + sFileName);
    string resultString =
    System.Web.HttpUtility.UrlDecode(sXMLString,
    System.Text.Encoding.GetEncoding(1252));
    XmlDocument oXML = new XmlDocument();
    oXML.LoadXml(resultString);
    XmlNode oLabel = oXML.SelectSingleNode("//LabelBody");
    // removed the line that saved it to a string variable, because it converts the binary characters to
    // incorrect text representations. However, by saving the bytes directly rectifies this
    File.WriteAllBytes(@"C:\NET 2.0 Projects\ThrowAways\SampleLabels\" + sFileName + ".txt", Convert.FromBase64String(oLabel.InnerText));
    Any suggestion is strongly appreciated.
    Thanks,
    Squid

  • Preventing parser from replacing & with &

    Is there a way to prevent the xdk parser from substituting the & and &apos; with & and ' respectively when the document is parsed?

    No, unless you enclose it with &lt;![CDATA[ ]]&gt;.

  • Refresh package with 'From-Date' Problem

    Hi All,
    I just ran into configuring the Analyze and Specify 'From-Date' problem fro refreshing package.   I've completed the normal package with the starting date 8/30/2008.  Now I am trying to go back and copy and select from 7/30/2008 for the new run during that posting period.  I am not if this is possible but it doesn't allow me to choose any of the option.  If I choose Analyse and deine new 'From-Date' when the screen popup, then choose 7/30, the date is not transfer to the Chosen From Date field at all, and execute.  The system will display he error with  "Evaluation failed. Required customising data no available".  Basically, it doesn't allow me to choose any date.
    Do any of you experiencing the same problem.  Or did I miss any step from the first run?
    Thanks,
    Tai

    Hi Tai,
    Implement the note 1180500 - Activity TD01P_FROM_RFH runs into error in a refresh package.
    Regards,
    Santosh

  • System currently suffers from technical problems. Your order will be processed as soon as possible.

    I placed the order for Creative Cloud and it has been confirmed.
    But I received this email: Our order processing system currently suffers from technical problems. Your order will be processed as soon as possible. This is my second attempt and my order has not been processed.

    if you've waited more than 1 business day, contact adobe support by clicking here and, when available, click 'still need help', https://helpx.adobe.com/contact.html

  • Dual Quad Core - wake from sleep problems

    I have a brand new Quad core 2.8 ATI Radeon, and have experienced both wake from sleep problems within the first week of ownership, more than once. Namely, restart on wake, and/or corrupt graphics-frozen on wake. I haven't called AppleCare, but my question is is it worth it? Is it thought to be a software problem, or a hardware issue? I don't want to go to a lot of trouble if any replacement exhibits the same problem (or worse), but at the same time I feel it is a real issue and should be dealt with under guarantee. What should I do? Suggestions please...

    There's lots of anecdotal data in the forum here and elsewhere, but the bottom line so far is that nobody knows except perhaps the Apple folks that are working on it.
    No one that I've seen posting has identified even a common thread...some machines have the reboot from sleep problem, some have graphics issues, some have both (I'm in the first camp...reboot from wake but no (touch wood) graphic issues.
    It wouldn't hurt to call Apple and get your issues on record; it helps them know the extent of the problem.
    Your warranty is for a year so it's not immediate, especially since there doesn't seem to be a lasting fix available. Resetting SMC and/or PRAM works for some...for a while...
    Right now I'm simply not sleeping the machine (I don't normally do it anyway) and waiting for Apple to come out with a fix. My bet is on a software/firmware fix (there are reports that the problem does not happen in bootcamp/windows, which more or less rules out hardware). But that's a sort of educated guess.
    People have returned the machine only to get the same...or worse. Again, I'm not rushing into that.
    Message was edited by: BillC37

  • SAX Parser XML Validation Problems

    Hi,
    I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
    When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
    Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
    Code Snippet:
    boolean isValid = false;
    try {
         // Create and configure factory
    SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    // To be notified of validation errors in the XML document,
    // add a custom error handler to the document builder
    PIMSFeedFileValidationHandler handler
    = new PIMSFeedFileValidationHandler();
         // Create and Configure Parser
    SAXParser parser = factory.newSAXParser();
    parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
         // Set reader with entityResolver for dtd
    XMLReader xmlReader = parser.getXMLReader();
    xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
    // convert file to URL, as it is a remote file
    URL url = super.getFile().toURL();
    // Open an input stream and parse
    InputStream is = url.openStream();
    xmlReader.setErrorHandler(handler);
    xmlReader.parse(new InputSource(is));
    is.close();
    // get the result of parsing the document by checking the
    // errorhandler's isValid property
    isValid = handler.isValid();
    if (!isValid) {
    LOGGER.warn(handler.getMessage());
    LOGGER.debug("XML file is valid XML? " + isValid);
    } catch (ParserConfigurationException e) {
    LOGGER.error("Error parsing file", e);
    } catch (SAXException e) {
    LOGGER.error("Error parsing file", e);
    } catch (IOException e) {
    throw new FeedException(e);
    return isValid;
    See stack trace below for a little more info.
    2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
    2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
    VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
    2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
    2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
    org.xml.sax.SAXParseException: Element type "Session" must be declared.
    org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
    org.xml.sax.SAXParseException: Element type "Volume" must be declared.
    org.xml.sax.SAXParseException: Element type "Written" must be declared.
    org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
    org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
    … continues for all the elements in the doc
    2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
    2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
    Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
    Thanks in Advance
    Adam

    Hi David,
    I have checked the ejb-jar.xml file and there is no duplicate values in it and the other things is that the same application is been deployed on OAS 10G and websphere and its working fine. In the forum someone has replied to a similar problem that there is bug in Weblogic 10.3 and its CR no 376292. I am not sure about it, does anyone any information about it.
    Thanks and Regards
    Deepak Dani

  • DOM parsing from memory avoid deprecated class usage

    I am parsing an xml file from memory stored in a StringBuffer xmlBuffer like this
    try {
                   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                   DocumentBuilder db = dbf.newDocumentBuilder();
                   InputStream is = new StringBufferInputStream(xmlBuffer.toString());
                   Document doc = db.parse(is);How can i avoid using of that deprecated class?

    Why are you storing the file in memory in a StringBuffer? You could use this method directly:
    [http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html#parse(java.io.File)]
    or from a URI:
    [http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilder.html#parse(java.lang.String)]
    StringBufferInputStream is deprecated because it does not properly convert characters into bytes.

Maybe you are looking for

  • Where to write IF THEN ELASE statements in BEX Query Designer

    Hi All, I need to write a formula in query designer... saying that to display the all Quantities in KGs.. Now articles are in Grams and KGs... So here i need to perform calculation like... if article is in KGs divide by 1, else if article is in Grams

  • COPA -update new value field

    Hi All, We have 3 revenue value fields and created new value field to capture total revenues for all 3 revenue value fields. only new sales orders total revenue value field is populated with revenues.how can we update old sales orders revenue value f

  • Multiple calling logical database ADA

    Hello, I need to call logical database ADA two times in my program. I use calling logical database using LDB_PROCESS function module. I need to call LDB for depreciation areas 01 and 60. If I call second time, I get exception  LDB_NOT_REENTRANT. I fo

  • Get the JMS Queue property in BPEL

    Hi, Does anyone have idea on how to get the value of JMSXDeliveryCount which is a prorerty of JMS queue in BPEL. I want that value in the bpel flow to control the Flow on the basis of it. Plz suggest its urgent. TIA. Best Regards, Amit Jain

  • Display Exceptions within BEx Web using individual icons/symbols

    Hi Experts, we have the requirement of our customer to display exceptions in a Web Template using individual symbols/icons. This is what we have done so far: first we included some exceptions in our query (i.e. 1, 2 and 3) which are now displayed wit