Fixed the bug where the polar file could not be read after being packaged

tags: #story[955]  #pair[wmu16, zyt10]
This commit is contained in:
William Muir
2017-07-10 12:36:32 +12:00
parent fe76ef9cdc
commit 5f9da6b40a
2 changed files with 37 additions and 43 deletions
+8 -15
View File
@@ -4,8 +4,6 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.Stage;
import seng302.models.PolarTable;
import seng302.models.stream.StreamParser;
@@ -16,7 +14,7 @@ public class App extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
PolarTable.parsePolarFile(getClass().getResource("/config/acc_polars.csv").getFile());
PolarTable.parsePolarFile(getClass().getResourceAsStream("/config/acc_polars.csv"));
Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml"));
primaryStage.setTitle("RaceVision");
@@ -31,11 +29,12 @@ public class App extends Application {
StreamReceiver.noMoreBytes();
System.exit(0);
});
}
public static void main(String[] args) {
try {
StreamReceiver sr = null;
new ServerThread("Racevision Test Server");
@@ -69,21 +68,15 @@ public class App extends Application {
}
//Change the StreamReceiver in this else block to change the default data source.
else{
sr = new StreamReceiver("livedata.americascup.com", 4940, "RaceStream");
// sr = new StreamReceiver("localhost", 4949, "RaceStream");
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4941, "RaceStream");
// sr = new StreamReceiver("csse-s302staff.canterbury.ac.nz", 4942, "RaceStream");
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
}
sr.start();
StreamParser streamParser = new StreamParser("StreamParser");
streamParser.start();
}
catch (Exception e){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText("Fatal Error");
alert.setContentText("There was an error connecting to the AC35 stream");
alert.showAndWait();
}
launch(args);
+4 -3
View File
@@ -24,9 +24,8 @@ public final class PolarTable {
* Iterates through each row of the polar table, in pairs, to extract the row into a hashmap of angle to boat speed.
* These angle boatspeed hashmaps are then added to an outer hashmap at the end of wind speed key to each row hashmap
* as a value
* @param file containing the polar csv information
*/
public static void parsePolarFile(String file) {
public static void parsePolarFile(InputStream polarFile) {
polarTable = new HashMap<>();
upwindOptimal = new HashMap<>();
downwindOptimal = new HashMap<>();
@@ -34,7 +33,7 @@ public final class PolarTable {
String line;
Boolean isHeaderLine = true;
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
try (BufferedReader br = new BufferedReader(new InputStreamReader(polarFile))) {
while ((line = br.readLine()) != null) {
String[] thisLine = line.split(",");
@@ -69,6 +68,8 @@ public final class PolarTable {
} catch (IOException e) {
e.printStackTrace();
}
}