/** * Creates an instance. * Created by the {@code ServiceLoader}. * * @throws ZoneRulesException if unable to load */ public TzdbZoneRulesProvider() { super(); if (load(ZoneRulesProvider.class.getClassLoader()) == false) { throw new ZoneRulesException("No time-zone rules found for 'TZDB'"); } }
/** * Creates an instance. * Created by the {@code ServiceLoader}. * * @throws ZoneRulesException if unable to load */ public TzdbZoneRulesProvider() { super(); if (load(ZoneRulesProvider.class.getClassLoader()) == false) { throw new ZoneRulesException("No time-zone rules found for 'TZDB'"); } }
/** * Loads the rules from a URL, often in a jar file. * * @param url the jar file to load, not null * @return true if updated * @throws ClassNotFoundException if a classpath error occurs * @throws IOException if an IO error occurs * @throws ZoneRulesException if the data is already loaded for the version */ private boolean load(URL url) throws ClassNotFoundException, IOException, ZoneRulesException { boolean updated = false; if (loadedUrls.add(url.toExternalForm())) { InputStream in = null; try { in = url.openStream(); updated |= load(in); } finally { if (in != null) { in.close(); } } } return updated; }
/** * Loads the rules from a URL, often in a jar file. * * @param url the jar file to load, not null * @return true if updated * @throws ClassNotFoundException if a classpath error occurs * @throws IOException if an IO error occurs * @throws ZoneRulesException if the data is already loaded for the version */ private boolean load(URL url) throws ClassNotFoundException, IOException, ZoneRulesException { boolean updated = false; if (loadedUrls.add(url.toExternalForm())) { InputStream in = null; try { in = url.openStream(); updated |= load(in); } finally { if (in != null) { in.close(); } } } return updated; }
/** * Creates an instance and loads the specified input stream. * <p> * This could be used to wrap this provider in another instance. * * @param stream the stream to load, not null, not closed after use * @throws ZoneRulesException if unable to load */ public TzdbZoneRulesProvider(InputStream stream) { super(); try { load(stream); } catch (Exception ex) { throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex); } }
/** * Creates an instance and loads the specified input stream. * <p> * This could be used to wrap this provider in another instance. * * @param stream the stream to load, not null, not closed after use * @throws ZoneRulesException if unable to load */ public TzdbZoneRulesProvider(InputStream stream) { super(); try { load(stream); } catch (Exception ex) { throw new ZoneRulesException("Unable to load TZDB time-zone rules", ex); } }
/** * Loads the rules. * * @param classLoader the class loader to use, not null * @return true if updated * @throws ZoneRulesException if unable to load */ private boolean load(ClassLoader classLoader) { boolean updated = false; URL url = null; try { Enumeration<URL> en = classLoader.getResources("org/threeten/bp/TZDB.dat"); while (en.hasMoreElements()) { url = en.nextElement(); updated |= load(url); } } catch (Exception ex) { throw new ZoneRulesException("Unable to load TZDB time-zone rules: " + url, ex); } return updated; }
/** * Loads the rules. * * @param classLoader the class loader to use, not null * @return true if updated * @throws ZoneRulesException if unable to load */ private boolean load(ClassLoader classLoader) { boolean updated = false; URL url = null; try { Enumeration<URL> en = classLoader.getResources("org/threeten/bp/TZDB.dat"); while (en.hasMoreElements()) { url = en.nextElement(); updated |= load(url); } } catch (Exception ex) { throw new ZoneRulesException("Unable to load TZDB time-zone rules: " + url, ex); } return updated; }
/** * Creates an instance and loads the specified URL. * <p> * This could be used to wrap this provider in another instance. * * @param url the URL to load, not null * @throws ZoneRulesException if unable to load */ public TzdbZoneRulesProvider(URL url) { super(); try { if (load(url) == false) { throw new ZoneRulesException("No time-zone rules found: " + url); } } catch (Exception ex) { throw new ZoneRulesException("Unable to load TZDB time-zone rules: " + url, ex); } }
/** * Creates an instance and loads the specified URL. * <p> * This could be used to wrap this provider in another instance. * * @param url the URL to load, not null * @throws ZoneRulesException if unable to load */ public TzdbZoneRulesProvider(URL url) { super(); try { if (load(url) == false) { throw new ZoneRulesException("No time-zone rules found: " + url); } } catch (Exception ex) { throw new ZoneRulesException("Unable to load TZDB time-zone rules: " + url, ex); } }