By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

Parsing with Java SAX from a UDP socket

P: 1
I'm trying to accept UDP multicast XML messages and parse them. The current way I'm doing so is by creating a new File for each message and then calling parser.parse(filename.xml) This way works. However, I think the frequent File I/O is causing performance problems. Is there a way I can do this without doing File I/O? The parse() method allows an InputStream but I don't know how to get an InputStream. Here's my current code:

MulticastSocket s = new MulticastSocket(port);

byte[] buf = new byte[10240];
DatagramPacket recv = new DatagramPacket(buf, buf.length);

//a.xml is a temporary file where the message is written
String outFile = "a.xml";
File out_file = new File(outFile);

FileOutputStream xml_temp = new FileOutputStream(out_file);
parser.parse(out_file, SAXHandler);
catch (Exception e)
{System.out.println("Parser had an error:" + e);}
Jan 18 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.