1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-12 14:01:08 +01:00

Use try-with-resources where possible

and make StanzaCollector implement AutoCloseable.
This commit is contained in:
Florian Schmaus 2019-02-04 09:36:37 +01:00
parent e98d42790a
commit 658fd08d20
10 changed files with 30 additions and 69 deletions

View file

@ -29,7 +29,6 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.util.CloseableUtil;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jivesoftware.smack.util.stringencoder.Base64;
@ -177,11 +176,10 @@ public class JivePropertiesExtension implements ExtensionElement {
// a binary format, which won't work well inside of XML. Therefore, we base-64
// encode the binary data before adding it.
else {
ByteArrayOutputStream byteStream = null;
ObjectOutputStream out = null;
try {
byteStream = new ByteArrayOutputStream();
out = new ObjectOutputStream(byteStream);
try (
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteStream);
) {
out.writeObject(value);
type = "java-object";
valueStr = Base64.encodeToString(byteStream.toByteArray());
@ -191,10 +189,6 @@ public class JivePropertiesExtension implements ExtensionElement {
type = "java-object";
valueStr = "Serializing error: " + e.getMessage();
}
finally {
CloseableUtil.maybeClose(out, LOGGER);
CloseableUtil.maybeClose(byteStream, LOGGER);
}
}
xml.attribute("type", type);
xml.rightAngleBracket();