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

Introduce CloseableUtil

This commit is contained in:
Florian Schmaus 2018-08-15 17:25:22 +02:00
parent 1136e8a2e9
commit a00aa726fe
19 changed files with 109 additions and 256 deletions

View file

@ -27,12 +27,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.util.CloseableUtil;
/**
@ -158,20 +158,8 @@ public class IncomingFileTransfer extends FileTransfer {
if (getStatus().equals(Status.in_progress)) {
setStatus(Status.complete);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Closing input stream", e);
}
}
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Closing output stream", e);
}
}
CloseableUtil.maybeClose(inputStream, LOGGER);
CloseableUtil.maybeClose(outputStream, LOGGER);
}
}, "File Transfer " + streamID);
transferThread.start();

View file

@ -22,7 +22,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
@ -30,6 +29,7 @@ import org.jivesoftware.smack.SmackException.IllegalStateChangeException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.util.CloseableUtil;
import org.jxmpp.jid.Jid;
@ -258,19 +258,8 @@ public class OutgoingFileTransfer extends FileTransfer {
setStatus(FileTransfer.Status.error);
setException(e);
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Closing input stream", e);
}
}
try {
outputStream.close();
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Closing output stream", e);
}
CloseableUtil.maybeClose(inputStream, LOGGER);
CloseableUtil.maybeClose(outputStream, LOGGER);
}
updateStatus(Status.in_progress, FileTransfer.Status.complete);
}
@ -325,16 +314,8 @@ public class OutgoingFileTransfer extends FileTransfer {
setStatus(FileTransfer.Status.error);
setException(e);
} finally {
try {
if (in != null) {
in.close();
}
outputStream.flush();
outputStream.close();
} catch (IOException e) {
/* Do Nothing */
}
CloseableUtil.maybeClose(in, LOGGER);
CloseableUtil.maybeClose(outputStream, LOGGER);
}
updateStatus(Status.in_progress, FileTransfer.Status.complete);
}