Skip to content

Commit 917540c

Browse files
committed
minor refactoring + fix for copyright date
1 parent 426efef commit 917540c

File tree

2 files changed

+57
-57
lines changed

2 files changed

+57
-57
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>net.time4j</groupId>
66
<artifactId>time4j-tzdata</artifactId>
7-
<version>1.8-2016a</version>
7+
<version>1.9-2016a</version>
88
<packaging>jar</packaging>
99
<name>Time4J-TZDATA</name>
1010

src/main/java/net/time4j/tz/spi/TimezoneRepositoryProviderSPI.java

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* -----------------------------------------------------------------------
3-
* Copyright © 2013-2015 Meno Hochschild, <http://www.menodata.de/>
3+
* Copyright © 2013-2016 Meno Hochschild, <http://www.menodata.de/>
44
* -----------------------------------------------------------------------
55
* This file (TimezoneRepositoryProviderSPI.java) is part of project Time4J.
66
*
@@ -80,7 +80,6 @@ public TimezoneRepositoryProviderSPI() {
8080

8181
URI uri = null;
8282
InputStream is = null;
83-
DataInputStream dis = null;
8483
IllegalStateException ise = null;
8584

8685
String tmpVersion = "";
@@ -131,76 +130,77 @@ public TimezoneRepositoryProviderSPI() {
131130

132131
if (uri != null) {
133132
is = ResourceLoader.getInstance().load(uri, true);
133+
tmpLocation = uri.toString();
134+
}
134135

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();
146147
}
148+
}
147149

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();
172154

173-
int sizeOfLinks = dis.readShort();
155+
List<String> zones = new ArrayList<String>(sizeOfZones);
174156

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;
180162

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+
}
183173

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();
189175

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();
194184

185+
for (int i = 0; i < sizeOfLeaps; i++) {
195186
int year = dis.readShort();
196187
int month = dis.readByte();
197188
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));
199194
}
200195

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);
202200
}
203201

202+
tmpVersion = v; // here all is okay, so let us set the version
203+
204204
} catch (IOException ioe) {
205205
ise = new IllegalStateException("[ERROR] TZ-repository not available. => " + ioe.getMessage(), ioe);
206206
} finally {

0 commit comments

Comments
 (0)