in src/main/java/org/apache/log4j/pattern/CachedDateFormat.java [161:217]
public static int findMillisecondStart(
final long time, final String formatted, final DateFormat formatter) {
long slotBegin = (time / 1000) * 1000;
if (slotBegin > time) {
slotBegin -= 1000;
}
int millis = (int) (time - slotBegin);
int magic = MAGIC1;
String magicString = MAGICSTRING1;
if (millis == MAGIC1) {
magic = MAGIC2;
magicString = MAGICSTRING2;
}
String plusMagic = formatter.format(new Date(slotBegin + magic));
/**
* If the string lengths differ then
* we can't use the cache except for duplicate requests.
*/
if (plusMagic.length() != formatted.length()) {
return UNRECOGNIZED_MILLISECONDS;
} else {
// find first difference between values
for (int i = 0; i < formatted.length(); i++) {
if (formatted.charAt(i) != plusMagic.charAt(i)) {
//
// determine the expected digits for the base time
StringBuffer formattedMillis = new StringBuffer("ABC");
millisecondFormat(millis, formattedMillis, 0);
String plusZero = formatter.format(new Date(slotBegin));
// If the next 3 characters match the magic
// string and the expected string
if (
(plusZero.length() == formatted.length())
&& magicString.regionMatches(
0, plusMagic, i, magicString.length())
&& formattedMillis.toString().regionMatches(
0, formatted, i, magicString.length())
&& ZERO_STRING.regionMatches(
0, plusZero, i, ZERO_STRING.length())) {
return i;
} else {
return UNRECOGNIZED_MILLISECONDS;
}
}
}
}
return NO_MILLISECONDS;
}