mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-21 22:02:06 +01:00
Close stream in UrlInitializer
This commit is contained in:
parent
384e1852cc
commit
5517d03fae
1 changed files with 18 additions and 1 deletions
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.initializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.LinkedList;
|
||||
|
@ -39,7 +40,7 @@ public abstract class UrlInitializer implements SmackInitializer {
|
|||
|
||||
@Override
|
||||
public List<Exception> initialize() {
|
||||
InputStream is;
|
||||
InputStream is = null;
|
||||
final ClassLoader classLoader = this.getClass().getClassLoader();
|
||||
final List<Exception> exceptions = new LinkedList<Exception>();
|
||||
final String providerUriString = getProvidersUri();
|
||||
|
@ -56,6 +57,8 @@ public abstract class UrlInitializer implements SmackInitializer {
|
|||
catch (Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "Error trying to load provider file " + providerUriString, e);
|
||||
exceptions.add(e);
|
||||
} finally {
|
||||
maybeClose(is);
|
||||
}
|
||||
}
|
||||
final String configUriString = getConfigUri();
|
||||
|
@ -67,6 +70,8 @@ public abstract class UrlInitializer implements SmackInitializer {
|
|||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add(e);
|
||||
} finally {
|
||||
maybeClose(is);
|
||||
}
|
||||
}
|
||||
return exceptions;
|
||||
|
@ -79,4 +84,16 @@ public abstract class UrlInitializer implements SmackInitializer {
|
|||
protected String getConfigUri() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void maybeClose(InputStream is) {
|
||||
if (is == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not close input stream", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue