DecodeDateTimeSecond implements IpfixDataRecordDecodeMethod { @Override public String decodeDataRecord(byte[] data, int length) throws UtilityException, DataTypeLengthMismatchException { if (length != LENGTH) { throw new DataTypeLengthMismatchException("Incorrect length for Date Time Second type: " + length); } data = IpfixUtilities.copyByteArray(data, 0, LENGTH); Long millisecondSinceEpoch = IpfixUtilities.bytesToLong(data, 1, 4) * 1000; Date date = new Date(millisecondSinceEpoch); DateFormat df = new SimpleDateFormat(PATTERN); df.setTimeZone(TimeZone.getTimeZone(TIMEZONE)); String value = df.format(date); return value; }  @Override String decodeDataRecord(byte[] data, int length);  }
@Test public void testDecodeDateTimeSecond() throws UtilityException, DataTypeLengthMismatchException, UnknownHostException, MissingAbstractDataTypeException { byte[] data = IpfixUtilities.hexStringToByteArray("5A6C8D6D"); int length = 4; IpfixDataRecordDecodeMethod method = new DecodeDateTimeSecond(); String value = method.decodeDataRecord(data, length); assertEquals("2018-01-27T14:32:13Z", value); }
@Test(expected = DataTypeLengthMismatchException.class) public void testDecodeDateTimeSecondLengthMismatch() throws DataTypeLengthMismatchException, UtilityException, UnknownHostException, MissingAbstractDataTypeException { byte[] data = IpfixUtilities.hexStringToByteArray("5A6C8D6D"); int length = 3; IpfixDataRecordDecodeMethod method = new DecodeDateTimeSecond(); String value = method.decodeDataRecord(data, length); }