private static Data loadLeapSeconds ( ) { Data bestData = null ; URL url = null ; try { // this is the new location of the file, working on Java 8, Java 9 class path and Java 9 module path Enumeration < URL > en = Thread . currentThread ( ) . getContextClassLoader ( ) . getResources ( "META-INF/" + LEAP_SECONDS_TXT ) ; while ( en . hasMoreElements ( ) ) { url = en . nextElement ( ) ; Data candidate = loadLeapSeconds ( url ) ; if ( bestData == null || candidate . getNewestDate ( ) > bestData . getNewestDate ( ) ) { bestData = candidate ; } } // this location does not work on Java 9 module path because the resource is encapsulated en = Thread . currentThread ( ) . getContextClassLoader ( ) . getResources ( LEAP_SECONDS_TXT ) ; while ( en . hasMoreElements ( ) ) { url = en . nextElement ( ) ; Data candidate = loadLeapSeconds ( url ) ; if ( bestData == null || candidate . getNewestDate ( ) > bestData . getNewestDate ( ) ) { bestData = candidate ; } } // this location is the canonical one, and class-based loading works on Java 9 module path url = SystemUtcRules . class . getResource ( "/" + LEAP_SECONDS_TXT ) ; if ( url != null ) { Data candidate = loadLeapSeconds ( url ) ; if ( bestData == null || candidate . getNewestDate ( ) > bestData . getNewestDate ( ) ) { bestData = candidate ; } } } catch ( Exception ex ) { throw new RuntimeException ( "Unable to load time-zone rule data: " + url , ex ) ; } if ( bestData == null ) { // no data on classpath, but we allow manual registration of leap seconds // setup basic known data - MJD 1972-01-01 is 41317L, where offset was 10 bestData = new Data ( new long [ ] { 41317L } , new int [ ] { 10 } , new long [ ] { tai ( 41317L , 10 ) } ) ; } return bestData ; }
Loads the rules from files in the class loader often jar files .