Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:19:40+00:00 2026-06-01T06:19:40+00:00

I have a socket feeding into a sax parser, formatted as a ISO 8859/1

  • 0

I have a socket feeding into a sax parser, formatted as a ISO 8859/1 stream. Every so often there is an invalid character, and I get a SAXParseException with a row and column where that happened, so I need to see what the data is at that point (or more importantly log it).

Originally the lines that processed the data were:

InputSource is = new InputSource(new InputStreamReader(socket.getInputStream(), "ISO8859_1"));
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler(new ResponseParseHandler(etc, id));
reader.parse(is);

Problem is that I can’t get the data after the event of this happening, so I changed it to read into a large byte buffer, convert it to a string and parse that data with a StringReader. Unfortunately the data coming from the socket is spread out in small chunks over a long time, so it will start with the root tag when it first connects, but then there will be thousands of separate messages without a closing tag.

Because I am parsing these strings individually when they come in the first one has an error that it doesn’t have a closing tag, and the following ones error as they don’t have a base tag. This doesn’t happen with the socket as I assume the stream is still open

Presumably I can feed these strings to another reader / writer but it seems to be getting really complicated just to find out what the block of data was at the time of the error.

Is there something really simple I am missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:19:42+00:00Added an answer on June 1, 2026 at 6:19 am

    The last time I had a problem similar to this, I solved it with a SplittingWriter. This was a decorator style class around two other Writers, and when something “wrote” to the SplittingWriter it simply delegated the write call to both of its two underlying Writers.

    In your case, you would want something like a SplittingInputStreamReader, which would implement InputStreamReader and which you would pass in to InputSource instead of the InputStreamReader you are using at the moment.

    In its constructor the SplittingInputStreamReader would take your current InputStreamReader and some other object, lets call it Foo. The implementation of the read methods on SplittingInputStreamReader would then delegate the read calls to the underlying InputStreamReader, push the results of those calls to Foo, and then return the result of those calls back to the thing that called it. So your implementation of the int read() method would be something like:

    
       @Override
       public int read() {
           int r = this.inputStreamReader.read();
           this.foo.submit(r);
           return r;
       }
    
    

    That way, as you read via the SplittingInputStreamReader, you also write to Foo, allowing you to see where the write stopped assuming you gave Foo a decent interface. In the end, after implementing SplittingInputStreamReader and Foo, your code would look something like this:

    
    Foo streamCapture = new Foo();
    SplittingInputStreamReader streamReader = new SplittingInputStreamReader(
       new InputStreamReader(socket.getInputStream(), "ISO8859_1"), streamCapture);
    InputSource is = new InputSource(streamReader);
    XMLReader reader = XMLReaderFactory.createXMLReader();
    reader.setContentHandler(new ResponseParseHandler(etc, id));
    reader.parse(is);
    // After parse, if there was an error, check what is in Foo streamCapture
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a socket application which I can use in local network, at home.
I have a socket server in php server.php $master = WebSocket(localhost,800); $sockets = array($master);
I have the DWORD socket in windows. I need to know if it is
I have a tcp socket sending three lines like this out2.println(message1\n); out2.println(message2\n); out2.println(message3\n); and
I have an open socket to a remote terminal. Using the answer to Force
I have a Java socket server program listening on a specific port. When receiving
We create a socket. On one side of the socket we have a server
Suppose, I have a connected socket after writing this code.. if ((sd = accept(socket_d,
I have small test app: Socket socket = new Socket(jeck.ru, 80); PrintWriter pw =
I have this socket server script, import SocketServer import shelve import zlib class MyTCPHandler(SocketServer.BaseRequestHandler):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.