Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a7c98049 authored by cketti's avatar cketti
Browse files

Make sure the InputStream is always closed

Moving the code to create the OutputStream wrappers into the try-block ensures
that the InputStream is closed in case something goes wrong.
parent 6cd52c12
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -52,8 +52,9 @@ public class BinaryTempFileBody implements Body {
    }

    public void writeTo(OutputStream out) throws IOException, MessagingException {
        boolean closeStream = false;
        InputStream in = getInputStream();
        try {
            boolean closeStream = false;
            if (MimeUtil.isBase64Encoding(mEncoding)) {
                out = new Base64OutputStream(out);
                closeStream = true;
@@ -61,7 +62,7 @@ public class BinaryTempFileBody implements Body {
                out = new QuotedPrintableOutputStream(out, false);
                closeStream = true;
            }
        try {

            try {
                IOUtils.copy(in, out);
            } finally {
+9 −8
Original line number Diff line number Diff line
@@ -4028,8 +4028,9 @@ public class LocalStore extends Store implements Serializable {

        @Override
        public void writeTo(OutputStream out) throws IOException, MessagingException {
            boolean closeStream = false;
            InputStream in = getInputStream();
            try {
                boolean closeStream = false;
                if (MimeUtil.isBase64Encoding(mEncoding)) {
                    out = new Base64OutputStream(out);
                    closeStream = true;
@@ -4037,7 +4038,7 @@ public class LocalStore extends Store implements Serializable {
                    out = new QuotedPrintableOutputStream(out, false);
                    closeStream = true;
                }
            try {

                try {
                    IOUtils.copy(in, out);
                } finally {