src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/AttachmentPartImpl.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -136,11 +136,10 @@
             headers.addHeader(hd.getName(), hd.getValue());
         }
     }
 
     public int getSize() throws SOAPException {
-        byte[] bytes;
         if (mimePart != null) {
             try {
                 return mimePart.read().available();
             } catch (IOException e) {
                 return -1;

@@ -386,26 +385,30 @@
             mimePart.close();
             mimePart = null;
         }
         dataHandler = null;
         InputStream decoded = null;
+        ByteOutputStream bos = null;
         try {
             decoded = MimeUtility.decode(content, "base64");
             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 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);
         } catch (Exception e) {
             log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e);
             throw new SOAPExceptionImpl(e.getLocalizedMessage());
         } finally {
+            if (bos != null)
+                bos.close();
             try {
+                if (decoded != null)
                 decoded.close();
             } catch (IOException ex) {
                 throw new SOAPException(ex);
             }
         }

@@ -476,24 +479,27 @@
         if (mimePart != null) {
             mimePart.close();
             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);
         } catch (Exception e) {
             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) {
                 throw new SOAPException(ex);
             }