From 917540c0221eccbb17c1ca7b37b483d8cef58759 Mon Sep 17 00:00:00 2001 From: Meno Hochschild Date: Fri, 4 Mar 2016 03:00:08 +0100 Subject: [PATCH] minor refactoring + fix for copyright date --- pom.xml | 2 +- .../tz/spi/TimezoneRepositoryProviderSPI.java | 112 +++++++++--------- 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/pom.xml b/pom.xml index 7a2b167..d5a88a3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.time4j time4j-tzdata - 1.8-2016a + 1.9-2016a jar Time4J-TZDATA diff --git a/src/main/java/net/time4j/tz/spi/TimezoneRepositoryProviderSPI.java b/src/main/java/net/time4j/tz/spi/TimezoneRepositoryProviderSPI.java index a09df3a..7d2c9c4 100644 --- a/src/main/java/net/time4j/tz/spi/TimezoneRepositoryProviderSPI.java +++ b/src/main/java/net/time4j/tz/spi/TimezoneRepositoryProviderSPI.java @@ -1,6 +1,6 @@ /* * ----------------------------------------------------------------------- - * Copyright © 2013-2015 Meno Hochschild, + * Copyright © 2013-2016 Meno Hochschild, * ----------------------------------------------------------------------- * This file (TimezoneRepositoryProviderSPI.java) is part of project Time4J. * @@ -80,7 +80,6 @@ public TimezoneRepositoryProviderSPI() { URI uri = null; InputStream is = null; - DataInputStream dis = null; IllegalStateException ise = null; String tmpVersion = ""; @@ -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 zones = new ArrayList(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 zones = new ArrayList(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 {