Skip to content

Commit

Permalink
chore: using more efficient buffered streams (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkchouaki authored Dec 20, 2024
1 parent 7ed1950 commit fa01556
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.matsim.core.events.MatsimEventsReader;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.trafficmonitoring.FreeSpeedTravelTime;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.vehicles.Vehicle;

/**
Expand Down Expand Up @@ -78,7 +79,7 @@ public double getLinkTravelTime(Link link, double time, Person person, Vehicle v
}

static public void writeBinary(String outputPath, RecordedTravelTime travelTime) throws IOException, InterruptedException {
OutputStream outputStream = new FileOutputStream(outputPath);
OutputStream outputStream = IOUtils.getOutputStream(new File(outputPath).toURI().toURL(), false);
RecordedTravelTime.writeBinary(outputStream, travelTime);
outputStream.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -220,7 +219,7 @@ public class Writer implements VDFWriterInterface {
@Override
public void writeFile(File outputFile) {
try {
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(outputFile.toString()));
DataOutputStream outputStream = new DataOutputStream(IOUtils.getOutputStream(outputFile.toURI().toURL(), false));

outputStream.writeDouble(scope.getStartTime());
outputStream.writeDouble(scope.getEndTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -113,7 +112,7 @@ public class Writer implements VDFWriterInterface {
@Override
public void writeFile(File outputFile) {
try {
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(outputFile.toString()));
DataOutputStream outputStream = new DataOutputStream(IOUtils.getOutputStream(outputFile.toURI().toURL(), false));

outputStream.writeDouble(scope.getStartTime());
outputStream.writeDouble(scope.getEndTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -244,7 +243,7 @@ public class Writer implements VDFWriterInterface {
@Override
public void writeFile(File outputFile) {
try {
DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(outputFile.toString()));
DataOutputStream outputStream = new DataOutputStream(IOUtils.getOutputStream(outputFile.toURI().toURL(), false));

outputStream.writeDouble(scope.getStartTime());
outputStream.writeDouble(scope.getEndTime());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package org.eqasim.core.standalone_mode_choice;


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Paths;
Expand Down Expand Up @@ -45,12 +40,14 @@
import org.matsim.api.core.v01.population.Population;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigGroup;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.trafficmonitoring.FreeSpeedTravelTime;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.pt.transitSchedule.api.TransitSchedule;
import org.matsim.vehicles.Vehicle;

Expand All @@ -71,7 +68,7 @@
* - travel-times-factors-path: if provided, should point out to a csv file specifying the congestion levels on the network during the day as factors by which the free speed is divided. The file in question is a csv With a header timeUpperBound;travelTimeFactor in which the timeUpperBound should be ordered incrementally.
* - recorded-travel-times-path: mutually exclusive with the travel-times-factors-path. Points to a RecordedTravelTime file.
* - eqasim-configurator-class: The full name of a class extending the {@link org.eqasim.core.simulation.EqasimConfigurator} class, the provided configurator class will be instantiated and used to:
* - Detect optional config groups using the {@link org.eqasim.core.simulation.EqasimConfigurator#addOptionalConfigGroups(Config)} method
* - Detect optional config groups using the {@link org.eqasim.core.simulation.EqasimConfigurator#registerConfigGroup(ConfigGroup, boolean)} (Config)} method
* - Configure the scenario using the {@link org.eqasim.core.simulation.EqasimConfigurator#configureScenario(Scenario)} before loading
* - Adjust the scenario using the {@link org.eqasim.core.simulation.EqasimConfigurator#adjustScenario(Scenario)} after loading
* - mode-choice-configurator-class: The full name of a class the extending the {@link org.eqasim.core.standalone_mode_choice.StandaloneModeChoiceConfigurator} class.
Expand Down Expand Up @@ -216,7 +213,7 @@ public void install() {
@Singleton
RecordedTravelTime provideRecordedTravelTime() {
try {
InputStream inputStream = new FileInputStream(path);
InputStream inputStream = IOUtils.getInputStream(new File(path).toURI().toURL());
RecordedTravelTime recordedTravelTime = RecordedTravelTime.readBinary(inputStream);
inputStream.close();
return recordedTravelTime;
Expand Down

0 comments on commit fa01556

Please sign in to comment.