StreamPacket class created so that we can store all packets generically. The timestamp has also been extracted and stored with the packet so that in the future we may turn the current ArrayList into a priority que.

#story[817]
This commit is contained in:
Kusal Ekanayake
2017-04-23 20:14:41 +12:00
parent ba352183bf
commit 3dc1a7f9c0
3 changed files with 93 additions and 13 deletions
@@ -0,0 +1,44 @@
package seng302.models.parsers;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/**
* Created by kre39 on 23/04/17.
*/
public class StreamParser {
private static boolean isWithinTag;
static void parseLine(byte[] bytes) {
//TODO overhaul all of this to treat packets as appropriate
String line = new String(bytes);
if (line.startsWith("<")){
isWithinTag = true;
}
// System.out.println("line = ---------------------------------------------\n" + line);
if (isWithinTag) {
// try {
// Element node = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(line.getBytes())).getDocumentElement();
// if (node.getAttributes().getNamedItem("Type") != null) {
// System.out.println(node.getAttributes().getNamedItem("Type") );
// System.out.println(line);
// }
// } catch (Throwable e){
//// e.printStackTrace();
// }
}
if (line.startsWith("</")) {
isWithinTag = false;
}
}
}