Skip to content

Commit

Permalink
Auto close input streams
Browse files Browse the repository at this point in the history
  • Loading branch information
benfortuna committed Jul 25, 2018
1 parent f236571 commit 903b64f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/main/java/net/fortuna/ical4j/model/TimeZoneLoader.java
Expand Up @@ -14,6 +14,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
Expand Down Expand Up @@ -99,15 +100,17 @@ public VTimeZone loadVTimeZone(String id) throws IOException, ParserException, P
if (!cache.containsId(id)) {
final URL resource = ResourceLoader.getResource(resourcePrefix + id + ".ics");
if (resource != null) {
final CalendarBuilder builder = new CalendarBuilder();
final Calendar calendar = builder.build(resource.openStream());
final VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE);
// load any available updates for the timezone.. can be explicility disabled via configuration
if (!"false".equals(Configurator.getProperty(UPDATE_ENABLED).orElse("true"))) {
return updateDefinition(vTimeZone);
}
if (vTimeZone != null) {
cache.putIfAbsent(id, vTimeZone);
try (InputStream in = resource.openStream()) {
final CalendarBuilder builder = new CalendarBuilder();
final Calendar calendar = builder.build(in);
final VTimeZone vTimeZone = (VTimeZone) calendar.getComponent(Component.VTIMEZONE);
// load any available updates for the timezone.. can be explicility disabled via configuration
if (!"false".equals(Configurator.getProperty(UPDATE_ENABLED).orElse("true"))) {
return updateDefinition(vTimeZone);
}
if (vTimeZone != null) {
cache.putIfAbsent(id, vTimeZone);
}
}
} else {
return generateTimezoneForId(id);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/fortuna/ical4j/util/Configurator.java
Expand Up @@ -35,6 +35,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import java.util.Properties;

Expand All @@ -55,8 +56,8 @@ public final class Configurator {
private static final Properties CONFIG = new Properties();

static {
try {
CONFIG.load(ResourceLoader.getResourceAsStream("ical4j.properties"));
try (InputStream in = ResourceLoader.getResourceAsStream("ical4j.properties")) {
CONFIG.load(in);
} catch (IOException | NullPointerException e) {
LOG.info("ical4j.properties not found.");
}
Expand Down

0 comments on commit 903b64f

Please sign in to comment.