|
1 | 1 | /* |
2 | 2 | * ----------------------------------------------------------------------- |
3 | | - * Copyright © 2013-2015 Meno Hochschild, <http://www.menodata.de/> |
| 3 | + * Copyright © 2013-2016 Meno Hochschild, <http://www.menodata.de/> |
4 | 4 | * ----------------------------------------------------------------------- |
5 | 5 | * This file (TimezoneRepositoryProviderSPI.java) is part of project Time4J. |
6 | 6 | * |
@@ -80,7 +80,6 @@ public TimezoneRepositoryProviderSPI() { |
80 | 80 |
|
81 | 81 | URI uri = null; |
82 | 82 | InputStream is = null; |
83 | | - DataInputStream dis = null; |
84 | 83 | IllegalStateException ise = null; |
85 | 84 |
|
86 | 85 | String tmpVersion = ""; |
@@ -131,76 +130,77 @@ public TimezoneRepositoryProviderSPI() { |
131 | 130 |
|
132 | 131 | if (uri != null) { |
133 | 132 | is = ResourceLoader.getInstance().load(uri, true); |
| 133 | + tmpLocation = uri.toString(); |
| 134 | + } |
134 | 135 |
|
135 | | - if (is == null) { |
136 | | - // fallback if something has gone wrong (maybe invalid uri from protection domain etc.) |
137 | | - URL url = getReference().getClassLoader().getResource(path); |
138 | | - if (url == null) { |
139 | | - throw new FileNotFoundException("Classloader cannot access tz-repository: " + path); |
140 | | - } else { |
141 | | - URLConnection conn = url.openConnection(); |
142 | | - conn.setUseCaches(false); |
143 | | - conn.connect(); // explicit for clarity |
144 | | - is = conn.getInputStream(); |
145 | | - } |
| 136 | + if (is == null) { |
| 137 | + // fallback if something has gone wrong (maybe invalid uri from protection domain etc.) |
| 138 | + URL url = getReference().getClassLoader().getResource(path); |
| 139 | + if (url == null) { |
| 140 | + throw new FileNotFoundException("Classloader cannot access tz-repository: " + path); |
| 141 | + } else { |
| 142 | + URLConnection conn = url.openConnection(); |
| 143 | + conn.setUseCaches(false); |
| 144 | + conn.connect(); // explicit for clarity |
| 145 | + is = conn.getInputStream(); |
| 146 | + tmpLocation = url.toString(); |
146 | 147 | } |
| 148 | + } |
147 | 149 |
|
148 | | - dis = new DataInputStream(is); |
149 | | - tmpLocation = uri.toString(); |
150 | | - checkMagicLabel(dis, tmpLocation); |
151 | | - String v = dis.readUTF(); |
152 | | - int sizeOfZones = dis.readInt(); |
153 | | - |
154 | | - List<String> zones = new ArrayList<String>(sizeOfZones); |
155 | | - |
156 | | - for (int i = 0; i < sizeOfZones; i++) { |
157 | | - String zoneID = dis.readUTF(); |
158 | | - int dataLen = dis.readInt(); |
159 | | - byte[] dataBuf = new byte[dataLen]; |
160 | | - int dataRead = 0; |
161 | | - |
162 | | - do { |
163 | | - dataRead += dis.read(dataBuf, dataRead, dataLen - dataRead); |
164 | | - if (dataRead == -1) { |
165 | | - throw new EOFException("Incomplete data: " + zoneID); |
166 | | - } |
167 | | - } while (dataLen > dataRead); |
168 | | - |
169 | | - zones.add(zoneID); |
170 | | - tmpData.put(zoneID, dataBuf); |
171 | | - } |
| 150 | + DataInputStream dis = new DataInputStream(is); |
| 151 | + checkMagicLabel(dis, tmpLocation); |
| 152 | + String v = dis.readUTF(); |
| 153 | + int sizeOfZones = dis.readInt(); |
172 | 154 |
|
173 | | - int sizeOfLinks = dis.readShort(); |
| 155 | + List<String> zones = new ArrayList<String>(sizeOfZones); |
174 | 156 |
|
175 | | - for (int i = 0; i < sizeOfLinks; i++) { |
176 | | - String alias = dis.readUTF(); |
177 | | - String id = zones.get(dis.readShort()); |
178 | | - tmpAliases.put(alias, id); |
179 | | - } |
| 157 | + for (int i = 0; i < sizeOfZones; i++) { |
| 158 | + String zoneID = dis.readUTF(); |
| 159 | + int dataLen = dis.readInt(); |
| 160 | + byte[] dataBuf = new byte[dataLen]; |
| 161 | + int dataRead = 0; |
180 | 162 |
|
181 | | - if (!noLeaps) { |
182 | | - int sizeOfLeaps = dis.readShort(); |
| 163 | + do { |
| 164 | + dataRead += dis.read(dataBuf, dataRead, dataLen - dataRead); |
| 165 | + if (dataRead == -1) { |
| 166 | + throw new EOFException("Incomplete data: " + zoneID); |
| 167 | + } |
| 168 | + } while (dataLen > dataRead); |
| 169 | + |
| 170 | + zones.add(zoneID); |
| 171 | + tmpData.put(zoneID, dataBuf); |
| 172 | + } |
183 | 173 |
|
184 | | - for (int i = 0; i < sizeOfLeaps; i++) { |
185 | | - int year = dis.readShort(); |
186 | | - int month = dis.readByte(); |
187 | | - int dom = dis.readByte(); |
188 | | - int shift = dis.readByte(); |
| 174 | + int sizeOfLinks = dis.readShort(); |
189 | 175 |
|
190 | | - this.leapsecs.put( |
191 | | - PlainDate.of(year, month, dom), |
192 | | - Integer.valueOf(shift)); |
193 | | - } |
| 176 | + for (int i = 0; i < sizeOfLinks; i++) { |
| 177 | + String alias = dis.readUTF(); |
| 178 | + String id = zones.get(dis.readShort()); |
| 179 | + tmpAliases.put(alias, id); |
| 180 | + } |
| 181 | + |
| 182 | + if (!noLeaps) { |
| 183 | + int sizeOfLeaps = dis.readShort(); |
194 | 184 |
|
| 185 | + for (int i = 0; i < sizeOfLeaps; i++) { |
195 | 186 | int year = dis.readShort(); |
196 | 187 | int month = dis.readByte(); |
197 | 188 | int dom = dis.readByte(); |
198 | | - tmpExpires = PlainDate.of(year, month, dom); |
| 189 | + int shift = dis.readByte(); |
| 190 | + |
| 191 | + this.leapsecs.put( |
| 192 | + PlainDate.of(year, month, dom), |
| 193 | + Integer.valueOf(shift)); |
199 | 194 | } |
200 | 195 |
|
201 | | - tmpVersion = v; // here all is okay, so let us set the version |
| 196 | + int year = dis.readShort(); |
| 197 | + int month = dis.readByte(); |
| 198 | + int dom = dis.readByte(); |
| 199 | + tmpExpires = PlainDate.of(year, month, dom); |
202 | 200 | } |
203 | 201 |
|
| 202 | + tmpVersion = v; // here all is okay, so let us set the version |
| 203 | + |
204 | 204 | } catch (IOException ioe) { |
205 | 205 | ise = new IllegalStateException("[ERROR] TZ-repository not available. => " + ioe.getMessage(), ioe); |
206 | 206 | } finally { |
|
0 commit comments