@Override public void handleEntity(Object bean) { try { NycVehicleLocationRecord record = (NycVehicleLocationRecord) bean; AgencyAndId vehicleId = record.getVehicleId(); NycVehicleLocationRecord prev = _lastRecordsByVehicleId.put(vehicleId, record); EntityHandler handler = _entityHandlersByVehicleId.get(vehicleId); long time = getTimeForRecord(record); if (prev == null || getTimeForRecord(prev) + _maxOffset < time || handler == null) { Writer writer = _writersByVehicleId.get(vehicleId); if (writer != null) writer.close(); String timeString = _format.format(new Date(time)); String fileName = vehicleId.getId() + "-" + timeString + ".txt"; File outputFile = new File(_outputDirectory, fileName); writer = new FileWriter(outputFile); handler = _factory.createWriter(NycVehicleLocationRecord.class, writer); _entityHandlersByVehicleId.put(vehicleId, handler); _writersByVehicleId.put(vehicleId, writer); } handler.handleEntity(record); } catch (IOException ex) { throw new IllegalStateException(ex); } }
public EntityHandlerImpl(File outputDirectory) { _outputDirectory = outputDirectory; _factory.setTokenizerStrategy(new TabTokenizerStrategy()); }