Search in sources :

Example 1 with DelimiterTokenizerStrategy

use of org.onebusaway.csv_entities.DelimiterTokenizerStrategy in project onebusaway-application-modules by camsys.

the class BlockLocationHistoryServiceImpl method getHistoryForTripId.

@Override
public Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> getHistoryForTripId(AgencyAndId tripId) {
    TripEntry trip = _transitGraphDao.getTripEntryForId(tripId);
    if (trip == null)
        return null;
    BlockEntry block = trip.getBlock();
    List<File> files = getFilesForBlockId(block.getId());
    CsvEntityReader reader = new CsvEntityReader();
    reader.setTokenizerStrategy(new DelimiterTokenizerStrategy("\t"));
    EntityHandlerImpl handler = new EntityHandlerImpl(tripId);
    reader.addEntityHandler(handler);
    try {
        for (File file : files) {
            InputStream in = openFileForInput(file);
            reader.readEntities(BlockLocationArchiveRecord.class, in);
            in.close();
        }
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
    Map<AgencyAndIdInstance, List<BlockLocationArchiveRecord>> recordsByInstance = handler.getRecordsByInstance();
    for (List<BlockLocationArchiveRecord> records : recordsByInstance.values()) Collections.sort(records, new DistanceAlongBlockComparator());
    return recordsByInstance;
}
Also used : AgencyAndIdInstance(org.onebusaway.gtfs.model.AgencyAndIdInstance) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) IOException(java.io.IOException) DelimiterTokenizerStrategy(org.onebusaway.csv_entities.DelimiterTokenizerStrategy) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ArrayList(java.util.ArrayList) List(java.util.List) CsvEntityReader(org.onebusaway.csv_entities.CsvEntityReader) File(java.io.File)

Aggregations

File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 CsvEntityReader (org.onebusaway.csv_entities.CsvEntityReader)1 DelimiterTokenizerStrategy (org.onebusaway.csv_entities.DelimiterTokenizerStrategy)1 AgencyAndIdInstance (org.onebusaway.gtfs.model.AgencyAndIdInstance)1 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1