89 * All the regions that are available. 90 */ 91 private List<String> regionIds; 92 /** 93 * Version Id of this tzdb rules 94 */ 95 private String versionId; 96 /** 97 * Region to rules mapping 98 */ 99 private final Map<String, Object> regionToRules = new ConcurrentHashMap<>(); 100 101 /** 102 * Creates an instance. 103 * Created by the {@code ServiceLoader}. 104 * 105 * @throws ZoneRulesException if unable to load 106 */ 107 public TzdbZoneRulesProvider() { 108 try { 109 String libDir = System.getProperty("java.home") + File.separator + "lib"; 110 try (DataInputStream dis = new DataInputStream( 111 new BufferedInputStream(new FileInputStream( 112 new File(libDir, "tzdb.dat"))))) { 113 load(dis); 114 } 115 } catch (Exception ex) { 116 throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex); 117 } 118 } 119 120 @Override 121 protected Set<String> provideZoneIds() { 122 return new HashSet<>(regionIds); 123 } 124 125 @Override 126 protected ZoneRules provideRules(String zoneId, boolean forCaching) { 127 // forCaching flag is ignored because this is not a dynamic provider 128 Object obj = regionToRules.get(zoneId); 129 if (obj == null) { 130 throw new ZoneRulesException("Unknown time-zone ID: " + zoneId); 131 } 132 try { | 89 * All the regions that are available. 90 */ 91 private List<String> regionIds; 92 /** 93 * Version Id of this tzdb rules 94 */ 95 private String versionId; 96 /** 97 * Region to rules mapping 98 */ 99 private final Map<String, Object> regionToRules = new ConcurrentHashMap<>(); 100 101 /** 102 * Creates an instance. 103 * Created by the {@code ServiceLoader}. 104 * 105 * @throws ZoneRulesException if unable to load 106 */ 107 public TzdbZoneRulesProvider() { 108 try { 109 String pathToRules = System.getProperty("jdk.time.tzdbfile"); 110 if (pathToRules == null) { 111 pathToRules = System.getProperty("java.home") + File.separator + "lib" + 112 File.separator + "tzdb.dat"; 113 } 114 115 try (DataInputStream dis = new DataInputStream( 116 new BufferedInputStream(new FileInputStream( 117 new File(pathToRules))))) { 118 load(dis); 119 } 120 } catch (Exception ex) { 121 throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex); 122 } 123 } 124 125 @Override 126 protected Set<String> provideZoneIds() { 127 return new HashSet<>(regionIds); 128 } 129 130 @Override 131 protected ZoneRules provideRules(String zoneId, boolean forCaching) { 132 // forCaching flag is ignored because this is not a dynamic provider 133 Object obj = regionToRules.get(zoneId); 134 if (obj == null) { 135 throw new ZoneRulesException("Unknown time-zone ID: " + zoneId); 136 } 137 try { |