private static Data loadLeapSeconds ( URL url ) throws ClassNotFoundException , IOException { List < String > lines ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( url . openStream ( ) , StandardCharsets . UTF_8 ) ) ) { lines = reader . lines ( ) . collect ( Collectors . toList ( ) ) ; } List < Long > dates = new ArrayList <> ( ) ; List < Integer > offsets = new ArrayList <> ( ) ; for ( String line : lines ) { line = line . trim ( ) ; if ( line . isEmpty ( ) || line . startsWith ( "#" ) ) { continue ; } Matcher matcher = LEAP_FILE_FORMAT . matcher ( line ) ; if ( matcher . matches ( ) == false ) { throw new StreamCorruptedException ( "Invalid leap second file" ) ; } dates . add ( LocalDate . parse ( matcher . group ( 1 ) ) . getLong ( JulianFields . MODIFIED_JULIAN_DAY ) ) ; offsets . add ( Integer . valueOf ( matcher . group ( 2 ) ) ) ; } long [ ] datesData = new long [ dates . size ( ) ] ; int [ ] offsetsData = new int [ dates . size ( ) ] ; long [ ] taiData = new long [ dates . size ( ) ] ; for ( int i = 0 ; i < datesData . length ; i ++ ) { datesData [ i ] = dates . get ( i ) ; offsetsData [ i ] = offsets . get ( i ) ; taiData [ i ] = tai ( datesData [ i ] , offsetsData [ i ] ) ; } return new Data ( datesData , offsetsData , taiData ) ; }
Loads the leap second rules from a URL often in a jar file .