Added comments and general code clean up

This commit is contained in:
U-BASIS\dsmyda 2019-12-13 15:46:24 -05:00
parent f4de27095c
commit d81c2bc22d
2 changed files with 244 additions and 248 deletions

View File

@ -52,8 +52,8 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
private static final String NETWORK_LOCALE = "(network)";
/**
* All of the known XRY keys for call reports and the blackboard
* attribute types they map to.
* All of the known XRY keys for call reports and their corresponding
* blackboard attribute types, if any.
*/
private enum XryKey {
NUMBER("number", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER),
@ -97,16 +97,16 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
/**
* Matches the display name of the xry key to the appropriate enum type.
*
* It is assumed that XRY key string is recognized. Otherwise,
* an IllegalArgumentException is thrown. Test all membership
* with contains() before hand.
* It is assumed that XRY key string is recognized. Otherwise, an
* IllegalArgumentException is thrown. Test all membership with
* contains() before hand.
*
* @param xryKey
* @return
*/
public static XryKey fromPair(XRYKeyValuePair pair) {
for(XryKey keyChoice : XryKey.values()) {
if(pair.hasKey(keyChoice.name)) {
for (XryKey keyChoice : XryKey.values()) {
if (pair.hasKey(keyChoice.name)) {
return keyChoice;
}
}
@ -125,20 +125,22 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
NONE(null);
private final String name;
XryNamespace(String name) {
this.name = name;
}
/**
* Indicates if the display name of the XRY namespace is a recognized type.
* Indicates if the display name of the XRY namespace is a recognized
* type.
*
* @param xryNamespace
* @return
*/
public static boolean contains(String xryNamespace) {
String normalizedNamespace = xryNamespace.trim().toLowerCase();
for(XryNamespace keyChoice : XryNamespace.values()) {
if(normalizedNamespace.equals(keyChoice.name)) {
for (XryNamespace keyChoice : XryNamespace.values()) {
if (normalizedNamespace.equals(keyChoice.name)) {
return true;
}
}
@ -147,19 +149,20 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
}
/**
* Matches the display name of the xry namespace to the appropriate enum type.
* Matches the display name of the xry namespace to the appropriate enum
* type.
*
* It is assumed that XRY namespace string is recognized. Otherwise,
* an IllegalArgumentException is thrown. Test all membership
* with contains() before hand.
* It is assumed that XRY namespace string is recognized. Otherwise, an
* IllegalArgumentException is thrown. Test all membership with
* contains() before hand.
*
* @param xryNamespace
* @return
*/
public static XryNamespace fromDisplayName(String xryNamespace) {
String normalizedNamespace = xryNamespace.trim().toLowerCase();
for(XryNamespace keyChoice : XryNamespace.values()) {
if(normalizedNamespace.equals(keyChoice.name)) {
for (XryNamespace keyChoice : XryNamespace.values()) {
if (normalizedNamespace.equals(keyChoice.name)) {
return keyChoice;
}
}
@ -183,7 +186,7 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
Optional<BlackboardAttribute> getBlackboardAttribute(String nameSpace, XRYKeyValuePair pair) {
XryKey xryKey = XryKey.fromPair(pair);
XryNamespace xryNamespace = XryNamespace.NONE;
if(XryNamespace.contains(nameSpace)) {
if (XryNamespace.contains(nameSpace)) {
xryNamespace = XryNamespace.fromDisplayName(nameSpace);
}
@ -219,15 +222,15 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
default:
//Otherwise, the XryKey enum contains the correct BlackboardAttribute
//type.
if(xryKey.getType() != null) {
if (xryKey.getType() != null) {
return Optional.of(new BlackboardAttribute(xryKey.getType(),
PARSER_NAME, pair.getValue()));
PARSER_NAME, pair.getValue()));
}
logger.log(Level.WARNING, String.format("[XRY DSP] Key value pair "
+ "(in brackets) [ %s ] was recognized but "
+ "more data or time is needed to finish implementation. Discarding... ",
pair));
+ "(in brackets) [ %s ] was recognized but "
+ "more data or time is needed to finish implementation. Discarding... ",
pair));
return Optional.empty();
}
}
@ -253,7 +256,7 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
result = result.substring(0, deviceIndex);
}
int networkIndex = result.toLowerCase().indexOf(NETWORK_LOCALE);
if(networkIndex != -1) {
if (networkIndex != -1) {
result = result.substring(0, networkIndex);
}
return result;
@ -270,27 +273,26 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
/**
* The format of time in XRY Messages reports is of the form:
*
* 1/3/1990 1:23:54 AM UTC+4
* 1/3/1990 1:23:54 AM UTC+4
*
* In our current version of Java (openjdk-1.8.0.222), there is
* a bug with having the timezone offset (UTC+4 or GMT-7) at the
* end of the date time input. This is fixed in later versions
* of the JDK (9 and beyond).
* https://bugs.openjdk.java.net/browse/JDK-8154050
* Rather than update the JDK to accommodate this, the components of
* the date time string are reversed:
* In our current version of Java (openjdk-1.8.0.222), there is a bug
* with having the timezone offset (UTC+4 or GMT-7) at the end of the
* date time input. This is fixed in later versions of the JDK (9 and
* beyond). https://bugs.openjdk.java.net/browse/JDK-8154050 Rather than
* update the JDK to accommodate this, the components of the date time
* string are reversed:
*
* UTC+4 AM 1:23:54 1/3/1990
* UTC+4 AM 1:23:54 1/3/1990
*
* The java time package will correctly parse this date time format.
*/
String reversedDateTime = reverseOrderOfDateTimeComponents(dateTimeWithoutLocale);
/**
* Furthermore, the DateTimeFormatter's timezone offset letter ('O') does
* not recognize UTC but recognizes GMT. According to
* https://en.wikipedia.org/wiki/Coordinated_Universal_Time,
* GMT only differs from UTC by at most 1 second and so substitution
* will only introduce a trivial amount of error.
* Furthermore, the DateTimeFormatter's timezone offset letter ('O')
* does not recognize UTC but recognizes GMT. According to
* https://en.wikipedia.org/wiki/Coordinated_Universal_Time, GMT only
* differs from UTC by at most 1 second and so substitution will only
* introduce a trivial amount of error.
*/
String reversedDateTimeWithGMT = reversedDateTime.replace("UTC", "GMT");
TemporalAccessor result = DATE_TIME_PARSER.parseBest(reversedDateTimeWithGMT,
@ -298,7 +300,7 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
LocalDateTime::from,
OffsetDateTime::from);
//Query for the ZoneID
if(result.query(TemporalQueries.zoneId()) == null) {
if (result.query(TemporalQueries.zoneId()) == null) {
//If none, assumed GMT+0.
return ZonedDateTime.of(LocalDateTime.from(result),
ZoneId.of("GMT")).toEpochSecond();
@ -310,10 +312,7 @@ final class XRYCallsFileParser extends AbstractSingleKeyValueParser {
/**
* Reverses the order of the date time components.
*
* Example:
* 1/3/1990 1:23:54 AM UTC+4
* becomes
* UTC+4 AM 1:23:54 1/3/1990
* Example: 1/3/1990 1:23:54 AM UTC+4 becomes UTC+4 AM 1:23:54 1/3/1990
*
* @param dateTime
* @return

View File

@ -64,8 +64,8 @@ final class XRYMessagesFileParser implements XRYFileParser {
private static final int UNREAD = 0;
/**
* All of the known XRY keys for message reports and the blackboard
* attribute types they map to.
* All of the known XRY keys for message reports and their corresponding
* blackboard attribute types, if any.
*/
private enum XryKey {
DELETED("deleted", BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ISDELETED),
@ -121,17 +121,17 @@ final class XRYMessagesFileParser implements XRYFileParser {
/**
* Matches the display name of the xry key to the appropriate enum type.
*
* It is assumed that XRY key string is recognized. Otherwise,
* an IllegalArgumentException is thrown. Test all membership
* with contains() before hand.
* It is assumed that XRY key string is recognized. Otherwise, an
* IllegalArgumentException is thrown. Test all membership with
* contains() before hand.
*
* @param xryKey
* @return
*/
public static XryKey fromDisplayName(String name) {
String normalizedName = name.trim().toLowerCase();
for(XryKey keyChoice : XryKey.values()) {
if(normalizedName.equals(keyChoice.name)) {
for (XryKey keyChoice : XryKey.values()) {
if (normalizedName.equals(keyChoice.name)) {
return keyChoice;
}
}
@ -157,7 +157,8 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
* Indicates if the display name of the XRY namespace is a recognized type.
* Indicates if the display name of the XRY namespace is a recognized
* type.
*
* @param xryNamespace
* @return
@ -172,19 +173,20 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
* Matches the display name of the xry namespace to the appropriate enum type.
* Matches the display name of the xry namespace to the appropriate enum
* type.
*
* It is assumed that XRY namespace string is recognized. Otherwise,
* an IllegalArgumentException is thrown. Test all membership
* with contains() before hand.
* It is assumed that XRY namespace string is recognized. Otherwise, an
* IllegalArgumentException is thrown. Test all membership with
* contains() before hand.
*
* @param xryNamespace
* @return
*/
public static XryNamespace fromDisplayName(String xryNamespace) {
String normalizedNamespace = xryNamespace.trim().toLowerCase();
for(XryNamespace keyChoice : XryNamespace.values()) {
if(normalizedNamespace.equals(keyChoice.name)) {
for (XryNamespace keyChoice : XryNamespace.values()) {
if (normalizedNamespace.equals(keyChoice.name)) {
return keyChoice;
}
}
@ -212,7 +214,6 @@ final class XRYMessagesFileParser implements XRYFileParser {
return name;
}
/**
* Indicates if the display name of the XRY key is a recognized type.
*
@ -231,17 +232,17 @@ final class XRYMessagesFileParser implements XRYFileParser {
/**
* Matches the display name of the xry key to the appropriate enum type.
*
* It is assumed that XRY key string is recognized. Otherwise,
* an IllegalArgumentException is thrown. Test all membership
* with contains() before hand.
* It is assumed that XRY key string is recognized. Otherwise, an
* IllegalArgumentException is thrown. Test all membership with
* contains() before hand.
*
* @param xryKey
* @return
*/
public static XryMetaKey fromDisplayName(String name) {
String normalizedName = name.trim().toLowerCase();
for(XryMetaKey keyChoice : XryMetaKey.values()) {
if(normalizedName.equals(keyChoice.name)) {
for (XryMetaKey keyChoice : XryMetaKey.values()) {
if (normalizedName.equals(keyChoice.name)) {
return keyChoice;
}
}
@ -253,11 +254,11 @@ final class XRYMessagesFileParser implements XRYFileParser {
/**
* Message-SMS report artifacts can span multiple XRY entities and their
* attributes can span multiple lines. The "Text" and "Message" keys are the only known key
* value pair that can span multiple lines. Messages can be segmented,
* meaning that their "Text" and "Message" content can appear in multiple XRY entities.
* Our goal for a segmented message is to aggregate all of the text pieces and
* create 1 artifact.
* attributes can span multiple lines. The "Text" and "Message" keys are the
* only known key value pair that can span multiple lines. Messages can be
* segmented, meaning that their "Text" and "Message" content can appear in
* multiple XRY entities. Our goal for a segmented message is to aggregate
* all of the text pieces and create 1 artifact.
*
* This parse implementation assumes that segments are contiguous and that
* they ascend incrementally. There are checks in place to verify this
@ -283,7 +284,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
String xryEntity = reader.nextEntity();
List<BlackboardAttribute> attributes = getBlackboardAttributes(xryEntity, reader, referenceNumbersSeen);
//Only create artifacts with non-empty attributes.
if(!attributes.isEmpty()) {
if (!attributes.isEmpty()) {
BlackboardArtifact artifact = parent.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE);
artifact.addAttributes(attributes);
}
@ -291,12 +292,8 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
*
* @param xryEntity
* @param reader
* @param referenceValues
* @return
* @throws IOException
* Extracts all blackboard attributes from the XRY Entity. This function will
* unify any segmented text, if need be.
*/
private List<BlackboardAttribute> getBlackboardAttributes(String xryEntity,
XRYFileReader reader, Set<Integer> referenceValues) throws IOException {
@ -307,7 +304,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
List<BlackboardAttribute> attributes = new ArrayList<>();
//Count the key value pairs in the XRY entity.
int keyCount = countKeys(xryLines);
int keyCount = getCountOfKeyValuePairs(xryLines);
for (int i = 1; i <= keyCount; i++) {
//Get the ith key value pair in the entity. Always expect to have
//a valid value.
@ -333,9 +330,9 @@ final class XRYMessagesFileParser implements XRYFileParser {
//Assume text and message are the only fields that can be segmented
//among multiple XRY entities.
if (pair.hasKey(XryKey.TEXT.getDisplayName()) ||
pair.hasKey(XryKey.MESSAGE.getDisplayName())) {
String segmentedText = getSegmentedText(xryLines, reader, referenceValues);
if (pair.hasKey(XryKey.TEXT.getDisplayName())
|| pair.hasKey(XryKey.MESSAGE.getDisplayName())) {
String segmentedText = getSegmentedText(xryLines, reader, referenceValues);
pair = new XRYKeyValuePair(pair.getKey(),
//Assume text is segmented by word.
pair.getValue() + " " + segmentedText,
@ -353,13 +350,13 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
* Counts the key value pairs in an XRY entity.
* Skips counting the first line as it is assumed to be the title.
* Counts the key value pairs in an XRY entity. Skips counting the first
* line as it is assumed to be the title.
*/
private Integer countKeys(String[] xryEntity) {
private Integer getCountOfKeyValuePairs(String[] xryEntity) {
int count = 0;
for (int i = 1; i < xryEntity.length; i++) {
if(XRYKeyValuePair.isPair(xryEntity[i])) {
if (XRYKeyValuePair.isPair(xryEntity[i])) {
count++;
}
}
@ -367,12 +364,12 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
* Builds up segmented message entities so that the text is unified in the
* artifact.
* Builds up segmented message entities so that the text is unified for a
* single artifact.
*
* @param referenceNumber Reference number that messages are group by
* @param segmentNumber Segment number of the starting segment.
* @param reader
* @param reader File reader that is producing XRY entities.
* @param referenceNumbersSeen All known references numbers up until this point.
* @param xryEntity The source XRY entity.
* @return
* @throws IOException
*/
@ -380,7 +377,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
Set<Integer> referenceNumbersSeen) throws IOException {
Optional<Integer> referenceNumber = getMetaKeyValue(xryEntity, XryMetaKey.REFERENCE_NUMBER);
//Check if there is any segmented text.
if(!referenceNumber.isPresent()) {
if (!referenceNumber.isPresent()) {
return "";
}
@ -398,7 +395,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
referenceNumbersSeen.add(referenceNumber.get());
Optional<Integer> segmentNumber = getMetaKeyValue(xryEntity, XryMetaKey.SEGMENT_NUMBER);
if(!segmentNumber.isPresent()) {
if (!segmentNumber.isPresent()) {
logger.log(Level.SEVERE, String.format("No segment "
+ "number was found on the message entity"
+ "with reference number [%d]", referenceNumber.get()));
@ -414,8 +411,8 @@ final class XRYMessagesFileParser implements XRYFileParser {
String[] nextEntityLines = nextEntity.split("\n");
Optional<Integer> nextReferenceNumber = getMetaKeyValue(nextEntityLines, XryMetaKey.REFERENCE_NUMBER);
if (!nextReferenceNumber.isPresent() ||
!Objects.equals(nextReferenceNumber, referenceNumber)) {
if (!nextReferenceNumber.isPresent()
|| !Objects.equals(nextReferenceNumber, referenceNumber)) {
//Don't consume the next entity. It is not related
//to the current message thread.
break;
@ -429,7 +426,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
logger.log(Level.INFO, String.format("[XRY DSP] Processing [ %s ] "
+ "segment with reference number [ %d ]", nextEntityLines[0], referenceNumber.get()));
if(!nextSegmentNumber.isPresent()) {
if (!nextSegmentNumber.isPresent()) {
logger.log(Level.SEVERE, String.format("[XRY DSP] Segment with reference"
+ " number [ %d ] did not have a segment number associated with it."
+ " It cannot be determined if the reconstructed text will be in order.", referenceNumber.get()));
@ -440,16 +437,16 @@ final class XRYMessagesFileParser implements XRYFileParser {
+ "text will be out of order.", nextSegmentNumber.get(), currentSegmentNumber));
}
int keyCount = countKeys(nextEntityLines);
int keyCount = getCountOfKeyValuePairs(nextEntityLines);
for (int i = 1; i <= keyCount; i++) {
XRYKeyValuePair pair = getKeyValuePairByIndex(nextEntityLines, i).get();
if(pair.hasKey(XryKey.TEXT.getDisplayName()) ||
pair.hasKey(XryKey.MESSAGE.getDisplayName())) {
if (pair.hasKey(XryKey.TEXT.getDisplayName())
|| pair.hasKey(XryKey.MESSAGE.getDisplayName())) {
segmentedText.append(pair.getValue()).append(' ');
}
}
if(nextSegmentNumber.isPresent()) {
if (nextSegmentNumber.isPresent()) {
currentSegmentNumber = nextSegmentNumber.get();
}
}
@ -463,9 +460,10 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
* Extracts the value of the XRY meta key, if any.
*
* @param xryLines
* @param metaKey
* @param xryLines XRY entity to extract from.
* @param metaKey The key type to extract.
* @return
*/
private Optional<Integer> getMetaKeyValue(String[] xryLines, XryMetaKey metaKey) {
@ -475,7 +473,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
XRYKeyValuePair pair = XRYKeyValuePair.from(xryLine);
if(pair.hasKey(metaKey.getDisplayName())) {
if (pair.hasKey(metaKey.getDisplayName())) {
try {
return Optional.of(Integer.parseInt(pair.getValue()));
} catch (NumberFormatException ex) {
@ -488,9 +486,12 @@ final class XRYMessagesFileParser implements XRYFileParser {
}
/**
* Extracts the ith XRY Key Value pair in the XRY Entity.
*
* @param xryLines
* @param index
* The total number of pairs can be determined via getCountOfKeyValuePairs().
*
* @param xryLines XRY entity.
* @param index The requested Key Value pair.
* @return
*/
private Optional<XRYKeyValuePair> getKeyValuePairByIndex(String[] xryLines, int index) {
@ -498,32 +499,32 @@ final class XRYMessagesFileParser implements XRYFileParser {
String namespace = "";
for (int i = 1; i < xryLines.length; i++) {
String xryLine = xryLines[i];
if(XryNamespace.contains(xryLine)) {
if (XryNamespace.contains(xryLine)) {
namespace = xryLine.trim();
continue;
}
if(!XRYKeyValuePair.isPair(xryLine)) {
if (!XRYKeyValuePair.isPair(xryLine)) {
logger.log(Level.SEVERE, String.format("[XRY DSP] Expected a key value "
+ "pair on this line (in brackets) [ %s ], but one was not detected."
+ " Discarding...", xryLine));
+ "pair on this line (in brackets) [ %s ], but one was not detected."
+ " Discarding...", xryLine));
continue;
}
XRYKeyValuePair pair = XRYKeyValuePair.from(xryLine);
String value = pair.getValue();
//Build up multiple lines.
for (; (i+1) < xryLines.length
&& !XRYKeyValuePair.isPair(xryLines[i+1])
&& !XryNamespace.contains(xryLines[i+1]); i++) {
String continuedValue = xryLines[i+1].trim();
for (; (i + 1) < xryLines.length
&& !XRYKeyValuePair.isPair(xryLines[i + 1])
&& !XryNamespace.contains(xryLines[i + 1]); i++) {
String continuedValue = xryLines[i + 1].trim();
//Assume multi lined values are split by word.
value = value + " " + continuedValue;
}
pair = new XRYKeyValuePair(pair.getKey(), value, namespace);
pairsParsed++;
if(pairsParsed == index) {
if (pairsParsed == index) {
return Optional.of(pair);
}
}
@ -534,15 +535,15 @@ final class XRYMessagesFileParser implements XRYFileParser {
/**
* Creates an attribute from the extracted key value pair.
*
* @param nameSpace The namespace of this key value pair.
* It will have been verified beforehand, otherwise it will be NONE.
* @param nameSpace The namespace of this key value pair. It will have been
* verified beforehand, otherwise it will be NONE.
* @param key The recognized XRY key.
* @param value The value associated with that key.
* @return Corresponding blackboard attribute, if any.
*/
private Optional<BlackboardAttribute> getBlackboardAttribute(XRYKeyValuePair pair) {
XryNamespace namespace = XryNamespace.NONE;
if(XryNamespace.contains(pair.getNamespace())) {
if (XryNamespace.contains(pair.getNamespace())) {
namespace = XryNamespace.fromDisplayName(pair.getNamespace());
}
XryKey key = XryKey.fromDisplayName(pair.getKey());
@ -584,8 +585,8 @@ final class XRYMessagesFileParser implements XRYFileParser {
case "incoming":
case "outgoing":
return Optional.of(new BlackboardAttribute(
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION,
PARSER_NAME, pair.getValue()));
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DIRECTION,
PARSER_NAME, pair.getValue()));
case "deliver":
case "submit":
case "status report":
@ -620,14 +621,14 @@ final class XRYMessagesFileParser implements XRYFileParser {
default:
//Otherwise, the XryKey enum contains the correct BlackboardAttribute
//type.
if(key.getType() != null) {
if (key.getType() != null) {
return Optional.of(new BlackboardAttribute(key.getType(),
PARSER_NAME, pair.getValue()));
PARSER_NAME, pair.getValue()));
}
logger.log(Level.WARNING, String.format("[XRY DSP] Key value pair "
+ "(in brackets) [ %s ] was recognized but "
+ "more data or time is needed to finish implementation. Discarding... ", pair));
+ "(in brackets) [ %s ] was recognized but "
+ "more data or time is needed to finish implementation. Discarding... ", pair));
return Optional.empty();
}
@ -648,7 +649,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
result = result.substring(0, deviceIndex);
}
int networkIndex = result.toLowerCase().indexOf(NETWORK_LOCALE);
if(networkIndex != -1) {
if (networkIndex != -1) {
result = result.substring(0, networkIndex);
}
return result;
@ -665,27 +666,26 @@ final class XRYMessagesFileParser implements XRYFileParser {
/**
* The format of time in XRY Messages reports is of the form:
*
* 1/3/1990 1:23:54 AM UTC+4
* 1/3/1990 1:23:54 AM UTC+4
*
* In our current version of Java (openjdk-1.8.0.222), there is
* a bug with having the timezone offset (UTC+4 or GMT-7) at the
* end of the date time input. This is fixed in later versions
* of the JDK (9 and beyond).
* https://bugs.openjdk.java.net/browse/JDK-8154050
* Rather than update the JDK to accommodate this, the components of
* the date time string are reversed:
* In our current version of Java (openjdk-1.8.0.222), there is a bug
* with having the timezone offset (UTC+4 or GMT-7) at the end of the
* date time input. This is fixed in later versions of the JDK (9 and
* beyond). https://bugs.openjdk.java.net/browse/JDK-8154050 Rather than
* update the JDK to accommodate this, the components of the date time
* string are reversed:
*
* UTC+4 AM 1:23:54 1/3/1990
* UTC+4 AM 1:23:54 1/3/1990
*
* The java time package will correctly parse this date time format.
*/
String reversedDateTime = reverseOrderOfDateTimeComponents(dateTimeWithoutLocale);
/**
* Furthermore, the DateTimeFormatter's timezone offset letter ('O') does
* not recognize UTC but recognizes GMT. According to
* https://en.wikipedia.org/wiki/Coordinated_Universal_Time,
* GMT only differs from UTC by at most 1 second and so substitution
* will only introduce a trivial amount of error.
* Furthermore, the DateTimeFormatter's timezone offset letter ('O')
* does not recognize UTC but recognizes GMT. According to
* https://en.wikipedia.org/wiki/Coordinated_Universal_Time, GMT only
* differs from UTC by at most 1 second and so substitution will only
* introduce a trivial amount of error.
*/
String reversedDateTimeWithGMT = reversedDateTime.replace("UTC", "GMT");
TemporalAccessor result = DATE_TIME_PARSER.parseBest(reversedDateTimeWithGMT,
@ -693,7 +693,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
LocalDateTime::from,
OffsetDateTime::from);
//Query for the ZoneID
if(result.query(TemporalQueries.zoneId()) == null) {
if (result.query(TemporalQueries.zoneId()) == null) {
//If none, assumed GMT+0.
return ZonedDateTime.of(LocalDateTime.from(result),
ZoneId.of("GMT")).toEpochSecond();
@ -705,10 +705,7 @@ final class XRYMessagesFileParser implements XRYFileParser {
/**
* Reverses the order of the date time components.
*
* Example:
* 1/3/1990 1:23:54 AM UTC+4
* becomes
* UTC+4 AM 1:23:54 1/3/1990
* Example: 1/3/1990 1:23:54 AM UTC+4 becomes UTC+4 AM 1:23:54 1/3/1990
*
* @param dateTime
* @return