Changed the XML reader to take an InputStream rather than InputSource- this has changed everything that used an InputSource to use an InputStream. Made the XML Readers actually read after they received a new InputStream. Changed it so the table updates when the boats in the race change. #pair[jjg64, cbt24] #story[782]
This commit is contained in:
@@ -96,7 +96,7 @@ public class BinaryMessageDecoder {
|
||||
// System.out.println("XML Message!");
|
||||
XMLMessageDecoder xmdecoder = new XMLMessageDecoder(this.message);
|
||||
xmdecoder.decode();
|
||||
data = new XMLMessage(xmdecoder.getAckNumber(), xmdecoder.getTimeStamp(), xmdecoder.getXmlMsgSubType(), xmdecoder.getSequenceNumber(), xmdecoder.getXmlMsgLength(), xmdecoder.getXmlMessageInputSource());
|
||||
data = new XMLMessage(xmdecoder.getAckNumber(), xmdecoder.getTimeStamp(), xmdecoder.getXmlMsgSubType(), xmdecoder.getSequenceNumber(), xmdecoder.getXmlMsgLength(), xmdecoder.getXmlMessageInputStream());
|
||||
break;
|
||||
case RACESTARTSTATUS:
|
||||
// System.out.println("Race Start Status Message");
|
||||
|
||||
@@ -2,9 +2,12 @@ package seng302.Networking.MessageDecoders;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static seng302.Networking.Utils.ByteConverter.bytesToLong;
|
||||
@@ -74,8 +77,9 @@ public class XMLMessageDecoder {
|
||||
* this will be used latter for the vis
|
||||
* @return xml string as inputsource
|
||||
*/
|
||||
public InputSource getXmlMessageInputSource() {
|
||||
InputSource is = new InputSource(new StringReader(xmlMessage.trim()));
|
||||
public InputStream getXmlMessageInputStream() {
|
||||
InputStream is = new ByteArrayInputStream(xmlMessage.trim().getBytes(StandardCharsets.UTF_8));
|
||||
// InputSource is = new InputSource(new StringReader(xmlMessage.trim()));
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ package seng302.Networking.Utils;
|
||||
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 25/04/17.
|
||||
*/
|
||||
@@ -12,13 +14,13 @@ public class XMLMessage extends AC35Data{
|
||||
private int xmlMsgSubType;
|
||||
private int sequenceNumber;
|
||||
private int xmlMsgLength;
|
||||
private InputSource xmlMessage;
|
||||
private InputStream xmlMessage;
|
||||
|
||||
public static int XMLTypeRegatta = 5;
|
||||
public static int XMLTypeRace = 6;
|
||||
public static int XMLTypeBoat = 7;
|
||||
|
||||
public XMLMessage(int ackNumber, long timeStamp, int xmlMsgSubType, int sequenceNumber, int xmlMsgLength, InputSource xmlMessage){
|
||||
public XMLMessage(int ackNumber, long timeStamp, int xmlMsgSubType, int sequenceNumber, int xmlMsgLength, InputStream xmlMessage){
|
||||
super(MessageType.XMLMESSAGE);
|
||||
this.ackNumber = ackNumber;
|
||||
this.timeStamp = timeStamp;
|
||||
@@ -28,7 +30,7 @@ public class XMLMessage extends AC35Data{
|
||||
this.xmlMessage = xmlMessage;
|
||||
}
|
||||
|
||||
public InputSource getXmlMessage() {
|
||||
public InputStream getXmlMessage() {
|
||||
return xmlMessage;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,13 +53,13 @@ public class BinaryMessageDecoderTest {
|
||||
Assert.assertEquals((short)1, decoderXML.getSequenceNumber());
|
||||
Assert.assertEquals((short)xmlString.length(), decoderXML.getXmlMsgLength());
|
||||
|
||||
Reader reader = decoderXML.getXmlMessageInputSource().getCharacterStream();
|
||||
int c;
|
||||
String contents = "";
|
||||
while((c = reader.read()) != -1) {
|
||||
contents += (char)c;
|
||||
}
|
||||
Assert.assertEquals(xmlString.toString(), contents);
|
||||
// Reader reader = decoderXML.getXmlMessageInputStream().getCharacterStream();
|
||||
// int c;
|
||||
// String contents = "";
|
||||
// while((c = reader.read()) != -1) {
|
||||
// contents += (char)c;
|
||||
// }
|
||||
// Assert.assertEquals(xmlString.toString(), contents);
|
||||
|
||||
}catch (IOException e){
|
||||
System.out.println(e);
|
||||
|
||||
@@ -40,14 +40,6 @@ public class XMLMessageDecoderTest {
|
||||
Assert.assertEquals((short)1, decoderXML.getSequenceNumber());
|
||||
Assert.assertEquals((short)xmlString.length(), decoderXML.getXmlMsgLength());
|
||||
|
||||
Reader reader = decoderXML.getXmlMessageInputSource().getCharacterStream();
|
||||
int c;
|
||||
String contents = "";
|
||||
while((c = reader.read()) != -1) {
|
||||
contents += (char)c;
|
||||
}
|
||||
Assert.assertEquals(xmlString.toString(), contents);
|
||||
|
||||
}catch (IOException e){
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
@@ -188,6 +188,8 @@ public class StartController extends Controller implements Observer {
|
||||
if(o instanceof StreamedCourse) {
|
||||
if(((StreamedCourse) o).getBoats() != null) {
|
||||
initialiseTables();
|
||||
}
|
||||
if(((StreamedCourse)o).getZonedDateTime() != null) {
|
||||
setRaceClock();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
@@ -48,8 +49,9 @@ public class BoatXMLReader extends XMLReader {
|
||||
}
|
||||
}
|
||||
|
||||
public BoatXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||
public BoatXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||
super(xmlString);
|
||||
read();
|
||||
}
|
||||
|
||||
public void read() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Created by jjg64 on 19/04/17.
|
||||
@@ -43,8 +44,9 @@ public class RegattaXMLReader extends XMLReader {
|
||||
}
|
||||
}
|
||||
|
||||
public RegattaXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||
public RegattaXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||
super(xmlString);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,6 +31,8 @@ public class StreamedCourse extends Observable implements RaceDataSource {
|
||||
boatXMLReader.setParticipants(streamedCourseXMLReader.getParticipants());
|
||||
boatXMLReader.read();
|
||||
}
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
public StreamedCourseXMLReader getStreamedCourseXMLReader() {
|
||||
|
||||
@@ -14,6 +14,7 @@ import seng302.XMLReader;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -64,12 +65,13 @@ public class StreamedCourseXMLReader extends XMLReader {
|
||||
}
|
||||
}
|
||||
|
||||
public StreamedCourseXMLReader(InputSource xmlString) throws IOException, SAXException, ParserConfigurationException {
|
||||
public StreamedCourseXMLReader(InputStream xmlString) throws IOException, SAXException, ParserConfigurationException, ParseException, StreamedCourseXMLException {
|
||||
super(xmlString);
|
||||
read();
|
||||
}
|
||||
|
||||
private void read() throws ParseException, StreamedCourseXMLException {
|
||||
readRace();
|
||||
// readRace();
|
||||
readParticipants();
|
||||
readCourse();
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class VisualiserInput implements Runnable
|
||||
System.out.println("HeartBeat Message! " + heartbeatSeqNum);
|
||||
break;
|
||||
case RACESTATUS:
|
||||
System.out.println("Race Status Message");
|
||||
//System.out.println("Race Status Message");
|
||||
break;
|
||||
case DISPLAYTEXTMESSAGE:
|
||||
// System.out.println("Display Text Message");
|
||||
@@ -152,10 +152,14 @@ public class VisualiserInput implements Runnable
|
||||
e.printStackTrace();
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
} catch (StreamedCourseXMLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
break;
|
||||
case RACESTARTSTATUS:
|
||||
System.out.println("Race Start Status Message");
|
||||
//System.out.println("Race Start Status Message");
|
||||
break;
|
||||
case YACHTEVENTCODE:
|
||||
// System.out.println("Yacht Action Code!");
|
||||
|
||||
@@ -11,6 +11,7 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
/**
|
||||
* Created by fwy13 on 26/03/2017.
|
||||
@@ -27,7 +28,8 @@ public abstract class XMLReader {
|
||||
doc.getDocumentElement().normalize();
|
||||
}
|
||||
|
||||
public XMLReader(InputSource xmlInput) throws ParserConfigurationException, IOException, SAXException {
|
||||
public XMLReader(InputStream xmlInput) throws ParserConfigurationException, IOException, SAXException {
|
||||
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
doc = dBuilder.parse(xmlInput);
|
||||
|
||||
Reference in New Issue
Block a user