jaxws/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java
changeset 23782 953bfc3fbe31
parent 16791 fe5141eabb0e
child 23959 f37ffa18553c
--- a/jaxws/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java	Wed Jul 05 19:34:04 2017 +0200
+++ b/jaxws/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java	Mon Mar 31 10:43:20 2014 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -138,7 +138,6 @@
     }
 
     public int getSize() throws SOAPException {
-        byte[] bytes;
         if (mimePart != null) {
             try {
                 return mimePart.read().available();
@@ -388,6 +387,7 @@
         }
         dataHandler = null;
         InputStream decoded = null;
+        ByteOutputStream bos = null;
         try {
             decoded = MimeUtility.decode(content, "base64");
             InternetHeaders hdrs = new InternetHeaders();
@@ -395,7 +395,7 @@
             //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
             // Ctor with inputStream causes problems based on the InputStream
             // has markSupported()==true
-            ByteOutputStream bos = new ByteOutputStream();
+            bos = new ByteOutputStream();
             bos.write(decoded);
             rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
             setMimeHeader("Content-Type", contentType);
@@ -403,8 +403,11 @@
             log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e);
             throw new SOAPExceptionImpl(e.getLocalizedMessage());
         } finally {
+            if (bos != null)
+                bos.close();
             try {
-                decoded.close();
+                if (decoded != null)
+                    decoded.close();
             } catch (IOException ex) {
                 throw new SOAPException(ex);
             }
@@ -478,13 +481,14 @@
             mimePart = null;
         }
         dataHandler = null;
+        ByteOutputStream bos = null;
         try {
             InternetHeaders hdrs = new InternetHeaders();
             hdrs.setHeader("Content-Type", contentType);
             //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
             // Ctor with inputStream causes problems based on whether the InputStream has
             // markSupported()==true or false
-            ByteOutputStream bos = new ByteOutputStream();
+            bos = new ByteOutputStream();
             bos.write(content);
             rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
             setMimeHeader("Content-Type", contentType);
@@ -492,6 +496,8 @@
             log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e);
             throw new SOAPExceptionImpl(e.getLocalizedMessage());
         } finally {
+            if (bos != null)
+                bos.close();
             try {
                 content.close();
             } catch (IOException ex) {