Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes made for the ASCII type input #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ the License, or (at your option) any later version.
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;

import org.opentripplanner.routing.graph.Graph;
import org.opentripplanner.updater.JsonConfigurable;
import org.opentripplanner.util.Constants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.protobuf.TextFormat;
import com.google.transit.realtime.GtfsRealtime;
import com.google.transit.realtime.GtfsRealtime.FeedEntity;
import com.google.transit.realtime.GtfsRealtime.FeedMessage;
Expand All @@ -47,11 +50,17 @@ public class GtfsRealtimeFileTripUpdateSource implements TripUpdateSource, JsonC
* Default agency id that is used for the trip ids in the TripUpdates
*/
private String feedId;

/**
* An optional filed used for ASCII input
*/
private String feedType;

@Override
public void configure(Graph graph, JsonNode config) throws Exception {
this.feedId = config.path("feedId").asText();
this.file = new File(config.path("file").asText(""));
this.feedType = config.path("feedType").asText("");
}

@Override
Expand All @@ -64,7 +73,15 @@ public List<TripUpdate> getUpdates() {
InputStream is = new FileInputStream(file);
if (is != null) {
// Decode message
feedMessage = FeedMessage.PARSER.parseFrom(is);
if( this.feedType.equalsIgnoreCase(Constants.FEED_TYPE_ASCII)){
InputStreamReader reader = new InputStreamReader(is, Constants.FEED_TYPE_ASCII);
FeedMessage.Builder builder = FeedMessage.newBuilder();
TextFormat.merge(reader, builder);
feedMessage = builder.build();
}
else{
feedMessage = FeedMessage.PARSER.parseFrom(is);
}
feedEntityList = feedMessage.getEntityList();

// Change fullDataset value if this is an incremental update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ public interface Constants {
public static final String POINT_SUFFIX = ")";
public static final int POINT_SUFFIX_LEN = POINT_SUFFIX.length();
public static final String POINT_SEPARATOR = " ";
public static final String FEED_TYPE_ASCII = "ASCII";
}