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