private static void loadLeapSeconds() {
// It would be better for LeapSeconds.txt to be a file within the JRE lib folder to enable
// simple updating.
InputStream in = LeapSeconds.class.getResourceAsStream("LeapSeconds.txt");
if (in == null) {
throw new CalendricalException("LeapSeconds.txt resource missing");
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
ArrayList<Entry> entries = new ArrayList<Entry>();
while (true) {
String line = reader.readLine();
if (line == null) {
break;
}
line = line.trim();
if (line.length() > 0 && line.charAt(0) != '#') {
int index = 0;
boolean possible = false;
if (line.charAt(0) == '?') {
possible = true;
index=1;
}
// parse a simple date from index
int x = line.indexOf('-', index);
int year = Integer.parseInt(line.substring(index, x));
index = x+1;
x = line.indexOf('-', index);
int month = Integer.parseInt(line.substring(index, x));
index = x+1;
x = line.indexOf(' ');
int day = Integer.parseInt(x < 0 ? line.substring(index) : line.substring(index, x));
if (possible)
nextPossibleLeap = ScaleUtil.epochSeconds(year, month, day);
else
entries.add(new Entry(year, month, day));
}
}
Entry[] entryArray = new Entry[entries.size()];
entries.toArray(entryArray);
LeapSeconds.list = new UTC_TAI<Entry>(entryArray);
in.close();
} catch (IOException e) {
throw new CalendricalException("Exception reading LeapSeconds.txt", e);
}
}