@Test(expected = IllegalArgumentException.class) public void testFactoryThrowsException() { LogFileParser.factory("invalidFileName"); fail("Expected IllegalArgumentException"); }
public static LogFileParser factory(String fileName) { LogFileParser fileParser; if (fileName.startsWith(RecordType.bsmTx.name())) { logger.debug("Parsing as \"Transmit BSM \" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmTx); } else if (fileName.startsWith(RecordType.bsmLogDuringEvent.name())) { logger.debug("Parsing as \"BSM For Event\" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmLogDuringEvent); } else if (fileName.startsWith(RecordType.rxMsg.name())) { logger.debug("Parsing as \"Received Messages\" log file type."); fileParser = new RxMsgFileParser().setRecordType(RecordType.rxMsg); } else if (fileName.startsWith(RecordType.dnMsg.name())) { logger.debug("Parsing as \"Distress Notifications\" log file type."); fileParser = new DistressMsgFileParser().setRecordType(RecordType.dnMsg); } else if (fileName.startsWith(RecordType.driverAlert.name())) { logger.debug("Parsing as \"Driver Alert\" log file type."); fileParser = new DriverAlertFileParser().setRecordType(RecordType.driverAlert); } else { throw new IllegalArgumentException("Unknown log file prefix: " + fileName); } return fileParser; }
LogFileParser implements FileParser { public static LogFileParser factory(String fileName) { LogFileParser fileParser; if (fileName.startsWith(RecordType.bsmTx.name())) { logger.debug("Parsing as \"Transmit BSM \" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmTx); } else if (fileName.startsWith(RecordType.bsmLogDuringEvent.name())) { logger.debug("Parsing as \"BSM For Event\" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmLogDuringEvent); } else if (fileName.startsWith(RecordType.rxMsg.name())) { logger.debug("Parsing as \"Received Messages\" log file type."); fileParser = new RxMsgFileParser().setRecordType(RecordType.rxMsg); } else if (fileName.startsWith(RecordType.dnMsg.name())) { logger.debug("Parsing as \"Distress Notifications\" log file type."); fileParser = new DistressMsgFileParser().setRecordType(RecordType.dnMsg); } else if (fileName.startsWith(RecordType.driverAlert.name())) { logger.debug("Parsing as \"Driver Alert\" log file type."); fileParser = new DriverAlertFileParser().setRecordType(RecordType.driverAlert); } else { throw new IllegalArgumentException("Unknown log file prefix: " + fileName); } return fileParser; } }
LogFileParser implements FileParser { public static LogFileParser factory(String fileName) { LogFileParser fileParser; if (fileName.startsWith(RecordType.bsmTx.name())) { logger.debug("Parsing as \"Transmit BSM \" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmTx); } else if (fileName.startsWith(RecordType.bsmLogDuringEvent.name())) { logger.debug("Parsing as \"BSM For Event\" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmLogDuringEvent); } else if (fileName.startsWith(RecordType.rxMsg.name())) { logger.debug("Parsing as \"Received Messages\" log file type."); fileParser = new RxMsgFileParser().setRecordType(RecordType.rxMsg); } else if (fileName.startsWith(RecordType.dnMsg.name())) { logger.debug("Parsing as \"Distress Notifications\" log file type."); fileParser = new DistressMsgFileParser().setRecordType(RecordType.dnMsg); } else if (fileName.startsWith(RecordType.driverAlert.name())) { logger.debug("Parsing as \"Driver Alert\" log file type."); fileParser = new DriverAlertFileParser().setRecordType(RecordType.driverAlert); } else { throw new IllegalArgumentException("Unknown log file prefix: " + fileName); } return fileParser; } LogFileParser(); }
LogFileParser implements FileParser { public static LogFileParser factory(String fileName) { LogFileParser fileParser; if (fileName.startsWith(RecordType.bsmTx.name())) { logger.debug("Parsing as \"Transmit BSM \" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmTx); } else if (fileName.startsWith(RecordType.bsmLogDuringEvent.name())) { logger.debug("Parsing as \"BSM For Event\" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmLogDuringEvent); } else if (fileName.startsWith(RecordType.rxMsg.name())) { logger.debug("Parsing as \"Received Messages\" log file type."); fileParser = new RxMsgFileParser().setRecordType(RecordType.rxMsg); } else if (fileName.startsWith(RecordType.dnMsg.name())) { logger.debug("Parsing as \"Distress Notifications\" log file type."); fileParser = new DistressMsgFileParser().setRecordType(RecordType.dnMsg); } else if (fileName.startsWith(RecordType.driverAlert.name())) { logger.debug("Parsing as \"Driver Alert\" log file type."); fileParser = new DriverAlertFileParser().setRecordType(RecordType.driverAlert); } else { throw new IllegalArgumentException("Unknown log file prefix: " + fileName); } return fileParser; } LogFileParser(); static LogFileParser factory(String fileName); ParserStatus parseFile(BufferedInputStream bis, String fileName); ParserStatus parseStep(BufferedInputStream bis, int length); int getStep(); LogFileParser setStep(int step); String getFilename(); LogFileParser setFilename(String filename); RecordType getRecordType(); LogFileParser setRecordType(RecordType recordType); LocationParser getLocationParser(); void setLocationParser(LocationParser locationParser); TimeParser getTimeParser(); void setTimeParser(TimeParser timeParser); SecurityResultCodeParser getSecResCodeParser(); void setSecResCodeParser(SecurityResultCodeParser secResCodeParser); PayloadParser getPayloadParser(); void setPayloadParser(PayloadParser payloadParser); void updateMetadata(OdeLogMetadata metadata); void writeTo(OutputStream os); }
LogFileParser implements FileParser { public static LogFileParser factory(String fileName) { LogFileParser fileParser; if (fileName.startsWith(RecordType.bsmTx.name())) { logger.debug("Parsing as \"Transmit BSM \" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmTx); } else if (fileName.startsWith(RecordType.bsmLogDuringEvent.name())) { logger.debug("Parsing as \"BSM For Event\" log file type."); fileParser = new BsmLogFileParser().setRecordType(RecordType.bsmLogDuringEvent); } else if (fileName.startsWith(RecordType.rxMsg.name())) { logger.debug("Parsing as \"Received Messages\" log file type."); fileParser = new RxMsgFileParser().setRecordType(RecordType.rxMsg); } else if (fileName.startsWith(RecordType.dnMsg.name())) { logger.debug("Parsing as \"Distress Notifications\" log file type."); fileParser = new DistressMsgFileParser().setRecordType(RecordType.dnMsg); } else if (fileName.startsWith(RecordType.driverAlert.name())) { logger.debug("Parsing as \"Driver Alert\" log file type."); fileParser = new DriverAlertFileParser().setRecordType(RecordType.driverAlert); } else { throw new IllegalArgumentException("Unknown log file prefix: " + fileName); } return fileParser; } LogFileParser(); static LogFileParser factory(String fileName); ParserStatus parseFile(BufferedInputStream bis, String fileName); ParserStatus parseStep(BufferedInputStream bis, int length); int getStep(); LogFileParser setStep(int step); String getFilename(); LogFileParser setFilename(String filename); RecordType getRecordType(); LogFileParser setRecordType(RecordType recordType); LocationParser getLocationParser(); void setLocationParser(LocationParser locationParser); TimeParser getTimeParser(); void setTimeParser(TimeParser timeParser); SecurityResultCodeParser getSecResCodeParser(); void setSecResCodeParser(SecurityResultCodeParser secResCodeParser); PayloadParser getPayloadParser(); void setPayloadParser(PayloadParser payloadParser); void updateMetadata(OdeLogMetadata metadata); void writeTo(OutputStream os); static final int BUFFER_SIZE; }