1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package build.tools.tzdb;
28
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.HashSet;
38 import java.util.List;
39 import java.util.Map;
40 import java.util.Map.Entry;
41 import java.util.NavigableMap;
42 import java.util.Objects;
43 import java.util.Set;
44 import java.util.TreeMap;
45 import java.util.TreeSet;
46 import java.util.concurrent.ConcurrentHashMap;
47 import java.time.*;
48 import java.time.Year;
49 import java.time.chrono.IsoChronology;
50 import java.time.temporal.TemporalAdjusters;
51 import java.time.zone.ZoneOffsetTransition;
52 import java.time.zone.ZoneOffsetTransitionRule;
53 import java.time.zone.ZoneOffsetTransitionRule.TimeDefinition;
54 import java.time.zone.ZoneRulesException;
55
56 /**
57 * Compile and build time-zone rules from IANA timezone data
58 *
59 * @author Xueming Shen
60 * @author Stephen Colebourne
61 * @author Michael Nascimento Santos
62 *
63 * @since 9
64 */
65
66 class TzdbZoneRulesProvider {
114 try {
115 ZoneRules zrules = buildRules(zoneId, (List<ZoneLine>)obj);
116 zones.put(zoneId, zrules);
117 return zrules;
118 } catch (Exception ex) {
119 throw new ZoneRulesException(
120 "Invalid binary time-zone data: TZDB:" + zoneId, ex);
121 }
122 }
123
124 //////////////////////////////////////////////////////////////////////
125
126 /**
127 * All the regions that are available.
128 */
129 private List<String> regionIds = new ArrayList<>(600);
130
131 /**
132 * Zone region to rules mapping
133 */
134 private final Map<String, Object> zones = new ConcurrentHashMap<>();
135
136 /**
137 * compatibility list
138 */
139 private static HashSet<String> excludedZones;
140 static {
141 // (1) exclude EST, HST and MST. They are supported
142 // via the short-id mapping
143 // (2) remove UTC and GMT
144 // (3) remove ROC, which is not supported in j.u.tz
145 excludedZones = new HashSet<>(10);
146 excludedZones.add("EST");
147 excludedZones.add("HST");
148 excludedZones.add("MST");
149 excludedZones.add("GMT+0");
150 excludedZones.add("GMT-0");
151 excludedZones.add("ROC");
152 }
153
154 private Map<String, String> links = new HashMap<>(150);
155 private Map<String, List<RuleLine>> rules = new HashMap<>(500);
156
157 private void load(List<Path> files) throws IOException {
158
159 for (Path file : files) {
160 List<ZoneLine> openZone = null;
161 try {
162 for (String line : Files.readAllLines(file, StandardCharsets.ISO_8859_1)) {
163 if (line.length() == 0 || line.charAt(0) == '#') {
164 continue;
165 }
166 //StringIterator itr = new StringIterator(line);
167 String[] tokens = split(line);
168 if (openZone != null && // continuing zone line
169 Character.isWhitespace(line.charAt(0)) &&
170 tokens.length > 0) {
171 ZoneLine zLine = new ZoneLine();
172 openZone.add(zLine);
173 if (zLine.parse(tokens, 0)) {
174 openZone = null;
175 }
|
1 /*
2 * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26
27 package build.tools.tzdb;
28
29 import java.io.IOException;
30 import java.nio.charset.StandardCharsets;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Map.Entry;
39 import java.util.NavigableMap;
40 import java.util.Objects;
41 import java.util.Set;
42 import java.util.TreeMap;
43 import java.util.TreeSet;
44 import java.util.concurrent.ConcurrentSkipListMap;
45 import java.time.*;
46 import java.time.Year;
47 import java.time.chrono.IsoChronology;
48 import java.time.temporal.TemporalAdjusters;
49 import java.time.zone.ZoneOffsetTransition;
50 import java.time.zone.ZoneOffsetTransitionRule;
51 import java.time.zone.ZoneOffsetTransitionRule.TimeDefinition;
52 import java.time.zone.ZoneRulesException;
53
54 /**
55 * Compile and build time-zone rules from IANA timezone data
56 *
57 * @author Xueming Shen
58 * @author Stephen Colebourne
59 * @author Michael Nascimento Santos
60 *
61 * @since 9
62 */
63
64 class TzdbZoneRulesProvider {
112 try {
113 ZoneRules zrules = buildRules(zoneId, (List<ZoneLine>)obj);
114 zones.put(zoneId, zrules);
115 return zrules;
116 } catch (Exception ex) {
117 throw new ZoneRulesException(
118 "Invalid binary time-zone data: TZDB:" + zoneId, ex);
119 }
120 }
121
122 //////////////////////////////////////////////////////////////////////
123
124 /**
125 * All the regions that are available.
126 */
127 private List<String> regionIds = new ArrayList<>(600);
128
129 /**
130 * Zone region to rules mapping
131 */
132 private final Map<String, Object> zones = new ConcurrentSkipListMap<>();
133
134 /**
135 * compatibility list
136 */
137 private static Set<String> excludedZones;
138 static {
139 // (1) exclude EST, HST and MST. They are supported
140 // via the short-id mapping
141 // (2) remove UTC and GMT
142 // (3) remove ROC, which is not supported in j.u.tz
143 excludedZones = new TreeSet<>();
144 excludedZones.add("EST");
145 excludedZones.add("HST");
146 excludedZones.add("MST");
147 excludedZones.add("GMT+0");
148 excludedZones.add("GMT-0");
149 excludedZones.add("ROC");
150 }
151
152 private Map<String, String> links = new TreeMap<>();
153 private Map<String, List<RuleLine>> rules = new TreeMap<>();
154
155 private void load(List<Path> files) throws IOException {
156
157 for (Path file : files) {
158 List<ZoneLine> openZone = null;
159 try {
160 for (String line : Files.readAllLines(file, StandardCharsets.ISO_8859_1)) {
161 if (line.length() == 0 || line.charAt(0) == '#') {
162 continue;
163 }
164 //StringIterator itr = new StringIterator(line);
165 String[] tokens = split(line);
166 if (openZone != null && // continuing zone line
167 Character.isWhitespace(line.charAt(0)) &&
168 tokens.length > 0) {
169 ZoneLine zLine = new ZoneLine();
170 openZone.add(zLine);
171 if (zLine.parse(tokens, 0)) {
172 openZone = null;
173 }
|