@Test public void testPayloadLengthPartial() { ParserStatus expectedStatus = ParserStatus.PARTIAL; int expectedStep = 0; BufferedInputStream testInputStream = new BufferedInputStream( new ByteArrayInputStream(new byte[] { (byte)0x06 })); try { assertEquals(expectedStatus, payloadParser.parseFile(testInputStream, "testLogFile.bin")); assertEquals(expectedStep, payloadParser.getStep()); } catch (FileParserException e) { fail("Unexpected exception: " + e); } }
@Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, PAYLOAD_LENGTH_LENGTH); if (status != ParserStatus.COMPLETE) return status; setPayloadLength(CodecUtils.bytesToShort(readBuffer, 0, PAYLOAD_LENGTH_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, getPayloadLength()); if (status != ParserStatus.COMPLETE) return status; setPayload(Arrays.copyOf(readBuffer, getPayloadLength())); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; }
PayloadParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, PAYLOAD_LENGTH_LENGTH); if (status != ParserStatus.COMPLETE) return status; setPayloadLength(CodecUtils.bytesToShort(readBuffer, 0, PAYLOAD_LENGTH_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, getPayloadLength()); if (status != ParserStatus.COMPLETE) return status; setPayload(Arrays.copyOf(readBuffer, getPayloadLength())); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } }
PayloadParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, PAYLOAD_LENGTH_LENGTH); if (status != ParserStatus.COMPLETE) return status; setPayloadLength(CodecUtils.bytesToShort(readBuffer, 0, PAYLOAD_LENGTH_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, getPayloadLength()); if (status != ParserStatus.COMPLETE) return status; setPayload(Arrays.copyOf(readBuffer, getPayloadLength())); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } PayloadParser(); }
PayloadParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, PAYLOAD_LENGTH_LENGTH); if (status != ParserStatus.COMPLETE) return status; setPayloadLength(CodecUtils.bytesToShort(readBuffer, 0, PAYLOAD_LENGTH_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, getPayloadLength()); if (status != ParserStatus.COMPLETE) return status; setPayload(Arrays.copyOf(readBuffer, getPayloadLength())); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } PayloadParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); short getPayloadLength(); LogFileParser setPayloadLength(short length); byte[] getPayload(); LogFileParser setPayload(byte[] payload); @Override void writeTo(OutputStream os); }
PayloadParser extends LogFileParser { @Override public ParserStatus parseFile(BufferedInputStream bis, String fileName) throws FileParserException { ParserStatus status = ParserStatus.INIT; try { if (getStep() == 0) { status = parseStep(bis, PAYLOAD_LENGTH_LENGTH); if (status != ParserStatus.COMPLETE) return status; setPayloadLength(CodecUtils.bytesToShort(readBuffer, 0, PAYLOAD_LENGTH_LENGTH, ByteOrder.LITTLE_ENDIAN)); } if (getStep() == 1) { status = parseStep(bis, getPayloadLength()); if (status != ParserStatus.COMPLETE) return status; setPayload(Arrays.copyOf(readBuffer, getPayloadLength())); } resetStep(); status = ParserStatus.COMPLETE; } catch (Exception e) { throw new FileParserException(String.format("Error parsing %s on step %d", fileName, getStep()), e); } return status; } PayloadParser(); @Override ParserStatus parseFile(BufferedInputStream bis, String fileName); short getPayloadLength(); LogFileParser setPayloadLength(short length); byte[] getPayload(); LogFileParser setPayload(byte[] payload); @Override void writeTo(OutputStream os); static final int PAYLOAD_LENGTH_LENGTH; }