Skip to content

Commit

Permalink
minor refactoring + fix for copyright date
Browse files Browse the repository at this point in the history
  • Loading branch information
MenoData committed Mar 4, 2016
1 parent 426efef commit 917540c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.time4j</groupId>
<artifactId>time4j-tzdata</artifactId>
<version>1.8-2016a</version>
<version>1.9-2016a</version>
<packaging>jar</packaging>
<name>Time4J-TZDATA</name>

Expand Down
112 changes: 56 additions & 56 deletions src/main/java/net/time4j/tz/spi/TimezoneRepositoryProviderSPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* -----------------------------------------------------------------------
* Copyright © 2013-2015 Meno Hochschild, <http://www.menodata.de/>
* Copyright © 2013-2016 Meno Hochschild, <http://www.menodata.de/>
* -----------------------------------------------------------------------
* This file (TimezoneRepositoryProviderSPI.java) is part of project Time4J.
*
Expand Down Expand Up @@ -80,7 +80,6 @@ public TimezoneRepositoryProviderSPI() {

URI uri = null;
InputStream is = null;
DataInputStream dis = null;
IllegalStateException ise = null;

String tmpVersion = "";
Expand Down Expand Up @@ -131,76 +130,77 @@ public TimezoneRepositoryProviderSPI() {

if (uri != null) {
is = ResourceLoader.getInstance().load(uri, true);
tmpLocation = uri.toString();
}

if (is == null) {
// fallback if something has gone wrong (maybe invalid uri from protection domain etc.)
URL url = getReference().getClassLoader().getResource(path);
if (url == null) {
throw new FileNotFoundException("Classloader cannot access tz-repository: " + path);
} else {
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
conn.connect(); // explicit for clarity
is = conn.getInputStream();
}
if (is == null) {
// fallback if something has gone wrong (maybe invalid uri from protection domain etc.)
URL url = getReference().getClassLoader().getResource(path);
if (url == null) {
throw new FileNotFoundException("Classloader cannot access tz-repository: " + path);
} else {
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
conn.connect(); // explicit for clarity
is = conn.getInputStream();
tmpLocation = url.toString();
}
}

dis = new DataInputStream(is);
tmpLocation = uri.toString();
checkMagicLabel(dis, tmpLocation);
String v = dis.readUTF();
int sizeOfZones = dis.readInt();

List<String> zones = new ArrayList<String>(sizeOfZones);

for (int i = 0; i < sizeOfZones; i++) {
String zoneID = dis.readUTF();
int dataLen = dis.readInt();
byte[] dataBuf = new byte[dataLen];
int dataRead = 0;

do {
dataRead += dis.read(dataBuf, dataRead, dataLen - dataRead);
if (dataRead == -1) {
throw new EOFException("Incomplete data: " + zoneID);
}
} while (dataLen > dataRead);

zones.add(zoneID);
tmpData.put(zoneID, dataBuf);
}
DataInputStream dis = new DataInputStream(is);
checkMagicLabel(dis, tmpLocation);
String v = dis.readUTF();
int sizeOfZones = dis.readInt();

int sizeOfLinks = dis.readShort();
List<String> zones = new ArrayList<String>(sizeOfZones);

for (int i = 0; i < sizeOfLinks; i++) {
String alias = dis.readUTF();
String id = zones.get(dis.readShort());
tmpAliases.put(alias, id);
}
for (int i = 0; i < sizeOfZones; i++) {
String zoneID = dis.readUTF();
int dataLen = dis.readInt();
byte[] dataBuf = new byte[dataLen];
int dataRead = 0;

if (!noLeaps) {
int sizeOfLeaps = dis.readShort();
do {
dataRead += dis.read(dataBuf, dataRead, dataLen - dataRead);
if (dataRead == -1) {
throw new EOFException("Incomplete data: " + zoneID);
}
} while (dataLen > dataRead);

zones.add(zoneID);
tmpData.put(zoneID, dataBuf);
}

for (int i = 0; i < sizeOfLeaps; i++) {
int year = dis.readShort();
int month = dis.readByte();
int dom = dis.readByte();
int shift = dis.readByte();
int sizeOfLinks = dis.readShort();

this.leapsecs.put(
PlainDate.of(year, month, dom),
Integer.valueOf(shift));
}
for (int i = 0; i < sizeOfLinks; i++) {
String alias = dis.readUTF();
String id = zones.get(dis.readShort());
tmpAliases.put(alias, id);
}

if (!noLeaps) {
int sizeOfLeaps = dis.readShort();

for (int i = 0; i < sizeOfLeaps; i++) {
int year = dis.readShort();
int month = dis.readByte();
int dom = dis.readByte();
tmpExpires = PlainDate.of(year, month, dom);
int shift = dis.readByte();

this.leapsecs.put(
PlainDate.of(year, month, dom),
Integer.valueOf(shift));
}

tmpVersion = v; // here all is okay, so let us set the version
int year = dis.readShort();
int month = dis.readByte();
int dom = dis.readByte();
tmpExpires = PlainDate.of(year, month, dom);
}

tmpVersion = v; // here all is okay, so let us set the version

} catch (IOException ioe) {
ise = new IllegalStateException("[ERROR] TZ-repository not available. => " + ioe.getMessage(), ioe);
} finally {
Expand Down

0 comments on commit 917540c

Please sign in to comment.